Skip to content

Commit a985f4e

Browse files
committed
Implement prevent-increment-when-tagged and consolidat logic in NextVersionCalculator.
1 parent c0673dc commit a985f4e

File tree

70 files changed

+1198
-946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1198
-946
lines changed

docs/input/docs/reference/configuration.md

Lines changed: 207 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ created. Modify this to suit your needs.
3737

3838
## Global configuration
3939

40-
The global configuration looks like this:
40+
Following supported workflow configurations are available in GitVersion and can be referenced by the workflow property:
41+
- GitFlow (GitFlow/v1)
42+
- GitHubFlow (GitHubFlow/v1) and
43+
- TrunkBased (TrunkBased/v1)
44+
45+
Example of using a TrunkBased workflow with a different tag-prefix:
46+
47+
```yaml
48+
workflow: TrunkBased/v1
49+
tag-prefix: '[abc]'
50+
```
51+
52+
The build-in configuration for the `GitFlow` workflow (`workflow: GitFlow/v1`) looks like:
4153

4254
```yaml
4355
assembly-versioning-scheme: MajorMinorPatch
@@ -61,10 +73,10 @@ strategies:
6173
- VersionInBranchName
6274
branches:
6375
develop:
64-
take-incremented-version: TakeAlwaysIncrementedVersion
6576
label: alpha
6677
increment: Minor
6778
prevent-increment-of-merged-branch-version: false
79+
prevent-increment-when-tagged: false
6880
track-merge-target: true
6981
regex: ^dev(elop)?(ment)?$
7082
source-branches: []
@@ -89,10 +101,10 @@ branches:
89101
pre-release-weight: 55000
90102
release:
91103
mode: ManualDeployment
92-
take-incremented-version: TakeAlwaysIncrementedVersion
93104
label: beta
94105
increment: None
95106
prevent-increment-of-merged-branch-version: true
107+
prevent-increment-when-tagged: false
96108
track-merge-target: false
97109
regex: ^releases?[/-]
98110
source-branches:
@@ -138,6 +150,7 @@ branches:
138150
mode: ManualDeployment
139151
label: beta
140152
increment: Inherit
153+
prevent-increment-when-tagged: false
141154
regex: ^hotfix(es)?[/-]
142155
source-branches:
143156
- release
@@ -177,10 +190,10 @@ branches:
177190
ignore:
178191
sha: []
179192
mode: ContinuousDelivery
180-
take-incremented-version: TakeTaggedOtherwiseIncrementedVersion
181193
label: '{BranchName}'
182194
increment: Inherit
183195
prevent-increment-of-merged-branch-version: false
196+
prevent-increment-when-tagged: true
184197
track-merge-target: false
185198
track-merge-message: true
186199
commit-message-incrementing: Enabled
@@ -192,11 +205,195 @@ is-release-branch: false
192205
is-main-branch: false
193206
```
194207

