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

When incrementing version using commit message, we only consider tags with a valid version #3889

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
2 changes: 1 addition & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* The `useBranchName` magic string has been removed. Instead use `{BranchName}` for `label`.
* 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
* 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:
Expand Down
19 changes: 13 additions & 6 deletions src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -10,10 +11,14 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
strategies:
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
develop:
mode: ContinuousDeployment
label: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
Expand All @@ -38,6 +43,7 @@ branches:
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
Expand All @@ -53,7 +59,7 @@ branches:
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-](?<BranchName>.+)
Expand All @@ -80,7 +86,7 @@ branches:
- hotfix
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
mode: ManualDeployment
label: beta
increment: Inherit
regex: ^hotfix(es)?[/-]
Expand All @@ -89,6 +95,7 @@ branches:
- main
- support
- hotfix
is-release-branch: true
pre-release-weight: 30000
support:
label: ''
Expand All @@ -103,10 +110,10 @@ branches:
is-main-branch: true
pre-release-weight: 55000
unknown:
mode: ContinuousDelivery
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: (?<BranchName>.*)
regex: (?<BranchName>.+)
source-branches:
- main
- develop
Expand Down
15 changes: 11 additions & 4 deletions src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -10,7 +11,12 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
strategies:
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
main:
label: ''
Expand All @@ -25,6 +31,7 @@ branches:
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
Expand All @@ -38,7 +45,7 @@ branches:
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-](?<BranchName>.+)
Expand All @@ -59,10 +66,10 @@ branches:
- feature
pre-release-weight: 30000
unknown:
mode: ContinuousDelivery
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: (?<BranchName>.*)
regex: (?<BranchName>.+)
source-branches:
- main
- release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -10,7 +11,9 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [TrunkBased, ConfiguredNextVersion]
strategies:
- TrunkBased
- ConfiguredNextVersion
branches:
main:
mode: ContinuousDeployment
Expand Down Expand Up @@ -48,7 +51,7 @@ branches:
unknown:
mode: ManualDeployment
increment: Inherit
regex: (?<BranchName>.*)
regex: (?<BranchName>.+)
source-branches:
- main
- release
Expand Down
74 changes: 71 additions & 3 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,80 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.VersionCalculation;
using LibGit2Sharp;

namespace GitVersion.Core.Tests.IntegrationTests;

