Skip to content

Commit

Permalink
Fix wrong version generation for ContinuesDeployment actual: 5.0.0-be…
Browse files Browse the repository at this point in the history
…ta.1+3 expected 5.0.0-beta.3
  • Loading branch information
HHobeck committed Mar 21, 2023
1 parent d49e570 commit ba14aa7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void GitFlowSupportHotfixRelease()
fixture.SequenceDiagram.NoteOver("Hotfix branches are deleted once merged", "hotfix/1.3.1");
fixture.AssertFullSemver("1.3.1+4");
fixture.ApplyTag("1.3.1");

fixture.AssertFullSemver("1.3.1");
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
}
Expand Down
40 changes: 40 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,44 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd
// ✅ succeeds as expected
fixture.AssertFullSemver("2.0.0-pre.1", configuration);
}

[Test]
public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTagMain()
{
var configuration = GitFlowConfigurationBuilder.New
.WithNextVersion("5.0")
.WithSemanticVersionFormat(SemanticVersionFormat.Loose)
.WithBranch("main", _ => _
.WithLabel("beta")
.WithIncrement(IncrementStrategy.Patch)
.WithVersioningMode(VersioningMode.ContinuousDeployment)
).Build();

using EmptyRepositoryFixture fixture = new("main");
fixture.MakeACommit();
fixture.MakeACommit();
fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.1", configuration);

fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.2", configuration);

fixture.ApplyTag("5.0.0-beta.3");

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.3", configuration);

fixture.MakeATaggedCommit("5.0.0-rc.1");

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.4", configuration);

fixture.MakeACommit();

fixture.AssertFullSemver("5.0.0-beta.5", configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"PreReleaseLabelWithDash": "",
"PreReleaseNumber": null,
"WeightedPreReleaseNumber": 0,
"BuildMetaData": 5,
"FullBuildMetaData": "5.Sha.commitSha",
"BuildMetaData": null,
"FullBuildMetaData": "Sha.commitSha",
"MajorMinorPatch": "1.2.3",
"SemVer": "1.2.3",
"AssemblySemVer": "1.2.3.0",
"AssemblySemFileVer": "1.2.3.0",
"FullSemVer": "1.2.3+5",
"InformationalVersion": "1.2.3+5.Sha.commitSha",
"FullSemVer": "1.2.3",
"InformationalVersion": "1.2.3+Sha.commitSha",
"BranchName": "",
"EscapedBranchName": "",
"Sha": "commitSha",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi

var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

var vars = this.variableProvider.GetVariablesFor(semVer, configuration, SemanticVersion.Empty);
var variables = this.variableProvider.GetVariablesFor(semVer, configuration, SemanticVersion.Empty);

vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
variables.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ private NextVersion Calculate(IBranch branch, IGitVersionConfiguration configura
using (log.IndentLog("Calculating the base versions"))
{
var nextVersions = GetNextVersions(branch, configuration).ToArray();
var maxVersion = nextVersions.Max();

maxVersion.NotNull();
var maxVersion = nextVersions.Max()!;

var matchingVersionsOnceIncremented = nextVersions
.Where(v => v.BaseVersion.BaseVersionSource != null && v.IncrementedVersion == maxVersion.IncrementedVersion)
Expand Down
28 changes: 13 additions & 15 deletions src/GitVersion.Core/VersionCalculation/VariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ public class VariableProvider : IVariableProvider
public VersionVariables GetVariablesFor(
SemanticVersion semanticVersion, EffectiveConfiguration configuration, SemanticVersion? currentCommitTaggedVersion)
{
semanticVersion.NotNull();
configuration.NotNull();

var preReleaseTagName = semanticVersion.PreReleaseTag.Name;
var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment;

var label = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null);
var isCommitTagged = currentCommitTaggedVersion is not null && currentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label);

var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment
&& currentCommitTaggedVersion is null;
if (isContinuousDeploymentMode)
// Continuous Deployment always requires a pre-release tag unless the commit is tagged
if (isContinuousDeploymentMode && !isCommitTagged && !semanticVersion.PreReleaseTag.HasTag() && preReleaseTagName.IsNullOrEmpty())
{
semanticVersion = new SemanticVersion(semanticVersion);
// Continuous Deployment always requires a pre-release tag unless the commit is tagged
if (!semanticVersion.PreReleaseTag.HasTag())
{
preReleaseTagName = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null);
if (preReleaseTagName.IsNullOrEmpty())
{
preReleaseTagName = configuration.Label ?? string.Empty;
}
}
preReleaseTagName = label ?? string.Empty;
}

// Evaluate tag number pattern and append to prerelease tag, preserving build metadata
Expand All @@ -45,7 +42,7 @@ public VersionVariables GetVariablesFor(
}
}

if (isContinuousDeploymentMode || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline)
if ((!isCommitTagged && isContinuousDeploymentMode) || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline)
{
semanticVersion = PromoteNumberOfCommitsToTagNumber(semanticVersion, preReleaseTagName);
}
Expand All @@ -60,7 +57,8 @@ public VersionVariables GetVariablesFor(
};
}

if (semanticVersion.CompareTo(currentCommitTaggedVersion) == 0)
if (semanticVersion.BuildMetaData.CommitsSinceTag.HasValue
&& (isContinuousDeploymentMode || semanticVersion.CompareTo(currentCommitTaggedVersion) == 0))
{
// Will always be 0, don't bother with the +0 on tags
semanticVersion = new(semanticVersion)
Expand Down

0 comments on commit ba14aa7

Please sign in to comment.