208+
The supported build-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like:
209+
210+
```yaml
211+
assembly-versioning-scheme: MajorMinorPatch
212+
assembly-file-versioning-scheme: MajorMinorPatch
213+
tag-prefix: '[vV]?'
214+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
215+
major-version-bump-message: '\+semver:\s?(breaking|major)'
216+
minor-version-bump-message: '\+semver:\s?(feature|minor)'
217+
patch-version-bump-message: '\+semver:\s?(fix|patch)'
218+
no-bump-message: '\+semver:\s?(none|skip)'
219+
tag-pre-release-weight: 60000
220+
commit-date-format: yyyy-MM-dd
221+
merge-message-formats: {}
222+
update-build-number: true
223+
semantic-version-format: Strict
224+
strategies:
225+
- ConfiguredNextVersion
226+
- MergeMessage
227+
- TaggedCommit
228+
- TrackReleaseBranches
229+
- VersionInBranchName
230+
branches:
231+
main:
232+
label: ''
233+
increment: Patch
234+
prevent-increment-of-merged-branch-version: true
235+
track-merge-target: false
236+
regex: ^master$|^main$
237+
source-branches:
238+
- release
239+
is-source-branch-for: []
240+
tracks-release-branches: false
241+
is-release-branch: false
242+
is-main-branch: true
243+
pre-release-weight: 55000
244+
release:
245+
mode: ManualDeployment
246+
label: beta
247+
increment: None
248+
prevent-increment-of-merged-branch-version: true
249+
prevent-increment-when-tagged: false
250+
track-merge-target: false
251+
regex: ^releases?[/-]
252+
source-branches:
253+
- main
254+
- release
255+
is-source-branch-for: []
256+
tracks-release-branches: false
257+
is-release-branch: true
258+
is-main-branch: false
259+
pre-release-weight: 30000
260+
feature:
261+
mode: ManualDeployment
262+
label: '{BranchName}'
263+
increment: Inherit
264+
regex: ^features?[/-](?<BranchName>.+)
265+
source-branches:
266+
- main
267+
- release
268+
- feature
269+
is-source-branch-for: []
270+
pre-release-weight: 30000
271+
pull-request:
272+
mode: ContinuousDelivery
273+
label: PullRequest
274+
increment: Inherit
275+
label-number-pattern: '[/-](?<number>\d+)'
276+
regex: ^(pull|pull\-requests|pr)[/-]
277+
source-branches:
278+
- main
279+
- release
280+
- feature
281+
is-source-branch-for: []
282+
pre-release-weight: 30000
283+
unknown:
284+
mode: ManualDeployment
285+
label: '{BranchName}'
286+
increment: Inherit
287+
regex: (?<BranchName>.+)
288+
source-branches:
289+
- main
290+
- release
291+
- feature
292+
- pull-request
293+
is-source-branch-for: []
294+
ignore:
295+
sha: []
296+
mode: ContinuousDelivery
297+
label: '{BranchName}'
298+
increment: Inherit
299+
prevent-increment-of-merged-branch-version: false
300+
prevent-increment-when-tagged: true
301+
track-merge-target: false
302+
track-merge-message: true
303+
commit-message-incrementing: Enabled
304+
regex: ''
305+
source-branches: []
306+
is-source-branch-for: []
307+
tracks-release-branches: false
308+
is-release-branch: false
309+
is-main-branch: false
310+
```
311+
312+
The supported build-in configuration for the `TrunkBased` workflow (`workflow: TrunkBased/v1`) looks like:
313+
314+
```yaml
315+
assembly-versioning-scheme: MajorMinorPatch
316+
assembly-file-versioning-scheme: MajorMinorPatch
317+
tag-prefix: '[vV]?'
318+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
319+
major-version-bump-message: '\+semver:\s?(breaking|major)'
320+
minor-version-bump-message: '\+semver:\s?(feature|minor)'
321+
patch-version-bump-message: '\+semver:\s?(fix|patch)'
322+
no-bump-message: '\+semver:\s?(none|skip)'
323+
tag-pre-release-weight: 60000
324+
commit-date-format: yyyy-MM-dd
325+
merge-message-formats: {}
326+
update-build-number: true
327+
semantic-version-format: Strict
328+
strategies:
329+
- TrunkBased
330+
- ConfiguredNextVersion
331+
branches:
332+
main:
333+
mode: ContinuousDeployment
334+
label: ''
335+
increment: Patch
336+
prevent-increment-of-merged-branch-version: true
337+
track-merge-target: false
338+
regex: ^master$|^main$
339+
source-branches: []
340+
tracks-release-branches: false
341+
is-release-branch: false
342+
is-main-branch: true
343+
pre-release-weight: 55000
344+
feature:
345+
increment: Minor
346+
regex: ^features?[/-](?<BranchName>.+)
347+
prevent-increment-when-tagged: false
348+
source-branches:
349+
- main
350+
pre-release-weight: 30000
351+
hotfix:
352+
increment: Patch
353+
regex: ^hotfix(es)?[/-](?<BranchName>.+)
354+
prevent-increment-when-tagged: false
355+
source-branches:
356+
- main
357+
pre-release-weight: 30000
358+
pull-request:
359+
mode: ManualDeployment
360+
label: PullRequest
361+
increment: Inherit
362+
label-number-pattern: '[/-](?<number>\d+)'
363+
regex: ^(pull|pull\-requests|pr)[/-]
364+
source-branches:
365+
- main
366+
pre-release-weight: 30000
367+
unknown:
368+
mode: ManualDeployment
369+
increment: Inherit
370+
regex: (?<BranchName>.+)
371+
source-branches:
372+
- main
373+
- release
374+
- feature
375+
- pull-request
376+
ignore:
377+
sha: []
378+
mode: ManualDeployment
379+
label: '{BranchName}'
380+
increment: Inherit
381+
prevent-increment-of-merged-branch-version: false
382+
prevent-increment-when-tagged: true
383+
track-merge-target: false
384+
track-merge-message: true
385+
commit-message-incrementing: Enabled
386+
regex: ''
387+
tracks-release-branches: false
388+
is-release-branch: false
389+
is-main-branch: false
390+
```
391+
195392
The details of the available options are as follows:
196393

197394
### workflow
198395

199-
The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1
396+
The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1 or TrunkBased/v1. Defaults to GitFlow/v1 if not set.
200397

201398
### next-version
202399

