Skip to content

Commit

Permalink
Add new property with name strategy (type VersionStrategies) to the c…
Browse files Browse the repository at this point in the history
…onfiguration root level.
  • Loading branch information
HHobeck committed Jan 25, 2024
1 parent 1ae5536 commit cc5cc7c
Show file tree
Hide file tree
Showing 109 changed files with 40,550 additions and 43 deletions.
11 changes: 10 additions & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@
* 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)
* On the configuration root level a new property with name `version-strategy` has been introduced with following values:
* ConfigNext
* MergeMessage
* TaggedCommit
* TrackReleaseBranches
* VersionInBranchName
* NonTrunkBased = ConfigNext | MergeMessage | TaggedCommit | TrackReleaseBranches | VersionInBranchName,
* TrunkBased
## v5.0.0
* Version numbers in branches other than `release` branches are no longer
Expand Down
12 changes: 12 additions & 0 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
version-strategy: NonTrunkBased
branches:
develop:
mode: ContinuousDeployment
Expand Down Expand Up @@ -684,3 +685,14 @@ Example of invalid `Strict`, but valid `Loose`
[modes]: /docs/reference/modes
[variables]: /docs/reference/variables
[version-sources]: /docs/reference/version-sources
### version-strategy
Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined:
* ConfigNext
* MergeMessage
* TaggedCommit
* TrackReleaseBranches
* VersionInBranchName
* NonTrunkBased = ConfigNext,MergeMessage,TaggedCommit,TrackReleaseBranches,VersionInBranchName
* TrunkBased
9 changes: 9 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 @@ -377,6 +385,7 @@ public virtual IGitVersionConfiguration Build()
CommitDateFormat = this.commitDateFormat,
UpdateBuildNumber = this.updateBuildNumber,
SemanticVersionFormat = this.semanticVersionFormat,
VersionStrategy = this.versionStrategy,
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,
VersionStrategy = ConfigurationConstants.DefaultVersionStrategy,
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,
VersionStrategy = ConfigurationConstants.DefaultVersionStrategy,
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
5 changes: 5 additions & 0 deletions src/GitVersion.Configuration/GitVersionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public string? NextVersion
[JsonPropertyDefault(DefaultSemanticVersionFormat)]
public SemanticVersionFormat SemanticVersionFormat { get; internal set; }

[JsonPropertyName("version-strategy")]
[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'.")]
[JsonPropertyDefault(DefaultVersionStrategy)]
public VersionStrategies VersionStrategy { 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
versioning-strategy: '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
versioning-strategy: 'ConfigNext,MergeMessage,TaggedCommit,TrackReleaseBranches,VersionInBranchName'
branches:
main:
label: ''
Expand Down
83 changes: 83 additions & 0 deletions src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
versioning-strategy: TrunkBased
branches:
main:
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- release
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^releases?[/-]
source-branches:
- main
- release
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- main
- release
- feature
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- release
- feature
pre-release-weight: 30000
unknown:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: (?<BranchName>.*)
source-branches:
- main
- release
- feature
- pull-request
ignore:
sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ namespace GitVersion.Core.Tests.IntegrationTests;
[TestFixture]
internal class ComparingTheBehaviorOfDifferentDeploymentModes
{
private static readonly GitHubFlowConfigurationBuilder configurationBuilder = GitHubFlowConfigurationBuilder.New
private static GitHubFlowConfigurationBuilder GetConfigurationBuilder() => GitHubFlowConfigurationBuilder.New
.WithLabel(null)
.WithBranch("main", _ => _
.WithIncrement(IncrementStrategy.Patch).WithLabel(null)
).WithBranch("feature", _ => _
.WithIncrement(IncrementStrategy.Inherit).WithLabel("{BranchName}")
);

private static readonly IGitVersionConfiguration trunkBased = configurationBuilder
.WithDeploymentMode(DeploymentMode.TrunkBased)
private static readonly IGitVersionConfiguration trunkBased = GetConfigurationBuilder()
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
.Build();

private static readonly IGitVersionConfiguration continuousDeployment = configurationBuilder
private static readonly IGitVersionConfiguration continuousDeployment = GetConfigurationBuilder()
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.Build();

private static readonly IGitVersionConfiguration continuousDelivery = configurationBuilder
private static readonly IGitVersionConfiguration continuousDelivery = GetConfigurationBuilder()
.WithDeploymentMode(DeploymentMode.ContinuousDelivery)
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
.Build();

private static readonly IGitVersionConfiguration manualDeployment = configurationBuilder
private static readonly IGitVersionConfiguration manualDeployment = GetConfigurationBuilder()
.WithDeploymentMode(DeploymentMode.ManualDeployment)
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ManualDeployment))
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ManualDeployment))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GitVersion.Core.Tests.IntegrationTests;
public class TrunkBasedDevelopmentScenarios : TestBase
{
private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowConfigurationBuilder.New
.WithDeploymentMode(DeploymentMode.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder
.WithIsMainBranch(true).WithIncrement(IncrementStrategy.Patch)
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
Expand Down Expand Up @@ -511,7 +511,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO
public void VerifyIncrementConfigIsHonoured()
{
var minorIncrementConfig = GitFlowConfigurationBuilder.New
.WithDeploymentMode(DeploymentMode.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
.WithIncrement(IncrementStrategy.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void CanUseConventionalCommitsToBumpVersion(string commitMessage, string
.WithMinorVersionBumpMessage("^(feat)(\\([\\w\\s-]*\\))?:")
// For future debugging of this regex: https://regex101.com/r/oFpqxA/2
.WithPatchVersionBumpMessage("^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:")
.WithDeploymentMode(DeploymentMode.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder.WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.Build();

Expand Down
Loading

0 comments on commit cc5cc7c

Please sign in to comment.