Skip to content

Commit

Permalink
Merge pull request #3883 from HHobeck/feature/Replace-the-version-mod…
Browse files Browse the repository at this point in the history
…e-Mainline-Part-IV

Replace the version mode Mainline in 6.x (Part IV)
  • Loading branch information
HHobeck authored Jan 28, 2024
2 parents 27c86e6 + 0bd90f5 commit 3cafb59
Show file tree
Hide file tree
Showing 38 changed files with 211 additions and 176 deletions.
10 changes: 9 additions & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
* The `BranchPrefixToTrim` configuration property has been removed. `RegularExpression` is now used to capture named groups instead.
* Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
* Default `RegularExpression` for unknown branches is changed from `.*` to `(?<BranchName>.*)` to support using `{BranchName}` out-of-the-box
* The `Mainline` mode and the related implementation has been removed completely. The new `TrunkBased` version strategy should be used instead.
* The branch related property `is-mainline` in the configuration system has been renamed to `is-main-branch`
* The versioning mode has been renamed to deployment mode and consists of following values:
* ManualDeployment (previously ContinuousDelivery)
* ContinuousDelivery (previously ContinuousDeployment)
* ContinuousDeployment (new)
* At the configuration root level, a new array called `strategies` has been introduced, which can consist of on or more following values:
* ConfiguredNextVersion
* MergeMessage
* TaggedCommit
* TrackReleaseBranches
* VersionInBranchName
* TrunkBased
## v5.0.0
* Version numbers in branches other than `release` branches are no longer
Expand Down
27 changes: 13 additions & 14 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The global configuration looks like this:
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
Expand All @@ -53,6 +52,7 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
branches:
develop:
mode: ContinuousDeployment
Expand All @@ -62,7 +62,6 @@ branches:
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-main-branch: false
Expand All @@ -76,7 +75,6 @@ branches:
source-branches:
- develop
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
Expand All @@ -92,7 +90,6 @@ branches:
- main
- support
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
Expand All @@ -101,15 +98,14 @@ branches:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-]
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
Expand All @@ -124,7 +120,6 @@ branches:
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
Expand All @@ -136,8 +131,6 @@ branches:
- main
- support
- hotfix
is-source-branch-for: []
is-release-branch: true
pre-release-weight: 30000
support:
label: ''
Expand All @@ -147,7 +140,6 @@ branches:
regex: ^support[/-]
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
Expand All @@ -156,7 +148,7 @@ branches:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: .*
regex: (?<BranchName>.*)
source-branches:
- main
- develop
Expand All @@ -165,7 +157,6 @@ branches:
- pull-request
- hotfix
- support
is-source-branch-for: []
ignore:
sha: []
mode: ContinuousDelivery
Expand All @@ -176,8 +167,6 @@ track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
Expand Down Expand Up @@ -684,3 +673,13 @@ Example of invalid `Strict`, but valid `Loose`
[modes]: /docs/reference/modes
[variables]: /docs/reference/variables
[version-sources]: /docs/reference/version-sources
### strategies
Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined:
* ConfiguredNextVersion
* MergeMessage
* TaggedCommit
* TrackReleaseBranches
* VersionInBranchName
* TrunkBased
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
develop:
label: alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ public void OverwritesDefaultsWithProvidedConfig()
developConfiguration.Label.ShouldBe("dev");
}

[Test]
public void CombineVersionStrategyConfigNextAndTaggedCommit()
{
// Arrange
SetupConfigFileContent("strategies: [ConfiguredNextVersion, TaggedCommit]");

// Act
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);

// Assert
configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfiguredNextVersion | VersionStrategies.TaggedCommit);
}

