Skip to content

Commit 3efed65

Browse files
committed
Add demo test screnarion
1 parent 9998780 commit 3efed65

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using GitTools.Testing;
2+
using GitVersion.Model.Configuration;
3+
using GitVersion.OutputVariables;
4+
using LibGit2Sharp;
5+
using NUnit.Framework;
6+
using Shouldly;
7+
8+
namespace GitVersion.Core.Tests.IntegrationTests;
9+
10+
public class VersioningDemoScenario
11+
{
12+
[Test]
13+
public void ReleaseAndDevelopProblemDemo()
14+
{
15+
var configuration = new Config
16+
{
17+
// Settings the below NextVersion results in an exception
18+
// I wanted to set it to globally start with version 1
19+
// Setting the version to 1.0 (which is not a valid semantic version)
20+
// works in GitVersion.yml but not here.
21+
22+
// NextVersion = "1.0"
23+
};
24+
25+
// create main and develop branch, develop is two commits ahead of main
26+
using var fixture = new EmptyRepositoryFixture();
27+
fixture.Repository.MakeACommit();
28+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop"));
29+
fixture.Repository.MakeACommit();
30+
fixture.Repository.MakeACommit();
31+
32+
var previousVersion = GetSemVer(fixture.GetVersion(configuration));
33+
34+
// make a 3rd commit on develop
35+
fixture.Repository.MakeACommit();
36+
37+
38+
var currentVersion = GetSemVer(fixture.GetVersion(configuration));
39+
40+
currentVersion.ShouldBeGreaterThan(previousVersion,
41+
"the semver should be incremented after a commit on develop");
42+
43+
// we are ready to prepare the 1.0.0 release, create and checkout release/1.0.0
44+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/1.0.0"));
45+
46+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
47+
"the first semver on release/1.0.0 should be beta1");
48+
49+
// make another commit on release/1.0.0 to prepare the actual beta1 release
50+
fixture.Repository.MakeACommit();
51+
52+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
53+
"the semver on release/1.0.0 should still be be beta1");
54+
55+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
56+
57+
previousVersion = currentVersion;
58+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
59+
60+
currentVersion.ShouldBe(previousVersion,
61+
"the semver on develop should not have changed " +
62+
"even when release/1.0.0 has new commits due to beta 1 preparations");
63+
64+
// now some other team member makes changes on develop that may or may not end up in 1.0.0
65+
fixture.Repository.MakeACommit();
66+
fixture.Repository.MakeACommit();
67+
68+
previousVersion = currentVersion;
69+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
70+
71+
currentVersion.ShouldBeGreaterThan(previousVersion,
72+
"the semver should be incremented after a even more commit on develop");
73+
74+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);
75+
76+
// now we release the beta 1
77+
fixture.Repository.ApplyTag("1.0.0-beta1");
78+
79+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
80+
"the on release/1.0.0 should still be beta1 after the beta 1 tag");
81+
82+
// continue with more work on develop that may or may not end up in 1.0.0
83+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
84+
fixture.Repository.MakeACommit();
85+
fixture.Repository.MakeACommit();
86+
87+
previousVersion = currentVersion;
88+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
89+
90+
currentVersion.ShouldBeGreaterThan(previousVersion,
91+
"the semver should be incremented after a even more commit on develop");
92+
93+
// now we decide that the three commits on develop should be part of the beta 2 release
94+
// se we merge it into release/1.0.0 with --no-ff because it is a protected branch
95+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);
96+
fixture.Repository.Merge(
97+
fixture.Repository.Branches["develop"],
98+
Generate.SignatureNow(),
99+
new MergeOptions {FastForwardStrategy = FastForwardStrategy.NoFastForward});
100+
101+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.2",
102+
"the next semver on release/1.0.0 should be beta2");
103+
104+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
105+
previousVersion = currentVersion;
106+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
107+
108+
currentVersion.ShouldBeGreaterThanOrEqualTo(previousVersion,
109+
"the semver should be incremented (or unchanged) " +
110+
"after we merged develop into release/1.0.0");
111+
112+
static SemanticVersion GetSemVer(VersionVariables ver)
113+
=> SemanticVersion.Parse(ver.FullSemVer, null);
114+
}
115+
}

0 commit comments

Comments
 (0)