Skip to content

Commit 5d2ca54

Browse files
ruhullahshahRuh Ullah Shah
authored andcommitted
Adding support to specify pre-release-weight for branch specific configs and leverage the same using a new GitVersion variable WeightedPreReleaseNumber
1 parent 482dfce commit 5d2ca54

File tree

15 files changed

+77
-7
lines changed

15 files changed

+77
-7
lines changed

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ branches:
206206
track-merge-target: false
207207
tracks-release-branches: false
208208
is-release-branch: true
209+
pre-release-weight: 1000
209210
feature:
210211
regex: ^features?[/-]
211212
mode: ContinuousDelivery
@@ -385,3 +386,6 @@ Indicates this branch config represents a release branch in GitFlow.
385386

386387
### is-mainline
387388
When using Mainline mode, this indicates that this branch is a mainline. By default support/ and master are mainlines.
389+
390+
### pre-release-weight
391+
Provides a way to translate the `PreReleaseLabel` ([variables](/more-info/variables)) to a numeric value in order to avoid version collisions across different branches. For example, a release branch created after "1.2.3-alpha.55" results in "1.2.3-beta.1" and thus e.g. "1.2.3-alpha.4" and "1.2.3-beta.4" would have the same file version: "1.2.3.4". Related Issues [1145](https://github.com/GitTools/GitVersion/issues/1145), [1366](https://github.com/GitTools/GitVersion/issues/1366)

docs/more-info/variables.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For the `release/3.0.0` branch of GitVersion it shows:
1111
"PreReleaseTagWithDash":"-beta.1",
1212
"PreReleaseLabel":"beta",
1313
"PreReleaseNumber":1,
14+
"WeightedPreReleaseNumber":1001
1415
"BuildMetaData":1,
1516
"BuildMetaDataPadded": "0001",
1617
"FullBuildMetaData":"1.Branch.release/3.0.0.Sha.28c853159a46b5a87e6cc9c4f6e940c59d6bc68a",
@@ -40,3 +41,6 @@ For the `release/3.0.0` branch of GitVersion it shows:
4041

4142
This is a common approach that gives you the ability to roll out hot fixes to your assembly without breaking existing applications that may be referencing it. You are still able to get the full version number if you need to by looking at its file version number.
4243

44+
#### What is WeightedPreReleaseNumber?
45+
46+
It is a summation of branch specific `pre-release-weight` and the `PreReleaseNumber`. It can be used to obtain a monotonically increasing version number across the branches.

src/GitVersionCore.Tests/CommitDateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CommitDateFormatTest(string format, string expectedOutcome)
2626
},
2727
new EffectiveConfiguration(
2828
AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme.MajorMinorPatch, "", "", "", VersioningMode.ContinuousDelivery, "", "", "", IncrementStrategy.Inherit,
29-
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format)
29+
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format, 0)
3030
);
3131

3232
Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome));

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,4 +623,31 @@ public void FeatureOnRelease_FeatureBranchNotDeleted()
623623
fixture.AssertFullSemver(config, "4.5.0-beta.2");
624624
}
625625
}
626+
627+
[Test]
628+
public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
629+
{
630+
var config = new Config
631+
{
632+
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
633+
Branches =
634+
{
635+
{ "release", new BranchConfig
636+
{
637+
PreReleaseWeight = 1000
638+
}
639+
}
640+
}
641+
};
642+
using (var fixture = new EmptyRepositoryFixture())
643+
{
644+
fixture.Repository.MakeATaggedCommit("1.0.3");
645+
fixture.Repository.MakeCommits(5);
646+
fixture.Repository.CreateBranch("release-2.0.0");
647+
fixture.Checkout("release-2.0.0");
648+
ConfigurationProvider.ApplyDefaultsTo(config);
649+
var variables = fixture.GetVersion(config);
650+
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
651+
}
652+
}
626653
}

src/GitVersionCore.Tests/TestEffectiveConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
4040
majorMessage, minorMessage, patchMessage, noBumpMessage,
4141
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
4242
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
43-
tracksReleaseBranches, isRelease, commitDateFormat)
43+
tracksReleaseBranches, isRelease, commitDateFormat, 0)
4444
{
4545
}
4646
}

src/GitVersionCore.Tests/TestableVersionVariables.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44

