Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding support to specify pre-release-weight for branch specific conf…
…igs and leverage the same using a new GitVersion variable WeightedPreReleaseNumber
  • Loading branch information
ruhullahshah authored and Ruh Ullah Shah committed Feb 27, 2019
commit 5d2ca54e985cf6b8518e7345426fc2fcad6afddc
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ branches:
track-merge-target: false
tracks-release-branches: false
is-release-branch: true
pre-release-weight: 1000
feature:
regex: ^features?[/-]
mode: ContinuousDelivery
Expand Down Expand Up @@ -385,3 +386,6 @@ Indicates this branch config represents a release branch in GitFlow.

### is-mainline
When using Mainline mode, this indicates that this branch is a mainline. By default support/ and master are mainlines.

### pre-release-weight
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)
4 changes: 4 additions & 0 deletions docs/more-info/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For the `release/3.0.0` branch of GitVersion it shows:
"PreReleaseTagWithDash":"-beta.1",
"PreReleaseLabel":"beta",
"PreReleaseNumber":1,
"WeightedPreReleaseNumber":1001
"BuildMetaData":1,
"BuildMetaDataPadded": "0001",
"FullBuildMetaData":"1.Branch.release/3.0.0.Sha.28c853159a46b5a87e6cc9c4f6e940c59d6bc68a",
Expand Down Expand Up @@ -40,3 +41,6 @@ For the `release/3.0.0` branch of GitVersion it shows:

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.

#### What is WeightedPreReleaseNumber?

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.
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/CommitDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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<IVersionFilter>(), false, true, format)
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format, 0)
);

Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,31 @@ public void FeatureOnRelease_FeatureBranchNotDeleted()
fixture.AssertFullSemver(config, "4.5.0-beta.2");
}
}

[Test]
public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
{
var config = new Config
{
AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}",
Branches =
{
{ "release", new BranchConfig
{
PreReleaseWeight = 1000
}
}
}
};
using (var fixture = new EmptyRepositoryFixture())
{
fixture.Repository.MakeATaggedCommit("1.0.3");
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Checkout("release-2.0.0");
ConfigurationProvider.ApplyDefaultsTo(config);
var variables = fixture.GetVersion(config);
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
}
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, 0)
{
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/GitVersionCore.Tests/TestableVersionVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

class TestableVersionVariables : VersionVariables
{
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)
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 weightedPreReleaseNumber = "", 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, weightedPreReleaseNumber, preReleaseTagWithDash,
preReleaseLabel, preReleaseNumber, informationalVersion, commitDate, nugetVersion, nugetVersionV2,
nugetPreReleaseTag, nugetPreReleaseTagV2, commitsSinceVersionSource, commitsSinceVersionSourcePadded)
{
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionCore/Configuration/BranchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public BranchConfig(BranchConfig branchConfiguration)
Name = branchConfiguration.Name;
SourceBranches = branchConfiguration.SourceBranches;
IsSourceBranchFor = branchConfiguration.IsSourceBranchFor;
PreReleaseWeight = branchConfiguration.PreReleaseWeight;
}

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

[YamlMember(Alias = "pre-release-weight")]
public int? PreReleaseWeight { get; set; }

/// <summary>
/// The name given to this configuration in the config file.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static void ApplyBranchDefaults(Config config,
branchConfig.TracksReleaseBranches = branchConfig.TracksReleaseBranches ?? tracksReleaseBranches;
branchConfig.IsReleaseBranch = branchConfig.IsReleaseBranch ?? isReleaseBranch;
branchConfig.IsMainline = branchConfig.IsMainline ?? isMainline;
branchConfig.PreReleaseWeight = branchConfig.PreReleaseWeight ?? 0;
}

