Skip to content

Commit 3cafb59

Browse files
authored
Merge pull request #3883 from HHobeck/feature/Replace-the-version-mode-Mainline-Part-IV
Replace the version mode Mainline in 6.x (Part IV)
2 parents 27c86e6 + 0bd90f5 commit 3cafb59

38 files changed

+211
-176
lines changed

BREAKING_CHANGES.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@
3232
* The `BranchPrefixToTrim` configuration property has been removed. `RegularExpression` is now used to capture named groups instead.
3333
* Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
3434
* Default `RegularExpression` for unknown branches is changed from `.*` to `(?<BranchName>.*)` to support using `{BranchName}` out-of-the-box
35+
* The `Mainline` mode and the related implementation has been removed completely. The new `TrunkBased` version strategy should be used instead.
3536
* The branch related property `is-mainline` in the configuration system has been renamed to `is-main-branch`
3637
* The versioning mode has been renamed to deployment mode and consists of following values:
3738
* ManualDeployment (previously ContinuousDelivery)
3839
* ContinuousDelivery (previously ContinuousDeployment)
3940
* ContinuousDeployment (new)
40-
41+
* At the configuration root level, a new array called `strategies` has been introduced, which can consist of on or more following values:
42+
* ConfiguredNextVersion
43+
* MergeMessage
44+
* TaggedCommit
45+
* TrackReleaseBranches
46+
* VersionInBranchName
47+
* TrunkBased
48+
4149
## v5.0.0
4250
4351
* Version numbers in branches other than `release` branches are no longer

docs/input/docs/reference/configuration.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The global configuration looks like this:
4343
assembly-versioning-scheme: MajorMinorPatch
4444
assembly-file-versioning-scheme: MajorMinorPatch
4545
tag-prefix: '[vV]?'
46-
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
4746
major-version-bump-message: '\+semver:\s?(breaking|major)'
4847
minor-version-bump-message: '\+semver:\s?(feature|minor)'
4948
patch-version-bump-message: '\+semver:\s?(fix|patch)'
@@ -53,6 +52,7 @@ commit-date-format: yyyy-MM-dd
5352
merge-message-formats: {}
5453
update-build-number: true
5554
semantic-version-format: Strict
55+
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
5656
branches:
5757
develop:
5858
mode: ContinuousDeployment
@@ -62,7 +62,6 @@ branches:
6262
track-merge-target: true
6363
regex: ^dev(elop)?(ment)?$
6464
source-branches: []
65-
is-source-branch-for: []
6665
tracks-release-branches: true
6766
is-release-branch: false
6867
is-main-branch: false
@@ -76,7 +75,6 @@ branches:
7675
source-branches:
7776
- develop
7877
- release
79-
is-source-branch-for: []
8078
tracks-release-branches: false
8179
is-release-branch: false
8280
is-main-branch: true
@@ -92,7 +90,6 @@ branches:
9290
- main
9391
- support
9492
- release
95-
is-source-branch-for: []
9693
tracks-release-branches: false
9794
is-release-branch: true
9895
is-main-branch: false
@@ -101,15 +98,14 @@ branches:
10198
mode: ContinuousDelivery
10299
label: '{BranchName}'
103100
increment: Inherit
104-
regex: ^features?[/-]
101+
regex: ^features?[/-](?<BranchName>.+)
105102
source-branches:
106103
- develop
107104
- main
108105
- release
109106
- feature
110107
- support
111108
- hotfix
112-
is-source-branch-for: []
113109
pre-release-weight: 30000
114110
pull-request:
115111
mode: ContinuousDelivery
@@ -124,7 +120,6 @@ branches:
124120
- feature
125121
- support
126122
- hotfix
127-
is-source-branch-for: []
128123
pre-release-weight: 30000
129124
hotfix:
130125
mode: ContinuousDelivery
@@ -136,8 +131,6 @@ branches:
136131
- main
137132
- support
138133
- hotfix
139-
is-source-branch-for: []
140-
is-release-branch: true
141134
pre-release-weight: 30000
142135
support:
143136
label: ''
@@ -147,7 +140,6 @@ branches:
147140
regex: ^support[/-]
148141
source-branches:
149142
- main
150-
is-source-branch-for: []
151143
tracks-release-branches: false
152144
is-release-branch: false
153145
is-main-branch: true
@@ -156,7 +148,7 @@ branches:
156148
mode: ContinuousDelivery
157149
label: '{BranchName}'
158150
increment: Inherit
159-
regex: .*
151+
regex: (?<BranchName>.*)
160152
source-branches:
161153
- main
162154
- develop
@@ -165,7 +157,6 @@ branches:
165157
- pull-request
166158
- hotfix
167159
- support
168-
is-source-branch-for: []
169160
ignore:
170161
sha: []
171162
mode: ContinuousDelivery
@@ -176,8 +167,6 @@ track-merge-target: false
176167
track-merge-message: true
177168
commit-message-incrementing: Enabled
178169
regex: ''
179-
source-branches: []
180-
is-source-branch-for: []
181170
tracks-release-branches: false
182171
is-release-branch: false
183172
is-main-branch: false
@@ -684,3 +673,13 @@ Example of invalid `Strict`, but valid `Loose`
684673
[modes]: /docs/reference/modes
685674
[variables]: /docs/reference/variables
686675
[version-sources]: /docs/reference/version-sources
676+
677+
### strategies
678+
679+
Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined:
680+
* ConfiguredNextVersion
681+
* MergeMessage
682+
* TaggedCommit
683+
* TrackReleaseBranches
684+
* VersionInBranchName
685+
* TrunkBased

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ commit-date-format: yyyy-MM-dd
1111
merge-message-formats: {}
1212
update-build-number: true
1313
semantic-version-format: Strict
14+
strategies:
15+
- ConfiguredNextVersion
16+
- MergeMessage
17+
- TaggedCommit
18+
- TrackReleaseBranches
19+
- VersionInBranchName
1420
branches:
1521
develop:
1622
label: alpha

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public void OverwritesDefaultsWithProvidedConfig()
5656
developConfiguration.Label.ShouldBe("dev");
5757
}
5858

