-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIGitFlow.cs
More file actions
118 lines (98 loc) · 4.25 KB
/
IGitFlow.cs
File metadata and controls
118 lines (98 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Threading.Tasks;
using Candoumbe.Pipelines.Components.Workflows;
using Nuke.Common;
using Nuke.Common.Git;
using static Nuke.Common.Tools.Git.GitTasks;
namespace Candoumbe.Pipelines.Components;
/// <summary>
/// Marks a build as supporting the <see href="https://datasift.github.io/gitflow/IntroducingGitFlow.html">git flow</see> workflow.
/// </summary>
/// <remarks>
/// This interface will provide several ready-to-use targets to effectively manage this workflow even when the underlying "git" command does not support gitflow verbs.
/// </remarks>
public interface IGitFlow : IDoHotfixWorkflow, IDoColdfixWorkflow, IDoChoreWorkflow, IHaveDevelopBranch
{
/// <summary>
/// Name of the release branch
/// </summary>
public const string ReleaseBranch = "release";
/// <summary>
/// Prefix used to name release branches
/// </summary>
public string ReleaseBranchPrefix => "release";
///<inheritdoc/>
string IDoFeatureWorkflow.FeatureBranchSourceName => DevelopBranchName;
/// <inheritdoc />
string IDoChoreWorkflow.ChoreBranchSourceName => FeatureBranchSourceName;
///<inheritdoc/>
string IDoHotfixWorkflow.HotfixBranchSourceName => MainBranchName;
/// <summary>
/// Creates a new release branch from the develop branch.
/// </summary>
/// <remarks>
/// A major release can be created by setting <see cref="IHaveGitVersion.Major"/> to <see langword="true"/>
/// </remarks>
public Target Release => _ => _
.DependsOn(Changelog)
.Description($$"""
Starts a new {{ReleaseBranchPrefix}}/{version} from {{DevelopBranchName}} if not currently on {{ReleaseBranchPrefix}}/{version}.
When already on {{ReleaseBranchPrefix}}/{version}, merges back either to {{MainBranchName}} or {{DevelopBranchName}} ")
""")
.Requires(() => IsLocalBuild)
.Requires(() => !GitRepository.IsOnReleaseBranch() || GitHasCleanWorkingCopy())
.Executes(async () =>
{
if (!GitRepository.IsOnReleaseBranch())
{
string majorMinorPatchVersion = Major
? $"{GitVersion.Major + 1}.0.0"
: GitVersion.MajorMinorPatch;
Checkout($"{ReleaseBranchPrefix}/{majorMinorPatchVersion}", start: DevelopBranchName);
}
else
{
await FinishRelease();
}
});
/// <summary>
/// Merges a <see cref="IDoColdfixWorkflow.ColdfixBranchPrefix"/> back to <see cref="IHaveDevelopBranch.DevelopBranchName"/> branch
/// </summary>
async ValueTask IDoColdfixWorkflow.FinishColdfix() => await FinishFeature();
/// <summary>
/// Merges the current hotfix branch back to <see cref="IHaveMainBranch.MainBranchName"/>.
/// </summary>
ValueTask IDoHotfixWorkflow.FinishHotfix()
{
Git($"checkout {MainBranchName}");
Git("pull");
Git($"merge --no-ff --no-edit {GitRepository.Branch}");
Git($"tag {MajorMinorPatchVersion}");
Git($"checkout {DevelopBranchName}");
Git("pull");
Git($"merge --no-ff --no-edit {GitRepository.Branch}");
Git($"branch -D {GitRepository.Branch}");
Git($"push origin --follow-tags {MainBranchName} {DevelopBranchName} {MajorMinorPatchVersion}");
return ValueTask.CompletedTask;
}
/// <summary>
/// Merges a release branch back to the trunk branch.
/// </summary>
public async ValueTask FinishRelease() => await FinishHotfix().ConfigureAwait(false);
/// <summary>
/// Merges the current feature branch back to <see cref="IHaveDevelopBranch.DevelopBranchName"/>.
/// </summary>
ValueTask IDoFeatureWorkflow.FinishFeature()
{
Git($"rebase {DevelopBranchName}");
Git($"checkout {DevelopBranchName}");
Git("pull");
Git($"merge --no-ff --no-edit {GitRepository.Branch}");
Git($"branch -D {GitRepository.Branch}");
Git($"push origin {DevelopBranchName}");
return ValueTask.CompletedTask;
}
/// <summary>
/// Merges the current feature branch back to <see cref="IHaveDevelopBranch.DevelopBranchName"/>.
/// </summary>
ValueTask IDoChoreWorkflow.FinishChore() => FinishFeature();
}