From b264fff5ec7958a3fa4c327718187aeb1cf099ae Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Sun, 5 Apr 2020 21:35:45 +0200 Subject: [PATCH 1/5] Added a failing testcase to set up the expectations for translating the pre-release labels in Git tags to weights. --- .../TaggedCommitVersionStrategyTests.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs diff --git a/src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs b/src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs new file mode 100644 index 0000000000..340685b44f --- /dev/null +++ b/src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Linq; +using GitTools.Testing; +using GitVersion.Configuration; +using GitVersion.Extensions; +using GitVersion.Model.Configuration; +using GitVersion.VersionCalculation; +using GitVersionCore.Tests.Helpers; +using LibGit2Sharp; +using NUnit.Framework; +using Shouldly; + +namespace GitVersionCore.Tests.VersionCalculation.Strategies +{ + [TestFixture] + public class TaggedCommitVersionStrategyTests : TestBase + { + [TestCase] + public void TagWithPreReleaseLabelShouldBeTranslatedToPreReleaseWeight() + { + /*todo: Extend the configuration to specify the regex & pre-release weights + for the tags. + */ + + using var fixture = new EmptyRepositoryFixture(); + fixture.Repository.MakeACommit(); + fixture.BranchTo("develop"); + fixture.Repository.MakeATaggedCommit("v1.0.0-alpha"); + + var strategy = GetVersionStrategy(fixture.Repository, "develop"); + var baseVersion = strategy.GetVersions().Single(); + + baseVersion.SemanticVersion.ToString().ShouldBe("1.0.0-1000"); + } + + private static IVersionStrategy GetVersionStrategy( + IRepository repository, string branch, Config config = null) + { + var sp = BuildServiceProvider(repository, branch, config); + return sp.GetServiceForType(); + } + } +} \ No newline at end of file From f696177928ddda7352af8585b7242d05a7ddd69f Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Sat, 9 May 2020 16:39:17 +0200 Subject: [PATCH 2/5] Problem: Tagged commits end up having a zero WeightedPreReleaseNumber, especially in GitFlow branching scenarios. This could lead to an emission of AssemblyFileSemVer that is not strictly increasing. Solution: Introduce a new configuration parameter, tag-pre-release-weight, that could overrwrite the WeightedPreReleaseNumber if it turns out to be 0. --- docs/input/docs/configuration.md | 4 + ...riteOutEffectiveConfiguration.approved.txt | 1 + .../Helpers/TestEffectiveConfiguration.cs | 2 +- .../IntegrationTests/VersionInTagScenarios.cs | 107 ++++++++++++++++++ .../Model/CommitDateTests.cs | 2 +- ...sDeliveryModeForFeatureBranch.approved.txt | 2 +- ...hWithCustomAssemblyInfoFormat.approved.txt | 2 +- ...ntinuousDeliveryModeForStable.approved.txt | 2 +- ...ableWhenCurrentCommitIsTagged.approved.txt | 2 +- .../TaggedCommitVersionStrategyTests.cs | 43 ------- ...ileTests.UpdateWixVersionFile.approved.txt | 2 +- ...sionFileWhenFileAlreadyExists.approved.txt | 2 +- .../Configuration/ConfigExtensions.cs | 8 +- .../Model/Configuration/Config.cs | 3 + .../Configuration/EffectiveConfiguration.cs | 6 +- .../SemanticVersionFormatValues.cs | 14 ++- 16 files changed, 147 insertions(+), 55 deletions(-) create mode 100644 src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs delete mode 100644 src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs diff --git a/docs/input/docs/configuration.md b/docs/input/docs/configuration.md index d0f751d9e3..755a5462b4 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 0 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..ee4b84b3b9 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: 0 commit-message-incrementing: Enabled branches: develop: diff --git a/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs index 4c179f3db2..64b5974e5b 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, 0) { } } diff --git a/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs new file mode 100644 index 0000000000..993d2611fb --- /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_WeightedPreReleaseNumberShouldBeZero() + { + // 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.0"); + } + + [Test] + public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + TagPreReleaseWeight = 60000 + }; + 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_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheSameAsTheTagPreReleaseWeight() + { + // Arrange + var config = new Config() + { + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", + TagPreReleaseWeight = 60000, + 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"); + } + + [Test] + public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeZero() + { + // 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.0"); + } + } +} 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/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs b/src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs deleted file mode 100644 index 340685b44f..0000000000 --- a/src/GitVersionCore.Tests/VersionCalculation/Strategies/TaggedCommitVersionStrategyTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using GitTools.Testing; -using GitVersion.Configuration; -using GitVersion.Extensions; -using GitVersion.Model.Configuration; -using GitVersion.VersionCalculation; -using GitVersionCore.Tests.Helpers; -using LibGit2Sharp; -using NUnit.Framework; -using Shouldly; - -namespace GitVersionCore.Tests.VersionCalculation.Strategies -{ - [TestFixture] - public class TaggedCommitVersionStrategyTests : TestBase - { - [TestCase] - public void TagWithPreReleaseLabelShouldBeTranslatedToPreReleaseWeight() - { - /*todo: Extend the configuration to specify the regex & pre-release weights - for the tags. - */ - - using var fixture = new EmptyRepositoryFixture(); - fixture.Repository.MakeACommit(); - fixture.BranchTo("develop"); - fixture.Repository.MakeATaggedCommit("v1.0.0-alpha"); - - var strategy = GetVersionStrategy(fixture.Repository, "develop"); - var baseVersion = strategy.GetVersions().Single(); - - baseVersion.SemanticVersion.ToString().ShouldBe("1.0.0-1000"); - } - - private static IVersionStrategy GetVersionStrategy( - IRepository repository, string branch, Config config = null) - { - var sp = BuildServiceProvider(repository, branch, config); - return sp.GetServiceForType(); - } - } -} \ No newline at end of file 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..e25c472bcb 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 ??= 0; var configBranches = config.Branches.ToList(); @@ -182,6 +183,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 +267,10 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config var noBumpMessage = configuration.NoBumpMessage; var commitDateFormat = configuration.CommitDateFormat; var updateBuildNumber = configuration.UpdateBuildNumber ?? true; + var tagPreReleaseWeight = configuration.TagPreReleaseWeight; 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.HasValue ? tagPreReleaseWeight.Value : 0); } 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; + } } } From 80473c55291122d57d87d69d4b15367d73b55d6c Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Sat, 9 May 2020 16:50:02 +0200 Subject: [PATCH 3/5] Try to fix the Dotnet format problems --- src/GitVersionCore/Configuration/ConfigExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitVersionCore/Configuration/ConfigExtensions.cs b/src/GitVersionCore/Configuration/ConfigExtensions.cs index e25c472bcb..9ee650cb42 100644 --- a/src/GitVersionCore/Configuration/ConfigExtensions.cs +++ b/src/GitVersionCore/Configuration/ConfigExtensions.cs @@ -270,7 +270,6 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config var tagPreReleaseWeight = configuration.TagPreReleaseWeight; var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; - return new EffectiveConfiguration( assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, From d4ce8bbf35929796e48f4b6c17bf56f6483f69c0 Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Mon, 11 May 2020 15:33:05 +0200 Subject: [PATCH 4/5] Fix compilation error induced due to rebase --- src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/Helpers/TestEffectiveConfiguration.cs index 64b5974e5b..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, 0, 0) + tracksReleaseBranches, isRelease, commitDateFormat, updateBuildNumber, 0, 0) { } } From d713fd5b999f29195fad9d3b6145f7f64db0b543 Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Mon, 11 May 2020 21:52:18 +0200 Subject: [PATCH 5/5] Set a default value of 60000 for the TagPreReleaseWeight --- docs/input/docs/configuration.md | 2 +- ...anWriteOutEffectiveConfiguration.approved.txt | 2 +- .../IntegrationTests/VersionInTagScenarios.cs | 16 ++++++++-------- .../Configuration/ConfigExtensions.cs | 7 ++++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/input/docs/configuration.md b/docs/input/docs/configuration.md index 755a5462b4..134c92045e 100644 --- a/docs/input/docs/configuration.md +++ b/docs/input/docs/configuration.md @@ -201,7 +201,7 @@ set to `4`, which will pad the `CommitsSinceVersionSource` value of `1` to ### 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 0 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. +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 diff --git a/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index ee4b84b3b9..b7a78223f8 100644 --- a/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -10,7 +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: 0 +tag-pre-release-weight: 60000 commit-message-incrementing: Enabled branches: develop: diff --git a/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs index 993d2611fb..2d201b911d 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs @@ -11,7 +11,7 @@ namespace GitVersionCore.Tests.IntegrationTests class VersionInTagScenarios { [Test] - public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeZero() + public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreReleaseNumberShouldBeTheDefaultValue() { // Arrange var config = new Config() @@ -26,7 +26,7 @@ public void TagPreReleaseWeightIsNotConfigured_HeadIsATaggedCommit_WeightedPreRe var version = fixture.GetVersion(config); // Assert - version.AssemblySemFileVer.ShouldBe("1.1.0.0"); + version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); } [Test] @@ -36,7 +36,7 @@ public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreRelea var config = new Config() { AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - TagPreReleaseWeight = 60000 + TagPreReleaseWeight = 65535 }; config.ApplyDefaults(); @@ -46,7 +46,7 @@ public void TagPreReleaseWeightIsConfigured_HeadIsATaggedCommit_WeightedPreRelea var version = fixture.GetVersion(config); // Assert - version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); + version.AssemblySemFileVer.ShouldBe("1.1.0.65535"); } [Test] @@ -56,7 +56,7 @@ public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPre var config = new Config() { AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}", - TagPreReleaseWeight = 60000, + TagPreReleaseWeight = 65535, VersioningMode = VersioningMode.ContinuousDeployment }; config.ApplyDefaults(); @@ -74,11 +74,11 @@ public void TagPreReleaseWeightIsConfigured_GitFlowReleaseIsFinished_WeightedPre var version = fixture.GetVersion(config); // Assert - version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); + version.AssemblySemFileVer.ShouldBe("1.1.0.65535"); } [Test] - public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeZero() + public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_WeightedPreReleaseNumberShouldBeTheDefaultValue() { // Arrange var config = new Config() @@ -101,7 +101,7 @@ public void TagPreReleaseWeightIsNotConfigured_GitFlowReleaseIsFinished_Weighted var version = fixture.GetVersion(config); // Assert - version.AssemblySemFileVer.ShouldBe("1.1.0.0"); + version.AssemblySemFileVer.ShouldBe("1.1.0.60000"); } } } diff --git a/src/GitVersionCore/Configuration/ConfigExtensions.cs b/src/GitVersionCore/Configuration/ConfigExtensions.cs index 9ee650cb42..1b438952db 100644 --- a/src/GitVersionCore/Configuration/ConfigExtensions.cs +++ b/src/GitVersionCore/Configuration/ConfigExtensions.cs @@ -37,7 +37,7 @@ public static void Reset(this Config config) config.CommitsSinceVersionSourcePadding ??= 4; config.CommitDateFormat ??= "yyyy-MM-dd"; config.UpdateBuildNumber ??= true; - config.TagPreReleaseWeight ??= 0; + config.TagPreReleaseWeight ??= DefaultTagPreReleaseWeight; var configBranches = config.Branches.ToList(); @@ -129,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, @@ -267,7 +268,7 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config var noBumpMessage = configuration.NoBumpMessage; var commitDateFormat = configuration.CommitDateFormat; var updateBuildNumber = configuration.UpdateBuildNumber ?? true; - var tagPreReleaseWeight = configuration.TagPreReleaseWeight; + var tagPreReleaseWeight = configuration.TagPreReleaseWeight ?? DefaultTagPreReleaseWeight; var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; return new EffectiveConfiguration( @@ -288,7 +289,7 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config commitDateFormat, updateBuildNumber, preReleaseWeight, - tagPreReleaseWeight.HasValue ? tagPreReleaseWeight.Value : 0); + tagPreReleaseWeight); } public static string GetBranchSpecificTag(this EffectiveConfiguration configuration, ILog log, string branchFriendlyName, string branchNameOverride)