@@ -266,10 +463,6 @@ The default value is `{InformationalVersion}`.
266463
Sets the `mode` of how GitVersion should create a new version. Read more at
267464
[deployment modes][modes].
268465

269-
### take-incremented-version
270-
271-
This branch related property can be used to control the behavior weither to take the incremented or the tagged version.
272-
273466
### increment
274467

275468
The part of the SemVer to increment when GitVersion detects it needs to be
@@ -612,6 +805,10 @@ In a GitFlow-based repository, setting this option can have implications on the
612805
better version source proposed by the `MergeMessageBaseVersionStrategy`. For
613806
more details and an in-depth analysis, please see [the discussion][2506].
614807

808+
### prevent-increment-when-tagged
809+
810+
This branch related property can be used to control the behavior weither to take the incremented or the current tagged version.
811+
615812
### label-number-pattern
616813

617814
Pull requests require us to extract the pre-release number out of the branch
@@ -706,4 +903,4 @@ Specifies which version strategy implementation (one ore more) will be used to d
706903
* TaggedCommit
707904
* TrackReleaseBranches
708905
* VersionInBranchName
709-
* TrunkBased
906+
* TrunkBased

src/GitVersion.App.Tests/GitVersion.App.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<Compile Include="..\GitVersion.Core.Tests\Helpers\DirectoryHelper.cs" Link="Helpers\DirectoryHelper.cs" />
1919
<Compile Include="..\GitVersion.Core.Tests\Helpers\ExecutableHelper.cs" Link="Helpers\ExecutableHelper.cs" />
2020
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestConsoleAdapter.cs" Link="Helpers\TestConsoleAdapter.cs" />
21-
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEffectiveConfiguration.cs" Link="Helpers\TestEffectiveConfiguration.cs" />
2221
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
2322
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestFileSystem.cs" Link="Helpers\TestFileSystem.cs" />
2423
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestLogAppender.cs" Link="Helpers\TestLogAppender.cs" />

src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23
using GitVersion.Helpers;
34
using GitVersion.VersionCalculation;
@@ -144,10 +145,9 @@ private void AssertVariablesAreWrittenToFile(string propertyFile, string ps1File
144145
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "f28807e615e9f06aec8a33c87780374e0c1f6fb8", CommitDate = new DateTimeOffset(2022, 4, 6, 16, 10, 59, TimeSpan.FromHours(10)) }
145146
};
146147

147-
var configuration = new TestEffectiveConfiguration();
148148
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();
149149

150-
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
150+
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
151151

152152
this.buildServer.WithPropertyFile(propertyFile);
153153
this.buildServer.WithPowershellFile(ps1File);

src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23
using GitVersion.Logging;
34
using GitVersion.OutputVariables;
@@ -36,9 +37,7 @@ public void BuildNumberIsFullSemVer()
3637
}
3738
};
3839

39-
var configuration = new TestEffectiveConfiguration();
40-
41-
var variables = this.buildServer.GetVariablesFor(semanticVersion, configuration, null);
40+
var variables = this.buildServer.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
4241
var buildAgent = this.sp.GetRequiredService<BuildAgent>();
4342
buildAgent.WriteIntegration(writes.Add, variables);
4443

src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23
using GitVersion.Helpers;
34
using GitVersion.VersionCalculation;
@@ -81,11 +82,9 @@ private void AssertVariablesAreWrittenToFile(string file)
8182
}
8283
};
8384

84-
var configuration = new TestEffectiveConfiguration();
85-
8685
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();
8786

88-
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
87+
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
8988

9089
this.buildServer.WithPropertyFile(file);
9190

src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23
using GitVersion.Helpers;
34
using GitVersion.VersionCalculation;
@@ -59,13 +60,16 @@ private void AssertVariablesAreWrittenToFile(string file)
5960
Minor = 2,
6061
Patch = 3,
6162
PreReleaseTag = "beta1",
62-
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") }
63+
BuildMetaData = new SemanticVersionBuildMetaData("5")
64+
{
65+
Sha = "commitSha",
66+
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
67+
}
6368
};
6469

65-
var configuration = new TestEffectiveConfiguration();
6670
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();
6771

68-
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
72+
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
6973

7074
this.buildServer.WithPropertyFile(file);
7175

src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Configuration;
12
using GitVersion.Core.Tests.Helpers;
23
using GitVersion.Helpers;
34
using GitVersion.VersionCalculation;
@@ -133,11 +134,9 @@ private void AssertVariablesAreWrittenToFile(string file)
133134
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") }
134135
};
135136

136-
var configuration = new TestEffectiveConfiguration();
137-
138137
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();
139138

140-
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
139+
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
141140

142141
this.buildServer.WithPropertyFile(file);
143142

0 commit comments

Comments
 (0)