59+
[Test]
60+
public void CombineVersionStrategyConfigNextAndTaggedCommit()
61+
{
62+
// Arrange
63+
SetupConfigFileContent("strategies: [ConfiguredNextVersion, TaggedCommit]");
64+
65+
// Act
66+
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
67+
68+
// Assert
69+
configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfiguredNextVersion | VersionStrategies.TaggedCommit);
70+
}
71+
5972
[Test]
6073
public void CanRemoveLabel()
6174
{

src/GitVersion.Configuration.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ next-version: 2.0.0
22
merge-message-formats: {}
33
update-build-number: true
44
semantic-version-format: Strict
5+
strategies: []
56
branches: {}
67
ignore:
78
sha: []

src/GitVersion.Configuration/ConfigurationBuilderBase.cs

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfi
2424
private string? commitDateFormat;
2525
private bool updateBuildNumber;
2626
private SemanticVersionFormat semanticVersionFormat;
27+
private VersionStrategies versionStrategy;
2728
private Dictionary<string, string> mergeMessageFormats = new();
2829
private readonly List<IReadOnlyDictionary<object, object?>> overrides = new();
2930
private readonly Dictionary<string, BranchConfigurationBuilder> branchConfigurationBuilders = new();
@@ -199,6 +200,12 @@ public virtual TConfigurationBuilder WithSemanticVersionFormat(SemanticVersionFo
199200
return (TConfigurationBuilder)this;
200201
}
201202

203+
public virtual TConfigurationBuilder WithVersionStrategy(VersionStrategies value)
204+
{
205+
this.versionStrategy = value;
206+
return (TConfigurationBuilder)this;
207+
}
208+
202209
public virtual TConfigurationBuilder WithMergeMessageFormats(IReadOnlyDictionary<string, string> value)
203210
{
204211
this.mergeMessageFormats = new(value);
@@ -321,6 +328,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration
321328
WithCommitDateFormat(value.CommitDateFormat);
322329
WithUpdateBuildNumber(value.UpdateBuildNumber);
323330
WithSemanticVersionFormat(value.SemanticVersionFormat);
331+
WithVersionStrategy(value.VersionStrategy);
324332
WithMergeMessageFormats(value.MergeMessageFormats);
325333
foreach (var (name, branchConfiguration) in value.Branches)
326334
{
@@ -358,6 +366,10 @@ public virtual IGitVersionConfiguration Build()
358366
branches.Add(name, (BranchConfiguration)branchConfigurationBuilder.Build());
359367
}
360368

369+
var versionStrategies = Enum.GetValues<VersionStrategies>()
370+
.Where(element => element != VersionStrategies.None && this.versionStrategy.HasFlag(element))
371+
.ToArray();
372+
361373
IGitVersionConfiguration configuration = new GitVersionConfiguration
362374
{
363375
AssemblyVersioningScheme = this.assemblyVersioningScheme,
@@ -377,6 +389,7 @@ public virtual IGitVersionConfiguration Build()
377389
CommitDateFormat = this.commitDateFormat,
378390
UpdateBuildNumber = this.updateBuildNumber,
379391
SemanticVersionFormat = this.semanticVersionFormat,
392+
VersionStrategies = versionStrategies,
380393
Branches = branches,
381394
MergeMessageFormats = this.mergeMessageFormats,
382395
DeploymentMode = this.versioningMode,

src/GitVersion.Configuration/ConfigurationFileLocator.cs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GitVersion.Extensions;
22
using GitVersion.Helpers;
3-
using GitVersion.VersionCalculation;
43
using Microsoft.Extensions.Options;
54

65
namespace GitVersion.Configuration;
@@ -29,11 +28,7 @@ public IGitVersionConfiguration ReadConfiguration(string? configFilePath)
2928
if (configFilePath == null || !fileSystem.Exists(configFilePath)) return new GitVersionConfiguration();
3029

3130
var readAllText = fileSystem.ReadAllText(configFilePath);
32-
var readConfig = ConfigurationSerializer.Read(new StringReader(readAllText));
33-
34-
VerifyReadConfig(readConfig);
35-
36-
return readConfig;
31+
return ConfigurationSerializer.Read(new StringReader(readAllText));
3732
}
3833

3934
public IReadOnlyDictionary<object, object?>? ReadOverrideConfiguration(string? configFilePath)
@@ -64,19 +59,6 @@ bool HasConfigurationFileAt(string fileName, out string? configFile)
6459
|| HasConfigurationFileAt(DefaultAlternativeFileName, out path);
6560
}
6661

67-
private static void VerifyReadConfig(IGitVersionConfiguration configuration)
68-
{
69-
// Verify no branches are set to TrunkBased mode
70-
if (configuration.Branches.Any(b => b.Value.DeploymentMode == DeploymentMode.TrunkBased))
71-
{
72-
throw new ConfigurationException(@"TrunkBased mode only works at the repository level, a single branch cannot be put into TrunkBased mode
73-
74-
This is because TrunkBased mode treats your entire git repository as an event source with each merge into the 'TrunkBased' incrementing the version.
75-
76-
If the docs do not help you decide on the mode open an issue to discuss what you are trying to do.");
77-
}
78-
}
79-
8062
private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, string? projectRootDirectory)
8163
{
8264
TryGetConfigurationFile(workingDirectory, null, out var workingConfigFile);

src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private GitFlowConfigurationBuilder()
1818
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
1919
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
2020
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
21+
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
2122
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
2223
VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern,
2324
TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight,

src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private GitHubFlowConfigurationBuilder()
1818
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
1919
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
2020
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
21+
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
2122
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
2223
VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern,
2324
TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight,

src/GitVersion.Configuration/GitVersion.Configuration.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<None Remove="SupportedWorkflows\TrunkBased\v1.yml" />
4+
</ItemGroup>
25
<ItemGroup>
36
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
47
</ItemGroup>
@@ -10,6 +13,7 @@
1013
<ItemGroup>
1114
<EmbeddedResource Include="SupportedWorkflows\GitFlow\v1.yml" />
1215
<EmbeddedResource Include="SupportedWorkflows\GitHubFlow\v1.yml" />
16+
<EmbeddedResource Include="SupportedWorkflows\TrunkBased\v1.yml" />
1317
</ItemGroup>
1418

1519
<ItemGroup>

src/GitVersion.Configuration/GitVersionConfiguration.cs

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public string? NextVersion
124124
[JsonPropertyDefault(DefaultSemanticVersionFormat)]
125125
public SemanticVersionFormat SemanticVersionFormat { get; internal set; }
126126

127+
[JsonIgnore]
128+
VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0
129+
? VersionCalculation.VersionStrategies.None : VersionStrategies.Aggregate((one, another) => one | another);
130+
131+
[JsonPropertyName("strategies")]
132+
[JsonPropertyDescription($"Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: 'ConfiguredNextVersion', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.")]
133+
public VersionStrategies[] VersionStrategies { get; internal set; } = [];
134+
127135
[JsonIgnore]
128136
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
129137
=> Branches.ToDictionary(element => element.Key, element => (IBranchConfiguration)element.Value);

src/GitVersion.Configuration/Init/SetConfig/GlobalModeSetting.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ protected override StepResult HandleResult(
2323
switch (result)
2424
{
2525
case "1":
26-
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery);
26+
configurationBuilder.WithDeploymentMode(DeploymentMode.ManualDeployment);
2727
steps.Enqueue(this.returnToStep);
2828
return StepResult.Ok();
2929
case "2":
30-
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment);
30+
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery);
3131
steps.Enqueue(this.returnToStep);
3232
return StepResult.Ok();
3333
case "3":
34-
configurationBuilder.WithDeploymentMode(DeploymentMode.TrunkBased);
34+
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment);
3535
steps.Enqueue(this.returnToStep);
3636
return StepResult.Ok();
3737
case "0":

src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd
1010
merge-message-formats: {}
1111
update-build-number: true
1212
semantic-version-format: Strict
13+
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
1314
branches:
1415
develop:
1516
mode: ContinuousDeployment

src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd
1010
merge-message-formats: {}
1111
update-build-number: true
1212
semantic-version-format: Strict
13+
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
1314
branches:
1415
main:
1516
label: ''

0 commit comments

Comments
 (0)