55
class TestableVersionVariables : VersionVariables
66
{
7-
public TestableVersionVariables(string major = "", string minor = "", string patch = "", string buildMetaData = "", string buildMetaDataPadded = "", string fullBuildMetaData = "", string branchName = "", string sha = "", string shortSha = "", string majorMinorPatch = "", string semVer = "", string legacySemVer = "", string legacySemVerPadded = "", string fullSemVer = "", string assemblySemVer = "", string assemblySemFileVer = "", string preReleaseTag = "", string preReleaseTagWithDash = "", string preReleaseLabel = "", string preReleaseNumber = "", string informationalVersion = "", string commitDate = "", string nugetVersion = "", string nugetVersionV2 = "", string nugetPreReleaseTag = "", string nugetPreReleaseTagV2 = "", string commitsSinceVersionSource = "", string commitsSinceVersionSourcePadded = "") : base(major, minor, patch, buildMetaData, buildMetaDataPadded, fullBuildMetaData, branchName, sha, shortSha, majorMinorPatch, semVer, legacySemVer, legacySemVerPadded, fullSemVer, assemblySemVer, assemblySemFileVer, preReleaseTag, preReleaseTagWithDash, preReleaseLabel, preReleaseNumber, informationalVersion, commitDate, nugetVersion, nugetVersionV2, nugetPreReleaseTag, nugetPreReleaseTagV2, commitsSinceVersionSource, commitsSinceVersionSourcePadded)
7+
public TestableVersionVariables(
8+
string major = "", string minor = "", string patch = "", string buildMetaData = "",
9+
string buildMetaDataPadded = "", string fullBuildMetaData = "", string branchName = "",
10+
string sha = "", string shortSha = "", string majorMinorPatch = "", string semVer = "",
11+
string legacySemVer = "", string legacySemVerPadded = "", string fullSemVer = "",
12+
string assemblySemVer = "", string assemblySemFileVer = "", string preReleaseTag = "",
13+
string preReleaseTagWithDash = "", string preReleaseLabel = "", string preReleaseNumber = "",
14+
string weightedPreReleaseNumber = "", string informationalVersion = "", string commitDate = "",
15+
string nugetVersion = "", string nugetVersionV2 = "", string nugetPreReleaseTag = "",
16+
string nugetPreReleaseTagV2 = "", string commitsSinceVersionSource = "",
17+
string commitsSinceVersionSourcePadded = "") : base(
18+
major, minor, patch, buildMetaData, buildMetaDataPadded, fullBuildMetaData, branchName,
19+
sha, shortSha, majorMinorPatch, semVer, legacySemVer, legacySemVerPadded, fullSemVer,
20+
assemblySemVer, assemblySemFileVer, preReleaseTag, weightedPreReleaseNumber, preReleaseTagWithDash,
21+
preReleaseLabel, preReleaseNumber, informationalVersion, commitDate, nugetVersion, nugetVersionV2,
22+
nugetPreReleaseTag, nugetPreReleaseTagV2, commitsSinceVersionSource, commitsSinceVersionSourcePadded)
823
{
924
}
1025
}

src/GitVersionCore/Configuration/BranchConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public BranchConfig(BranchConfig branchConfiguration)
2828
Name = branchConfiguration.Name;
2929
SourceBranches = branchConfiguration.SourceBranches;
3030
IsSourceBranchFor = branchConfiguration.IsSourceBranchFor;
31+
PreReleaseWeight = branchConfiguration.PreReleaseWeight;
3132
}
3233

3334
[YamlMember(Alias = "mode")]
@@ -72,6 +73,9 @@ public BranchConfig(BranchConfig branchConfiguration)
7273
[YamlMember(Alias = "is-mainline")]
7374
public bool? IsMainline { get; set; }
7475

76+
[YamlMember(Alias = "pre-release-weight")]
77+
public int? PreReleaseWeight { get; set; }
78+
7579
/// <summary>
7680
/// The name given to this configuration in the config file.
7781
/// </summary>

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public static void ApplyBranchDefaults(Config config,
231231
branchConfig.TracksReleaseBranches = branchConfig.TracksReleaseBranches ?? tracksReleaseBranches;
232232
branchConfig.IsReleaseBranch = branchConfig.IsReleaseBranch ?? isReleaseBranch;
233233
branchConfig.IsMainline = branchConfig.IsMainline ?? isMainline;
234+
branchConfig.PreReleaseWeight = branchConfig.PreReleaseWeight ?? 0;
234235
}
235236

236237
static Config ReadConfig(string workingDirectory, IFileSystem fileSystem)

src/GitVersionCore/EffectiveConfiguration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public EffectiveConfiguration(
3232
IEnumerable<IVersionFilter> versionFilters,
3333
bool tracksReleaseBranches,
3434
bool isCurrentBranchRelease,
35-
string commitDateFormat)
35+
string commitDateFormat,
36+
int preReleaseWeight)
3637
{
3738
AssemblyVersioningScheme = assemblyVersioningScheme;
3839
AssemblyFileVersioningScheme = assemblyFileVersioningScheme;
@@ -61,6 +62,7 @@ public EffectiveConfiguration(
6162
TracksReleaseBranches = tracksReleaseBranches;
6263
IsCurrentBranchRelease = isCurrentBranchRelease;
6364
CommitDateFormat = commitDateFormat;
65+
PreReleaseWeight = preReleaseWeight;
6466
}
6567

6668
public bool TracksReleaseBranches { get; private set; }
@@ -115,5 +117,7 @@ public EffectiveConfiguration(
115117
public IEnumerable<IVersionFilter> VersionFilters { get; private set; }
116118

117119
public string CommitDateFormat { get; private set; }
120+
121+
public int PreReleaseWeight { get; private set; }
118122
}
119123
}

