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 5c9fc28
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
39 changes: 39 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,43 @@ 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();

// ✅ 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();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.5", configuration);
}
}
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
25 changes: 11 additions & 14 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 Down

0 comments on commit 5c9fc28

Please sign in to comment.