[Test]
public void CanRemoveLabel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ next-version: 2.0.0
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: []
branches: {}
ignore:
sha: []
Expand Down
13 changes: 13 additions & 0 deletions src/GitVersion.Configuration/ConfigurationBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfi
private string? commitDateFormat;
private bool updateBuildNumber;
private SemanticVersionFormat semanticVersionFormat;
private VersionStrategies versionStrategy;
private Dictionary<string, string> mergeMessageFormats = new();
private readonly List<IReadOnlyDictionary<object, object?>> overrides = new();
private readonly Dictionary<string, BranchConfigurationBuilder> branchConfigurationBuilders = new();
Expand Down Expand Up @@ -199,6 +200,12 @@ public virtual TConfigurationBuilder WithSemanticVersionFormat(SemanticVersionFo
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithVersionStrategy(VersionStrategies value)
{
this.versionStrategy = value;
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithMergeMessageFormats(IReadOnlyDictionary<string, string> value)
{
this.mergeMessageFormats = new(value);
Expand Down Expand Up @@ -321,6 +328,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration
WithCommitDateFormat(value.CommitDateFormat);
WithUpdateBuildNumber(value.UpdateBuildNumber);
WithSemanticVersionFormat(value.SemanticVersionFormat);
WithVersionStrategy(value.VersionStrategy);
WithMergeMessageFormats(value.MergeMessageFormats);
foreach (var (name, branchConfiguration) in value.Branches)
{
Expand Down Expand Up @@ -358,6 +366,10 @@ public virtual IGitVersionConfiguration Build()
branches.Add(name, (BranchConfiguration)branchConfigurationBuilder.Build());
}

var versionStrategies = Enum.GetValues<VersionStrategies>()
.Where(element => element != VersionStrategies.None && this.versionStrategy.HasFlag(element))
.ToArray();

IGitVersionConfiguration configuration = new GitVersionConfiguration
{
AssemblyVersioningScheme = this.assemblyVersioningScheme,
Expand All @@ -377,6 +389,7 @@ public virtual IGitVersionConfiguration Build()
CommitDateFormat = this.commitDateFormat,
UpdateBuildNumber = this.updateBuildNumber,
SemanticVersionFormat = this.semanticVersionFormat,
VersionStrategies = versionStrategies,
Branches = branches,
MergeMessageFormats = this.mergeMessageFormats,
DeploymentMode = this.versioningMode,
Expand Down
20 changes: 1 addition & 19 deletions src/GitVersion.Configuration/ConfigurationFileLocator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using GitVersion.Extensions;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.Options;

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

var readAllText = fileSystem.ReadAllText(configFilePath);
var readConfig = ConfigurationSerializer.Read(new StringReader(readAllText));

VerifyReadConfig(readConfig);

return readConfig;
return ConfigurationSerializer.Read(new StringReader(readAllText));
}

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

private static void VerifyReadConfig(IGitVersionConfiguration configuration)
{
// Verify no branches are set to TrunkBased mode
if (configuration.Branches.Any(b => b.Value.DeploymentMode == DeploymentMode.TrunkBased))
{
throw new ConfigurationException(@"TrunkBased mode only works at the repository level, a single branch cannot be put into TrunkBased mode
This is because TrunkBased mode treats your entire git repository as an event source with each merge into the 'TrunkBased' incrementing the version.
If the docs do not help you decide on the mode open an issue to discuss what you are trying to do.");
}
}

private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, string? projectRootDirectory)
{
TryGetConfigurationFile(workingDirectory, null, out var workingConfigFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private GitFlowConfigurationBuilder()
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern,
TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private GitHubFlowConfigurationBuilder()
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern,
TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight,
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Configuration/GitVersion.Configuration.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<None Remove="SupportedWorkflows\TrunkBased\v1.yml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
</ItemGroup>
Expand All @@ -10,6 +13,7 @@
<ItemGroup>
<EmbeddedResource Include="SupportedWorkflows\GitFlow\v1.yml" />
<EmbeddedResource Include="SupportedWorkflows\GitHubFlow\v1.yml" />
<EmbeddedResource Include="SupportedWorkflows\TrunkBased\v1.yml" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/GitVersion.Configuration/GitVersionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public string? NextVersion
[JsonPropertyDefault(DefaultSemanticVersionFormat)]
public SemanticVersionFormat SemanticVersionFormat { get; internal set; }

[JsonIgnore]
VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0
? VersionCalculation.VersionStrategies.None : VersionStrategies.Aggregate((one, another) => one | another);

[JsonPropertyName("strategies")]
[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'.")]
public VersionStrategies[] VersionStrategies { get; internal set; } = [];

[JsonIgnore]
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
=> Branches.ToDictionary(element => element.Key, element => (IBranchConfiguration)element.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ protected override StepResult HandleResult(
switch (result)
{
case "1":
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery);
configurationBuilder.WithDeploymentMode(DeploymentMode.ManualDeployment);
steps.Enqueue(this.returnToStep);
return StepResult.Ok();
case "2":
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment);
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery);
steps.Enqueue(this.returnToStep);
return StepResult.Ok();
case "3":
configurationBuilder.WithDeploymentMode(DeploymentMode.TrunkBased);
configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment);
steps.Enqueue(this.returnToStep);
return StepResult.Ok();
case "0":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
branches:
develop:
mode: ContinuousDeployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
branches:
main:
label: ''
Expand Down
Loading

0 comments on commit 3cafb59

Please sign in to comment.