Skip to content

Commit bc3204d

Browse files
committed
Add a reduced demo test
1 parent 5ada1ae commit bc3204d

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using GitTools.Testing;
2+
using GitVersion.Model.Configuration;
3+
using LibGit2Sharp;
4+
using NUnit.Framework;
5+
using Shouldly;
6+
7+
namespace GitVersion.Core.Tests.IntegrationTests;
8+
9+
public class ReducedReleaseWorkflowDemo : IDisposable
10+
{
11+
private static readonly EmptyRepositoryFixture _fixture = new();
12+
13+
private static readonly Config _config = new()
14+
{
15+
// ❓ In my GitVersion.yml I actually have set the version to "1.0"
16+
// but that will cause an exception when I do it here in the tests
17+
NextVersion = "1.0.0"
18+
};
19+
20+
public void Dispose() => _fixture.Dispose();
21+
22+
[Test]
23+
public void Demo()
24+
{
25+
// create main and develop branches
26+
// develop is one commits ahead of main
27+
MakeACommit();
28+
CreateAndCheckoutBranch("develop");
29+
MakeACommit();
30+
31+
// ✅ succeeds as expected
32+
GetCurrentSemVer().ShouldBe("1.0.0-alpha.1");
33+
34+
// now we are ready to start with the preparation of the 1.0.0 release
35+
CreateAndCheckoutBranch("release/1.0.0");
36+
37+
// ✅ succeeds as expected
38+
GetCurrentSemVer().ShouldBe("1.0.0-beta.1");
39+
40+
// make another commit on release/1.0.0 to prepare the actual beta1 release
41+
MakeACommit();
42+
43+
// ✅ succeeds as expected
44+
GetCurrentSemVer().ShouldBe("1.0.0-beta.1");
45+
46+
// now we makes changes on develop that may or may not end up in the 1.0.0 release
47+
CheckoutBranch("develop");
48+
MakeACommit();
49+
50+
// ❌ fails! actual: "1.1.0-alpha.1"
51+
// We have not released 1.0.0, not even a beta, so why increment to 1.1.0?
52+
// Even though this surprising, it might actually be OK,
53+
// at least the version is incremented, which is needed for the CI nuget feed
54+
GetCurrentSemVer().ShouldBe("1.0.0-alpha.2");
55+
56+
// now we do the actual release of beta 1
57+
CheckoutBranch("release/1.0.0");
58+
ApplyTag("1.0.0-beta1");
59+
60+
// ✅ succeeds as expected
61+
GetCurrentSemVer().ShouldBe("1.0.0-beta.1");
62+
63+
// continue with more work on develop that may or may not end up in the 1.0.0 release
64+
CheckoutBranch("develop");
65+
MakeACommit();
66+
67+
// ❌ fails! actual: "1.1.0-alpha.2"
68+
// We still have not finally released 1.0.0 yet, only a beta, so why increment to 1.1.0?
69+
// Even though this surprising, it might actually be OK,
70+
// at least the version is incremented, which is needed for the CI nuget feed
71+
GetCurrentSemVer().ShouldBe("1.0.0-alpha.3");
72+
73+
// now we decide that the new changes on develop should be part of the beta 2 release
74+
// se we merge it into release/1.0.0 with --no-ff because it is a protected branch
75+
// but we don't do the release of beta 2 jus yet
76+
CheckoutBranch("release/1.0.0");
77+
MergeWithNoFF("develop");
78+
79+
// ✅ succeeds as expected
80+
GetCurrentSemVer().ShouldBe("1.0.0-beta.2");
81+
82+
CheckoutBranch("develop");
83+
84+
// ❌ fails! actual "1.0.0-alpha.3"
85+
// This is now really a problem. Why did it decrement the minor version?
86+
// All subsequent changes on develop will now a lower version that previously
87+
// and the nuget packages end up on the CI feed with a lower version
88+
// so users of that feed would need to _downgrade_ to get a _newer_ version.
89+
GetCurrentSemVer().ShouldBe("1.1.0-alpha.2");
90+
}
91+
92+
private static void MakeACommit() => _fixture.Repository.MakeACommit();
93+
94+
private void CheckoutBranch(string branchName) => Commands.Checkout(_fixture.Repository, _fixture.Repository.Branches[branchName]);
95+
96+
private void CreateAndCheckoutBranch(string branchName) => Commands.Checkout(_fixture.Repository, _fixture.Repository.CreateBranch(branchName));
97+
98+
private string GetCurrentSemVer() => _fixture.GetVersion(_config).SemVer;
99+
100+
private void ApplyTag(string tag) => _fixture.Repository.ApplyTag(tag);
101+
102+
private void MergeWithNoFF(string sourceBranch) => _fixture.Repository.MergeNoFF(sourceBranch);
103+
}

0 commit comments

Comments
 (0)