Skip to content

Commit 4966764

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

31 files changed

+201
-43
lines changed

BREAKING_CHANGES.md

Lines changed: 10 additions & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ commit-date-format: yyyy-MM-dd
1111
merge-message-formats: {}
1212
update-build-number: true
1313
semantic-version-format: Strict
14+
version-strategy: NonTrunkBased
1415
branches:
1516
develop:
1617
label: alpha

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

Lines changed: 13 additions & 0 deletions
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("version-strategy: ConfigNext,TaggedCommit");
64+
65+
// Act
66+
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
67+
68+
// Assert
69+
configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfigNext | VersionStrategies.TaggedCommit);
70+
}
71+
5972
[Test]
6073
public void CanRemoveLabel()
6174
{

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

Lines changed: 1 addition & 0 deletions
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+
version-strategy: None
56
branches: {}
67
ignore:
78
sha: []

src/GitVersion.Configuration/ConfigurationBuilderBase.cs

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 19 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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>

0 commit comments

Comments
 (0)