Skip to content

Commit e78e9d2

Browse files
committed
Add full release workflow demo with workaround
1 parent bc3204d commit e78e9d2

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 ReleaseWorkflowDemoWithWorkaround : IDisposable
10+
{
11+
private readonly EmptyRepositoryFixture _fixture = new();
12+
13+
private 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("Commit 1 (made on main)");
28+
CreateAndCheckoutBranch("develop");
29+
MakeACommit("Commit 2 (made on develop)");
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+
GetCurrentSemVer("develop").ShouldBe("1.0.0-alpha.1");
40+
41+
// make another commit on release/1.0.0 to prepare the actual beta1 release
42+
MakeACommit("Commit 3 (made on release/1.0.0)");
43+
44+
// ✅ succeeds as expected
45+
GetCurrentSemVer().ShouldBe("1.0.0-beta.1");
46+
GetCurrentSemVer("develop").ShouldBe("1.0.0-alpha.1");
47+
48+
// now we makes changes on develop that may or may not end up in the 1.0.0 release
49+
CheckoutBranch("develop");
50+
MakeACommit("Commit 4 (made on develop)");
51+
52+
// ✅ succeeds as expected
53+
GetCurrentSemVer().ShouldBe("1.1.0-alpha.1");
54+
GetCurrentSemVer("release/1.0.0").ShouldBe("1.0.0-beta.1");
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+
GetCurrentSemVer("develop").ShouldBe("1.1.0-alpha.1");
63+
64+
// continue with more work on develop that may or may not end up in the 1.0.0 release
65+
CheckoutBranch("develop");
66+
MakeACommit("Commit 5 (made on develop)");
67+
68+
// ✅ succeeds as expected
69+
GetCurrentSemVer().ShouldBe("1.1.0-alpha.2");
70+
GetCurrentSemVer("release/1.0.0").ShouldBe("1.0.0-beta.1");
71+
72+
// now we decide that Commit 5 made on develop should be part of the beta 2 release
73+
// se we cherry pick it
74+
CheckoutBranch("release/1.0.0");
75+
CherryPickLatestCommitFromBranch("develop");
76+
77+
// ✅ succeeds as expected
78+
GetCurrentSemVer().ShouldBe("1.0.0-beta.2");
79+
GetCurrentSemVer("develop").ShouldBe("1.1.0-alpha.2");
80+
81+
// now we do an important bugfix that we found while preparing beta 2
82+
MakeACommit("Commit 6 (made on release/1.0.0)");
83+
84+
// ✅ succeeds as expected
85+
GetCurrentSemVer().ShouldBe("1.0.0-beta.2");
86+
GetCurrentSemVer("develop").ShouldBe("1.1.0-alpha.2");
87+
88+
// we want everything (Commit 3 and 6) that we made only on release/1.0.0 be in develop
89+
CheckoutBranch("develop");
90+
MergeWithNoFF("release/1.0.0");
91+
92+
// ✅ succeeds as expected
93+
GetCurrentSemVer().ShouldBe("1.1.0-alpha.6");
94+
GetCurrentSemVer("release/1.0.0").ShouldBe("1.0.0-beta.2");
95+
96+
// now we do the actual 1.0.0 release
97+
CheckoutBranch("release/1.0.0");
98+
MakeACommit("Commit 7 (made on release/1.0.0)");
99+
CheckoutBranch("main");
100+
MergeWithNoFF("release/1.0.0");
101+
ApplyTag("1.0.0");
102+
CheckoutBranch("develop");
103+
MergeWithNoFF("release/1.0.0");
104+
DeleteBranch("relesase/1.0.0");
105+
106+
// ✅ succeeds as expected
107+
GetCurrentSemVer().ShouldBe("1.1.0-alpha.8");
108+
GetCurrentSemVer("main").ShouldBe("1.0.0");
109+
110+
111+
}
112+
113+
private void DeleteBranch(string branch) => _fixture.Repository.Branches.Remove(branch);
114+
115+
private void MakeACommit(string? message = null) => _fixture.Repository.MakeACommit(message);
116+
117+
private void CheckoutBranch(string branchName) => Commands.Checkout(_fixture.Repository, _fixture.Repository.Branches[branchName]);
118+
119+
private void CreateAndCheckoutBranch(string branchName) => Commands.Checkout(_fixture.Repository, _fixture.Repository.CreateBranch(branchName));
120+
121+
private string GetCurrentSemVer(string? branch = null)
122+
{
123+
if (branch == null)
124+
{
125+
return _fixture.GetVersion(_config).SemVer;
126+
}
127+
128+
if (_fixture.Repository.Branches.All(b => b.FriendlyName != branch))
129+
{
130+
throw new InvalidOperationException($"Branch {branch} does not exist");
131+
}
132+
133+
return _fixture.GetVersion(_config, branch: branch).SemVer;
134+
}
135+
136+
private void ApplyTag(string tag) => _fixture.Repository.ApplyTag(tag);
137+
138+
private void MergeWithNoFF(string sourceBranch) => _fixture.Repository.MergeNoFF(sourceBranch);
139+
140+
private void CherryPickLatestCommitFromBranch(string sourceBranch) => this._fixture.Repository.CherryPick(this._fixture.Repository.Branches[sourceBranch].Commits.First(), Generate.SignatureNow());
141+
}

0 commit comments

Comments
 (0)