static Config ReadConfig(string workingDirectory, IFileSystem fileSystem)
Expand Down
6 changes: 5 additions & 1 deletion src/GitVersionCore/EffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public EffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters,
bool tracksReleaseBranches,
bool isCurrentBranchRelease,
string commitDateFormat)
string commitDateFormat,
int preReleaseWeight)
{
AssemblyVersioningScheme = assemblyVersioningScheme;
AssemblyFileVersioningScheme = assemblyFileVersioningScheme;
Expand Down Expand Up @@ -61,6 +62,7 @@ public EffectiveConfiguration(
TracksReleaseBranches = tracksReleaseBranches;
IsCurrentBranchRelease = isCurrentBranchRelease;
CommitDateFormat = commitDateFormat;
PreReleaseWeight = preReleaseWeight;
}

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

public string CommitDateFormat { get; private set; }

public int PreReleaseWeight { get; private set; }
}
}
4 changes: 3 additions & 1 deletion src/GitVersionCore/GitVersionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void CalculateEffectiveConfiguration()
var incrementStrategy = currentBranchConfig.Increment.Value;
var preventIncrementForMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion.Value;
var trackMergeTarget = currentBranchConfig.TrackMergeTarget.Value;
var preReleaseWeight = currentBranchConfig.PreReleaseWeight ?? 0;

var nextVersion = FullConfiguration.NextVersion;
var assemblyVersioningScheme = FullConfiguration.AssemblyVersioningScheme.Value;
Expand Down Expand Up @@ -148,7 +149,8 @@ void CalculateEffectiveConfiguration()
FullConfiguration.Ignore.ToFilters(),
currentBranchConfig.TracksReleaseBranches.Value,
currentBranchConfig.IsReleaseBranch.Value,
commitDateFormat);
commitDateFormat,
preReleaseWeight);
}

private static Branch GetTargetBranch(IRepository repository, string targetBranch)
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore/OutputVariables/VariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static VersionVariables GetVariablesFor(SemanticVersion semanticVersion,
semverFormatValues.PreReleaseTagWithDash,
semverFormatValues.PreReleaseLabel,
semverFormatValues.PreReleaseNumber,
semverFormatValues.WeightedPreReleaseNumber,
informationalVersion,
semverFormatValues.CommitDate,
semverFormatValues.NuGetVersion,
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersionCore/OutputVariables/VersionVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public VersionVariables(string major,
string preReleaseTagWithDash,
string preReleaseLabel,
string preReleaseNumber,
string weightedPreReleaseNumber,
string informationalVersion,
string commitDate,
string nugetVersion,
Expand Down Expand Up @@ -61,6 +62,7 @@ public VersionVariables(string major,
PreReleaseTagWithDash = preReleaseTagWithDash;
PreReleaseLabel = preReleaseLabel;
PreReleaseNumber = preReleaseNumber;
WeightedPreReleaseNumber = weightedPreReleaseNumber;
InformationalVersion = informationalVersion;
CommitDate = commitDate;
NuGetVersion = nugetVersion;
Expand All @@ -78,6 +80,7 @@ public VersionVariables(string major,
public string PreReleaseTagWithDash { get; private set; }
public string PreReleaseLabel { get; private set; }
public string PreReleaseNumber { get; private set; }
public string WeightedPreReleaseNumber { get; private set; }
public string BuildMetaData { get; private set; }
public string BuildMetaDataPadded { get; private set; }
public string FullBuildMetaData { get; private set; }
Expand Down
5 changes: 5 additions & 0 deletions src/GitVersionCore/SemanticVersionFormatValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public string PreReleaseNumber
get { return _semver.PreReleaseTag.HasTag() ? _semver.PreReleaseTag.Number.ToString() : null; }
}

public string WeightedPreReleaseNumber
{
get { return _semver.PreReleaseTag.HasTag() ? (_semver.PreReleaseTag.Number + _config.PreReleaseWeight).ToString() : null; }
}

public string BuildMetaData
{
get { return _semver.BuildMetaData; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionExe.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, 0)

{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TestEffectiveConfiguration(
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, 0)
{
}
}
Expand Down