src/GitVersionCore/GitVersionContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void CalculateEffectiveConfiguration()
117117
var incrementStrategy = currentBranchConfig.Increment.Value;
118118
var preventIncrementForMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion.Value;
119119
var trackMergeTarget = currentBranchConfig.TrackMergeTarget.Value;
120+
var preReleaseWeight = currentBranchConfig.PreReleaseWeight ?? 0;
120121

121122
var nextVersion = FullConfiguration.NextVersion;
122123
var assemblyVersioningScheme = FullConfiguration.AssemblyVersioningScheme.Value;
@@ -148,7 +149,8 @@ void CalculateEffectiveConfiguration()
148149
FullConfiguration.Ignore.ToFilters(),
149150
currentBranchConfig.TracksReleaseBranches.Value,
150151
currentBranchConfig.IsReleaseBranch.Value,
151-
commitDateFormat);
152+
commitDateFormat,
153+
preReleaseWeight);
152154
}
153155

154156
private static Branch GetTargetBranch(IRepository repository, string targetBranch)

src/GitVersionCore/OutputVariables/VariableProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static VersionVariables GetVariablesFor(SemanticVersion semanticVersion,
7272
semverFormatValues.PreReleaseTagWithDash,
7373
semverFormatValues.PreReleaseLabel,
7474
semverFormatValues.PreReleaseNumber,
75+
semverFormatValues.WeightedPreReleaseNumber,
7576
informationalVersion,
7677
semverFormatValues.CommitDate,
7778
semverFormatValues.NuGetVersion,

src/GitVersionCore/OutputVariables/VersionVariables.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public VersionVariables(string major,
3232
string preReleaseTagWithDash,
3333
string preReleaseLabel,
3434
string preReleaseNumber,
35+
string weightedPreReleaseNumber,
3536
string informationalVersion,
3637
string commitDate,
3738
string nugetVersion,
@@ -61,6 +62,7 @@ public VersionVariables(string major,
6162
PreReleaseTagWithDash = preReleaseTagWithDash;
6263
PreReleaseLabel = preReleaseLabel;
6364
PreReleaseNumber = preReleaseNumber;
65+
WeightedPreReleaseNumber = weightedPreReleaseNumber;
6466
InformationalVersion = informationalVersion;
6567
CommitDate = commitDate;
6668
NuGetVersion = nugetVersion;
@@ -78,6 +80,7 @@ public VersionVariables(string major,
7880
public string PreReleaseTagWithDash { get; private set; }
7981
public string PreReleaseLabel { get; private set; }
8082
public string PreReleaseNumber { get; private set; }
83+
public string WeightedPreReleaseNumber { get; private set; }
8184
public string BuildMetaData { get; private set; }
8285
public string BuildMetaDataPadded { get; private set; }
8386
public string FullBuildMetaData { get; private set; }

src/GitVersionCore/SemanticVersionFormatValues.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public string PreReleaseNumber
4848
get { return _semver.PreReleaseTag.HasTag() ? _semver.PreReleaseTag.Number.ToString() : null; }
4949
}
5050

51+
public string WeightedPreReleaseNumber
52+
{
53+
get { return _semver.PreReleaseTag.HasTag() ? (_semver.PreReleaseTag.Number + _config.PreReleaseWeight).ToString() : null; }
54+
}
55+
5156
public string BuildMetaData
5257
{
5358
get { return _semver.BuildMetaData; }

src/GitVersionExe.Tests/TestEffectiveConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
4040
majorMessage, minorMessage, patchMessage, noBumpMessage,
4141
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
4242
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
43-
tracksReleaseBranches, isRelease, commitDateFormat)
43+
tracksReleaseBranches, isRelease, commitDateFormat, 0)
4444

4545
{
4646
}

src/GitVersionTask.Tests/Helpers/TestEffectiveConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
4040
majorMessage, minorMessage, patchMessage, noBumpMessage,
4141
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
4242
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
43-
tracksReleaseBranches, isRelease, commitDateFormat)
43+
tracksReleaseBranches, isRelease, commitDateFormat, 0)
4444
{
4545
}
4646
}

0 commit comments

Comments
 (0)