[TestFixture]
public class OtherBranchScenarios : TestBase
{
[TestCase("", "NotAVersion", "2.0.0-1", "1.9.0", "1.9.0", "1.9.1-1")]
[TestCase("", "1.5.0", "1.5.0", "1.9.0", "1.9.0", "1.9.1-1")]
[TestCase("prefix", "1.5.0", "2.0.0-1", "1.9.0", "2.0.0-1", "2.0.0-2")]
[TestCase("prefix", "1.5.0", "2.0.0-1", "prefix1.9.0", "1.9.0", "1.9.1-1")]
[TestCase("prefix", "prefix1.5.0", "1.5.0", "1.9.0", "1.5.0", "1.5.1-1")]
public void CanUseCommitMessagesToBumpVersion_TagsTakePriorityOnlyIfVersions(
string tagPrefix,
string firstTag,
string expectedAfterFirstTag,
string secondTag,
string expectedAfterSecondTag,
string expectedVersionAfterNewCommit)
{
var configuration = GitFlowConfigurationBuilder.New
.WithTagPrefix(tagPrefix)
.Build();

using var fixture = new EmptyRepositoryFixture();
var repo = fixture.Repository;

repo.MakeATaggedCommit($"{tagPrefix}1.0.0");
repo.MakeACommit("+semver:major");
fixture.AssertFullSemver("2.0.0-1", configuration);

repo.ApplyTag(firstTag);
fixture.AssertFullSemver(expectedAfterFirstTag, configuration);

repo.ApplyTag(secondTag);
fixture.AssertFullSemver(expectedAfterSecondTag, configuration);

repo.MakeACommit();
fixture.AssertFullSemver(expectedVersionAfterNewCommit, configuration);
}

[TestCase("", null, "1.9.0-1", "2.0.0-1+1", ExpectedResult = "1.9.0-1")]
[TestCase("", "", "1.9.0-1", "2.0.0-1+1", ExpectedResult = "1.9.0-1")]
[TestCase("", "foo", "1.9.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
[TestCase("", "bar", "1.9.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]
[TestCase("prefix", null, "1.9.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
[TestCase("prefix", "", "1.9.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
[TestCase("prefix", "foo", "1.9.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
[TestCase("prefix", "bar", "1.9.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]

[TestCase("", null, "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.1.0-1")]
[TestCase("", "", "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.1.0-1")]
[TestCase("", "foo", "2.1.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.1.0-foo.1+1")]
[TestCase("", "bar", "2.1.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.1.0-bar.1+1")]
[TestCase("prefix", null, "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
[TestCase("prefix", "", "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
[TestCase("prefix", "foo", "2.1.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
[TestCase("prefix", "bar", "2.1.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]
public string WhenTaggingACommitAsPreRelease(string tagPrefix, string? label, string tag, string expectedVersion)
{
var configuration = GitFlowConfigurationBuilder.New.WithLabel(null).WithTagPrefix(tagPrefix)
.WithBranch("main", _ => _.WithLabel(label).WithDeploymentMode(DeploymentMode.ManualDeployment))
.Build();

using EmptyRepositoryFixture fixture = new("main");

fixture.MakeATaggedCommit($"{tagPrefix}1.0.0");
fixture.MakeACommit("+semver:major");
fixture.AssertFullSemver(expectedVersion, configuration);
fixture.ApplyTag(tag);

return fixture!.GetVersion(configuration).FullSemVer;
}

/// <summary>
/// https://github.com/GitTools/GitVersion/issues/2340
/// </summary>
Expand Down Expand Up @@ -34,7 +102,7 @@ public void ShouldOnlyConsiderTagsMatchingOfCurrentBranch()
public void CanTakeVersionFromReleaseBranch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("release", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.*)"))
.WithBranch("release", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.+)"))
.Build();

using var fixture = new EmptyRepositoryFixture();
Expand All @@ -52,7 +120,7 @@ public void CanTakeVersionFromReleaseBranch()
public void CanTakeVersionFromHotfixBranch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("hotfix", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.*)"))
.WithBranch("hotfix", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.+)"))
.Build();

using var fixture = new EmptyRepositoryFixture();
Expand Down Expand Up @@ -112,7 +180,7 @@ public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label,
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("other", builder => builder
.WithIncrement(IncrementStrategy.Patch)
.WithRegularExpression("(?<BranchName>.*)")
.WithRegularExpression("(?<BranchName>.+)")
.WithSourceBranches()
.WithLabel(label))
.Build();
Expand Down
4 changes: 3 additions & 1 deletion src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
string? tagPrefix,
SemanticVersionFormat format);

ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
string? tagPrefix,
SemanticVersionFormat format,
params IBranch[] excludeBranches);
Expand All @@ -25,4 +25,6 @@ ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranc
string? tagPrefix,
SemanticVersionFormat format,
params IBranch[] excludeBranches);

ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format);
}
6 changes: 3 additions & 3 deletions src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(IBr

if (!configuration.IsMainBranch && !configuration.IsReleaseBranch)
{
var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainlineBranches(
var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainBranches(
tagPrefix: configuration.TagPrefix,
format: configuration.SemanticVersionFormat,
excludeBranches: branch
Expand Down Expand Up @@ -188,7 +188,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
return result;
}

public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches)
{
tagPrefix ??= string.Empty;
Expand Down Expand Up @@ -236,7 +236,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
return GetElements().Distinct().ToLookup(element => element.Tag.Commit, element => element);
}

private ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format)
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format)
{
tagPrefix ??= string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ GitVersion.VersionCalculation.DeploymentMode.ManualDeployment = 0 -> GitVersion.
GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder
GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable<GitVersion.Configuration.EffectiveBranchConfiguration!>!
GitVersion.VersionCalculation.IIncrementStrategyFinder
GitVersion.VersionCalculation.IIncrementStrategyFinder.DetermineIncrementedField(GitVersion.ICommit! currentCommit, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveConfiguration! configuration) -> GitVersion.VersionField
GitVersion.VersionCalculation.IIncrementStrategyFinder.DetermineIncrementedField(GitVersion.ICommit! currentCommit, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveConfiguration! configuration, string? label) -> GitVersion.VersionField
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForcedByCommit(GitVersion.ICommit! commit, GitVersion.Configuration.EffectiveConfiguration! configuration) -> GitVersion.VersionField
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, GitVersion.ICommit![]! commits) -> GitVersion.VersionField?
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetMergedCommits(GitVersion.ICommit! mergeCommit, int index) -> System.Collections.Generic.IEnumerable<GitVersion.ICommit!>!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace GitVersion.VersionCalculation;

public interface IIncrementStrategyFinder
{
VersionField DetermineIncrementedField(ICommit currentCommit, BaseVersion baseVersion, EffectiveConfiguration configuration);
VersionField DetermineIncrementedField(
ICommit currentCommit, BaseVersion baseVersion, EffectiveConfiguration configuration, string? label);

VersionField? GetIncrementForCommits(
string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage,
Expand Down
Loading
Loading