Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the version mode Mainline in 6.x (Part IV) #3883

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit unsure about the name TrackReleaseBranches. We should be consistent with whether we use a verb (Track) in the enum values and whether we use singular (Commit) or plural (Branches) form.

Copy link
Contributor Author

@HHobeck HHobeck Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to any renaming as long we are renaming the underlying classes who implements the strategy as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TrackReleaseBranches really a versioning strategy, though? Isn't it more like a branch configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it is a version strategy yes. What is your suggestion!? To delete it? I thought this is the concept of our core domain to have provider based (strategy based) approach to determine the next version. And you can control whether or not it is called using the strategies property on the configuration root level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like the configurable strategy approach. But like next-version, tracks-release-branches is a configuration property. It's strange to have tracks-release-branches configured for a branch, but ignored because TrackReleaseBranches isn't configured.

Copy link
Contributor Author

@HHobeck HHobeck Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here I would say like I already did previously: You need to think of the property like a characteristic of a branch or a characteristic of the repository which is generally isolated of the actual used strategies. If someone decide e.g. not to use the NextVersionVersionStrategy but define next-version then it would be fine to ignore it (Actually if not it would be a bug).

And your second example is even easy to argument. The track-release-braches property will be used in the TrackReleaseBranchesVersionStrategy and TrunkBaseVersionStrategy. If you decide to use TrunkBaseVersionStrategy you should not execute the TrackReleaseBranchesVersionStrategy because it gives you maybe a wrong behavior for the TrunkBased (Mainline) workflow.

Does it make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of the possibility of tracks-release-branches being used by more than one strategy. That's not the case for next-version, is it?

Copy link
Contributor Author

@HHobeck HHobeck Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was mistaken. I have mixed tracks-release-branches with track-merge-message in my mind. You are right tracks-release-branches will be used in TrackReleaseBranchesVersionStrategy and next-version in ConfiguredNextVersionVersionStrategy only. But that can change. Who knows!?

* 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; } = [];
asbjornu marked this conversation as resolved.
Show resolved Hide resolved

[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
Loading