Skip to content

Commit cc5cc7c

Browse files
committed
Add new property with name strategy (type VersionStrategies) to the configuration root level.
1 parent 1ae5536 commit cc5cc7c

File tree

109 files changed

+40550
-43
lines changed

Some content is hidden

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

109 files changed

+40550
-43
lines changed

BREAKING_CHANGES.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@
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+
* On the configuration root level a new property with name `version-strategy` has been introduced with following values:
42+
* ConfigNext
43+
* MergeMessage
44+
* TaggedCommit
45+
* TrackReleaseBranches
46+
* VersionInBranchName
47+
* NonTrunkBased = ConfigNext | MergeMessage | TaggedCommit | TrackReleaseBranches | VersionInBranchName,
48+
* TrunkBased
49+
4150
## v5.0.0
4251
4352
* Version numbers in branches other than `release` branches are no longer

docs/input/docs/reference/configuration.md

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ commit-date-format: yyyy-MM-dd
5353
merge-message-formats: {}
5454
update-build-number: true
5555
semantic-version-format: Strict
56+
version-strategy: NonTrunkBased
5657
branches:
5758
develop:
5859
mode: ContinuousDeployment
@@ -684,3 +685,14 @@ Example of invalid `Strict`, but valid `Loose`
684685
[modes]: /docs/reference/modes
685686
[variables]: /docs/reference/variables
686687
[version-sources]: /docs/reference/version-sources
688+
689+
### version-strategy
690+
691+
Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined:
692+
* ConfigNext
693+
* MergeMessage
694+
* TaggedCommit
695+
* TrackReleaseBranches
696+
* VersionInBranchName
697+
* NonTrunkBased = ConfigNext,MergeMessage,TaggedCommit,TrackReleaseBranches,VersionInBranchName
698+
* TrunkBased

src/GitVersion.Configuration/ConfigurationBuilderBase.cs

