diff --git a/docs/input/docs/configuration.md b/docs/input/docs/configuration.md index d0f751d9e3..134c92045e 100644 --- a/docs/input/docs/configuration.md +++ b/docs/input/docs/configuration.md @@ -199,6 +199,10 @@ The number of characters to pad `CommitsSinceVersionSource` to in the set to `4`, which will pad the `CommitsSinceVersionSource` value of `1` to `0001`. +### tag-pre-release-weight + +The pre-release weight in case of tagged commits. If the value is not set in the configuration, a default weight of 60000 is used instead. If the `WeightedPreReleaseNumber` [variable](./more-info/variables) is 0 and this parameter is set, its value is used. This helps if your branching model is GitFlow and the last release build, which is often tagged, can utilise this parameter to produce a monotonically increasing build number. + ### commit-message-incrementing Sets whether it should be possible to increment the version with special syntax diff --git a/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index f27fc41426..b7a78223f8 100644 --- a/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -10,6 +10,7 @@ no-bump-message: '\+semver:\s?(none|skip)' legacy-semver-padding: 4 build-metadata-padding: 4 commits-since-version-source-padding: 4 +tag-pre-release-weight: 60000 commit-message-incrementing: Enabled branches: develop: diff --git a/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs index 4c179f3db2..bbc0685ecf 100644 --- a/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs +++ b/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs @@ -43,7 +43,7 @@ public TestEffectiveConfiguration( majorMessage, minorMessage, patchMessage, noBumpMessage, commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding, versionFilters ?? Enumerable.Empty(), - tracksReleaseBranches, isRelease, commitDateFormat, updateBuildNumber, 0) + tracksReleaseBranches, isRelease, commitDateFormat, updateBuildNumber, 0, 0) { } } diff --git a/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs new file mode 100644 index 0000000000..2d201b911d --- /dev/null +++ b/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs @@ -0,0 +1,107 @@ +using GitTools.Testing; +using GitVersion.Configuration; +using GitVersion.Model.Configuration; +using GitVersion.VersionCalculation; +using NUnit.Framework; +using Shouldly; + +namespace GitVersionCore.Tests.IntegrationTests +{ + [TestFixture] + class VersionInTagScenarios + { + [Test] + public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheDefaultValue() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + }; + config.ApplyDefaults(); + + // Act + using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); + fixture.MakeATaggedCommit("1.1.0"); + var version = fixture.GetVersion(config); + + // Assert + version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); + } + + [Test] + public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + TagPreReleaseWeight = 65535 + }; + config.ApplyDefaults(); + + // Act + using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); + fixture.MakeATaggedCommit("1.1.0"); + var version = fixture.GetVersion(config); + + // Assert + version.AssemblySemFileVer.ShouldBe("1.1.0.65535"); + } + + [Test] + public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + TagPreReleaseWeight = 65535, + VersioningMode = VersioningMode.ContinuousDeployment + }; + config.ApplyDefaults(); + + // Act + using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); + fixture.Checkout("master"); + fixture.MergeNoFF("develop"); + fixture.Checkout("develop"); + fixture.MakeACommit("Feature commit 1"); + fixture.BranchTo("release/1.1.0"); + fixture.MakeACommit("Release commit 1"); + fixture.AssertFullSemver("1.1.0-beta.1", config); + fixture.ApplyTag("1.1.0"); + var version = fixture.GetVersion(config); + + // Assert + version.AssemblySemFileVer.ShouldBe("1.1.0.65535"); + } + + [Test] + public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheDefaultValue() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + VersioningMode = VersioningMode.ContinuousDeployment + }; + config.ApplyDefaults(); + + // Act + using var fixture = new BaseGitFlowRepositoryFixture("1.0.0"); + fixture.Checkout("master"); + fixture.MergeNoFF("develop"); + fixture.Checkout("develop"); + fixture.MakeACommit("Feature commit 1"); + fixture.BranchTo("release/1.1.0"); + fixture.MakeACommit("Release commit 1"); + fixture.AssertFullSemver("1.1.0-beta.1", config); + fixture.ApplyTag("1.1.0"); + var version = fixture.GetVersion(config); + + // Assert + version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); + } + } +} diff --git a/src/GitVersionCore.Tests/Model/CommitDateTests.cs b/src/GitVersionCore.Tests/Model/CommitDateTests.cs index f98b6a8a42..a787843f1d 100644 --- a/src/GitVersionCore.Tests/Model/CommitDateTests.cs +++ b/src/GitVersionCore.Tests/Model/CommitDateTests.cs @@ -29,7 +29,7 @@ public void CommitDateFormatTest(string format, string expectedOutcome) }, new EffectiveConfiguration( AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme.MajorMinorPatch, "", "", "", VersioningMode.ContinuousDelivery, "", "", "", IncrementStrategy.Inherit, - "", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty(), false, true, format, false, 0) + "", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty(), false, true, format, false, 0, 0) ); Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome)); diff --git a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranch.approved.txt b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranch.approved.txt index 3e5bfc4add..2db1189a71 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranch.approved.txt +++ b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranch.approved.txt @@ -6,7 +6,7 @@ "PreReleaseTagWithDash":"", "PreReleaseLabel":"", "PreReleaseNumber":"", - "WeightedPreReleaseNumber":"", + "WeightedPreReleaseNumber":0, "BuildMetaData":5, "BuildMetaDataPadded":"0005", "FullBuildMetaData":"5.Branch.feature-123.Sha.commitSha", diff --git a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInfoFormat.approved.txt b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInfoFormat.approved.txt index d19cf3a4cc..652d13a6d2 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInfoFormat.approved.txt +++ b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInfoFormat.approved.txt @@ -6,7 +6,7 @@ "PreReleaseTagWithDash":"", "PreReleaseLabel":"", "PreReleaseNumber":"", - "WeightedPreReleaseNumber":"", + "WeightedPreReleaseNumber":0, "BuildMetaData":5, "BuildMetaDataPadded":"0005", "FullBuildMetaData":"5.Branch.feature-123.Sha.commitSha", diff --git a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt index 0a21e2a35d..467940e5e2 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt +++ b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt @@ -6,7 +6,7 @@ "PreReleaseTagWithDash":"", "PreReleaseLabel":"", "PreReleaseNumber":"", - "WeightedPreReleaseNumber":"", + "WeightedPreReleaseNumber":0, "BuildMetaData":5, "BuildMetaDataPadded":"0005", "FullBuildMetaData":"5.Branch.develop.Sha.commitSha", diff --git a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt index 68fa187286..b2d61c753e 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt +++ b/src/GitVersionCore.Tests/VersionCalculation/Approved/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt @@ -6,7 +6,7 @@ "PreReleaseTagWithDash":"", "PreReleaseLabel":"", "PreReleaseNumber":"", - "WeightedPreReleaseNumber":"", + "WeightedPreReleaseNumber":0, "BuildMetaData":5, "BuildMetaDataPadded":"0005", "FullBuildMetaData":"5.Sha.commitSha", diff --git a/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFile.approved.txt b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFile.approved.txt index effba7df8e..5ca86f99bf 100644 --- a/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFile.approved.txt +++ b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFile.approved.txt @@ -30,5 +30,5 @@ - + \ No newline at end of file diff --git a/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt index effba7df8e..5ca86f99bf 100644 --- a/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt +++ b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt @@ -30,5 +30,5 @@ - + \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/ConfigExtensions.cs b/src/GitVersionCore/Configuration/ConfigExtensions.cs index e8b5da813d..1b438952db 100644 --- a/src/GitVersionCore/Configuration/ConfigExtensions.cs +++ b/src/GitVersionCore/Configuration/ConfigExtensions.cs @@ -37,6 +37,7 @@ public static void Reset(this Config config) config.CommitsSinceVersionSourcePadding ??= 4; config.CommitDateFormat ??= "yyyy-MM-dd"; config.UpdateBuildNumber ??= true; + config.TagPreReleaseWeight ??= DefaultTagPreReleaseWeight; var configBranches = config.Branches.ToList(); @@ -128,6 +129,7 @@ public static void Reset(this Config config) { Config.MasterBranchRegex, 55000 } }; private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Inherit; + private const int DefaultTagPreReleaseWeight = 60000; public static void ApplyBranchDefaults(this Config config, BranchConfig branchConfig, @@ -182,6 +184,7 @@ public static void ApplyOverridesTo(this Config config, Config overrideConfig) config.VersioningMode = overrideConfig.VersioningMode; config.AssemblyFileVersioningFormat = overrideConfig.AssemblyFileVersioningFormat; config.TagPrefix = string.IsNullOrWhiteSpace(overrideConfig.TagPrefix) ? config.TagPrefix : overrideConfig.TagPrefix; + config.TagPreReleaseWeight = overrideConfig.TagPreReleaseWeight; } public static BranchConfig GetConfigForBranch(this Config config, string branchName) @@ -265,9 +268,9 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config var noBumpMessage = configuration.NoBumpMessage; var commitDateFormat = configuration.CommitDateFormat; var updateBuildNumber = configuration.UpdateBuildNumber ?? true; + var tagPreReleaseWeight = configuration.TagPreReleaseWeight ?? DefaultTagPreReleaseWeight; var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; - return new EffectiveConfiguration( assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, @@ -285,7 +288,8 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config currentBranchConfig.IsReleaseBranch.Value, commitDateFormat, updateBuildNumber, - preReleaseWeight); + preReleaseWeight, + tagPreReleaseWeight); } public static string GetBranchSpecificTag(this EffectiveConfiguration configuration, ILog log, string branchFriendlyName, string branchNameOverride) diff --git a/src/GitVersionCore/Model/Configuration/Config.cs b/src/GitVersionCore/Model/Configuration/Config.cs index cc03dd0f33..c5db8aa6bb 100644 --- a/src/GitVersionCore/Model/Configuration/Config.cs +++ b/src/GitVersionCore/Model/Configuration/Config.cs @@ -76,6 +76,9 @@ public string NextVersion [YamlMember(Alias = "commits-since-version-source-padding")] public int? CommitsSinceVersionSourcePadding { get; set; } + [YamlMember(Alias = "tag-pre-release-weight")] + public int? TagPreReleaseWeight { get; set; } + [YamlMember(Alias = "commit-message-incrementing")] public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } diff --git a/src/GitVersionCore/Model/Configuration/EffectiveConfiguration.cs b/src/GitVersionCore/Model/Configuration/EffectiveConfiguration.cs index 8070813436..9c50c050d9 100644 --- a/src/GitVersionCore/Model/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersionCore/Model/Configuration/EffectiveConfiguration.cs @@ -35,7 +35,8 @@ public EffectiveConfiguration( bool isCurrentBranchRelease, string commitDateFormat, bool updateBuildNumber, - int preReleaseWeight) + int preReleaseWeight, + int tagPreReleaseWeight) { AssemblyVersioningScheme = assemblyVersioningScheme; AssemblyFileVersioningScheme = assemblyFileVersioningScheme; @@ -66,6 +67,7 @@ public EffectiveConfiguration( CommitDateFormat = commitDateFormat; UpdateBuildNumber = updateBuildNumber; PreReleaseWeight = preReleaseWeight; + TagPreReleaseWeight = tagPreReleaseWeight; } public bool TracksReleaseBranches { get; private set; } @@ -124,5 +126,7 @@ public EffectiveConfiguration( public bool UpdateBuildNumber { get; private set; } public int PreReleaseWeight { get; private set; } + + public int TagPreReleaseWeight { get; private set; } } } diff --git a/src/GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs b/src/GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs index b83844f046..b681dad2ab 100644 --- a/src/GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs +++ b/src/GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersionFormatValues.cs @@ -30,7 +30,7 @@ public SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfiguratio public string PreReleaseNumber => semver.PreReleaseTag.HasTag() ? semver.PreReleaseTag.Number.ToString() : null; - public string WeightedPreReleaseNumber => semver.PreReleaseTag.HasTag() ? (semver.PreReleaseTag.Number + config.PreReleaseWeight).ToString() : null; + public string WeightedPreReleaseNumber => GetWeightedPreReleaseNumber(); public string BuildMetaData => semver.BuildMetaData; @@ -82,5 +82,17 @@ public SemanticVersionFormatValues(SemanticVersion semver, EffectiveConfiguratio public string CommitsSinceVersionSource => semver.BuildMetaData.CommitsSinceVersionSource.ToString(CultureInfo.InvariantCulture); public string CommitsSinceVersionSourcePadded => semver.BuildMetaData.CommitsSinceVersionSource.ToString(CultureInfo.InvariantCulture).PadLeft(config.CommitsSinceVersionSourcePadding, '0'); + + private String GetWeightedPreReleaseNumber() + { + var weightedPreReleaseNumber = + semver.PreReleaseTag.HasTag() ? (semver.PreReleaseTag.Number + config.PreReleaseWeight).ToString() : null; + if (string.IsNullOrEmpty(weightedPreReleaseNumber)) + { + weightedPreReleaseNumber = $"{config.TagPreReleaseWeight}"; + } + + return weightedPreReleaseNumber; + } } }