Skip to content

Commit 89851ad

Browse files
committed
Add demo test screnarion
1 parent 9998780 commit 89851ad

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
// NextVersion = "1.0"
20+
};
21+
22+
// create main and develop branch, develop is two commits ahead of main
23+
using var fixture = new EmptyRepositoryFixture();
24+
fixture.Repository.MakeACommit();
25+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop"));
26+
fixture.Repository.MakeACommit();
27+
fixture.Repository.MakeACommit();
28+
29+
var previousVersion = GetSemVer(fixture.GetVersion(configuration));
30+
31+
// make a 3rd commit on develop
32+
fixture.Repository.MakeACommit();
33+
34+
35+
var currentVersion = GetSemVer(fixture.GetVersion(configuration));
36+
37+
currentVersion.ShouldBeGreaterThan(previousVersion,
38+
"the semver should be incremented after a commit on develop");
39+
40+
// we are ready to prepare the 1.0.0 release, create and checkout release/1.0.0
41+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/1.0.0"));
42+
43+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
44+
"the first semver on release/1.0.0 should be beta1");
45+
46+
// make another commit on release/1.0.0 to prepare the actual beta1 release
47+
fixture.Repository.MakeACommit();
48+
49+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
50+
"the semver on release/1.0.0 should still be be beta1");
51+
52+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
53+
54+
previousVersion = currentVersion;
55+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
56+
57+
currentVersion.ShouldBe(previousVersion,
58+
"the semver on develop should not have changed " +
59+
"even when release/1.0.0 has new commits due to beta 1 preparations");
60+
61+
// now some other team member makes changes on develop that may or may not end up in 1.0.0
62+
fixture.Repository.MakeACommit();
63+
fixture.Repository.MakeACommit();
64+
65+
previousVersion = currentVersion;
66+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
67+
68+
currentVersion.ShouldBeGreaterThan(previousVersion,
69+
"the semver should be incremented after a even more commit on develop");
70+
71+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);
72+
73+
// now we release the beta 1
74+
fixture.Repository.ApplyTag("1.0.0-beta1");
75+
76+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
77+
"the on release/1.0.0 should still be beta1 after the beta 1 tag");
78+
79+
// continue with more work on develop that may or may not end up in 1.0.0
80+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
81+
fixture.Repository.MakeACommit();
82+
fixture.Repository.MakeACommit();
83+
84+
previousVersion = currentVersion;
85+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
86+
87+
currentVersion.ShouldBeGreaterThan(previousVersion,
88+
"the semver should be incremented after a even more commit on develop");
89+
90+
// now we decide that the three commits on develop should be part of the beta 2 release
91+
// se we merge it into release/1.0.0 with --no-ff because it is a protected branch
92+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);
93+
fixture.Repository.Merge(
94+
fixture.Repository.Branches["develop"],
95+
Generate.SignatureNow(),
96+
new MergeOptions {FastForwardStrategy = FastForwardStrategy.NoFastForward});
97+
98+
fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.2",
99+
"the next semver on release/1.0.0 should be beta2");
100+
101+
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
102+
previousVersion = currentVersion;
103+
currentVersion = GetSemVer(fixture.GetVersion(configuration));
104+
105+
currentVersion.ShouldBeGreaterThanOrEqualTo(previousVersion,
106+
"the semver should be incremented (or unchanged) " +
107+
"after we merged develop into release/1.0.0");
108+
109+
static SemanticVersion GetSemVer(VersionVariables ver)
110+
=> SemanticVersion.Parse(ver.FullSemVer, null);
111+
}
112+
}

0 commit comments

Comments
 (0)