+9
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
{
@@ -377,6 +385,7 @@ public virtual IGitVersionConfiguration Build()
377385
CommitDateFormat = this.commitDateFormat,
378386
UpdateBuildNumber = this.updateBuildNumber,
379387
SemanticVersionFormat = this.semanticVersionFormat,
388+
VersionStrategy = this.versionStrategy,
380389
Branches = branches,
381390
MergeMessageFormats = this.mergeMessageFormats,
382391
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+
VersionStrategy = ConfigurationConstants.DefaultVersionStrategy,
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+
VersionStrategy = ConfigurationConstants.DefaultVersionStrategy,
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

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

127+
[JsonPropertyName("version-strategy")]
128+
[JsonPropertyDescription($"Specifies which version strategy (one or more) will be used to determine the next version. Following values are available: 'ConfigNext', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.")]
129+
[JsonPropertyDefault(DefaultVersionStrategy)]
130+
public VersionStrategies VersionStrategy { get; internal set; }
131+
127132
[JsonIgnore]
128133
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
129134
=> 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+
versioning-strategy: '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+
versioning-strategy: 'ConfigNext,MergeMessage,TaggedCommit,TrackReleaseBranches,VersionInBranchName'
1314
branches:
1415
main:
1516
label: ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
assembly-versioning-scheme: MajorMinorPatch
2+
assembly-file-versioning-scheme: MajorMinorPatch
3+
tag-prefix: '[vV]?'
4+
major-version-bump-message: '\+semver:\s?(breaking|major)'
5+
minor-version-bump-message: '\+semver:\s?(feature|minor)'
6+
patch-version-bump-message: '\+semver:\s?(fix|patch)'
7+
no-bump-message: '\+semver:\s?(none|skip)'
8+
tag-pre-release-weight: 60000
9+
commit-date-format: yyyy-MM-dd
10+
merge-message-formats: {}
11+
update-build-number: true
12+
semantic-version-format: Strict
13+
versioning-strategy: TrunkBased
14+
branches:
15+
main:
16+
label: ''
17+
increment: Patch
18+
prevent-increment-of-merged-branch-version: true
19+
track-merge-target: false
20+
regex: ^master$|^main$
21+
source-branches:
22+
- release
23+
tracks-release-branches: false
24+
is-release-branch: false
25+
is-main-branch: true
26+
pre-release-weight: 55000
27+
release:
28+
label: beta
29+
increment: None
30+
prevent-increment-of-merged-branch-version: true
31+
track-merge-target: false
32+
regex: ^releases?[/-]
33+
source-branches:
34+
- main
35+
- release
36+
tracks-release-branches: false
37+
is-release-branch: true
38+
is-main-branch: false
39+
pre-release-weight: 30000
40+
feature:
41+
mode: ContinuousDelivery
42+
label: '{BranchName}'
43+
increment: Inherit
44+
regex: ^features?[/-](?<BranchName>.+)
45+
source-branches:
46+
- main
47+
- release
48+
- feature
49+
pre-release-weight: 30000
50+
pull-request:
51+
mode: ContinuousDelivery
52+
label: PullRequest
53+
increment: Inherit
54+
label-number-pattern: '[/-](?<number>\d+)'
55+
regex: ^(pull|pull\-requests|pr)[/-]
56+
source-branches:
57+
- main
58+
- release
59+
- feature
60+
pre-release-weight: 30000
61+
unknown:
62+
mode: ContinuousDelivery
63+
label: '{BranchName}'
64+
increment: Inherit
65+
regex: (?<BranchName>.*)
66+
source-branches:
67+
- main
68+
- release
69+
- feature
70+
- pull-request
71+
ignore:
72+
sha: []
73+
mode: ContinuousDelivery
74+
label: '{BranchName}'
75+
increment: Inherit
76+
prevent-increment-of-merged-branch-version: false
77+
track-merge-target: false
78+
track-merge-message: true
79+
commit-message-incrementing: Enabled
80+
regex: ''
81+
tracks-release-branches: false
82+
is-release-branch: false
83+
is-main-branch: false

src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@ namespace GitVersion.Core.Tests.IntegrationTests;
1111
[TestFixture]
1212
internal class ComparingTheBehaviorOfDifferentDeploymentModes
1313
{
14-
private static readonly GitHubFlowConfigurationBuilder configurationBuilder = GitHubFlowConfigurationBuilder.New
14+
private static GitHubFlowConfigurationBuilder GetConfigurationBuilder() => GitHubFlowConfigurationBuilder.New
1515
.WithLabel(null)
1616
.WithBranch("main", _ => _
1717
.WithIncrement(IncrementStrategy.Patch).WithLabel(null)
1818
).WithBranch("feature", _ => _
1919
.WithIncrement(IncrementStrategy.Inherit).WithLabel("{BranchName}")
2020
);
2121

22-
private static readonly IGitVersionConfiguration trunkBased = configurationBuilder
23-
.WithDeploymentMode(DeploymentMode.TrunkBased)
22+
private static readonly IGitVersionConfiguration trunkBased = GetConfigurationBuilder()
23+
.WithVersionStrategy(VersionStrategies.TrunkBased)
2424
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
2525
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
2626
.Build();
2727

28-
private static readonly IGitVersionConfiguration continuousDeployment = configurationBuilder
28+
private static readonly IGitVersionConfiguration continuousDeployment = GetConfigurationBuilder()
2929
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
3030
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
3131
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
3232
.Build();
3333

34-
private static readonly IGitVersionConfiguration continuousDelivery = configurationBuilder
34+
private static readonly IGitVersionConfiguration continuousDelivery = GetConfigurationBuilder()
3535
.WithDeploymentMode(DeploymentMode.ContinuousDelivery)
3636
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
3737
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
3838
.Build();
3939

40-
private static readonly IGitVersionConfiguration manualDeployment = configurationBuilder
40+
private static readonly IGitVersionConfiguration manualDeployment = GetConfigurationBuilder()
4141
.WithDeploymentMode(DeploymentMode.ManualDeployment)
4242
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ManualDeployment))
4343
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ManualDeployment))

src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GitVersion.Core.Tests.IntegrationTests;
88
public class TrunkBasedDevelopmentScenarios : TestBase
99
{
1010
private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowConfigurationBuilder.New
11-
.WithDeploymentMode(DeploymentMode.TrunkBased)
11+
.WithVersionStrategy(VersionStrategies.TrunkBased)
1212
.WithBranch("main", builder => builder
1313
.WithIsMainBranch(true).WithIncrement(IncrementStrategy.Patch)
1414
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
@@ -511,7 +511,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO
511511
public void VerifyIncrementConfigIsHonoured()
512512
{
513513
var minorIncrementConfig = GitFlowConfigurationBuilder.New
514-
.WithDeploymentMode(DeploymentMode.TrunkBased)
514+
.WithVersionStrategy(VersionStrategies.TrunkBased)
515515
.WithBranch("main", builder => builder
516516
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
517517
.WithIncrement(IncrementStrategy.None)

src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void CanUseConventionalCommitsToBumpVersion(string commitMessage, string
8686
.WithMinorVersionBumpMessage("^(feat)(\\([\\w\\s-]*\\))?:")
8787
// For future debugging of this regex: https://regex101.com/r/oFpqxA/2
8888
.WithPatchVersionBumpMessage("^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:")
89-
.WithDeploymentMode(DeploymentMode.TrunkBased)
89+
.WithVersionStrategy(VersionStrategies.TrunkBased)
9090
.WithBranch("main", builder => builder.WithDeploymentMode(DeploymentMode.ContinuousDeployment))
9191
.Build();
9292

0 commit comments

Comments
 (0)