Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] GitVersion behaves different if it is used the first time where the fallback version strategy applies #3436

Closed
HHobeck opened this issue Mar 12, 2023 · 1 comment
Labels
Milestone

Comments

@HHobeck
Copy link
Contributor

HHobeck commented Mar 12, 2023

Describe the bug
I came over this issue in the discussion of #3428: Use gitversion when promoting builds across environments. The scenario is quite simple that the user wants to tag a commit in one branch (or even with merging) with not only the same label name. If the branch is not labeled and the name is set to null then I would expect that all pre-release tags are considered. The other problem here is that the system behaves different if it is used the first time where the fallback version strategy applies.

Expected Behavior

[TestCase(1)]
[TestCase(2)]
public void ExpectedBehavior(long patchNumber)
{
    var configuration = GitHubFlowConfigurationBuilder.New
        .WithLabel(null)
        .WithBranch("main", branchBuilder => branchBuilder
            .WithLabel(null).WithIncrement(IncrementStrategy.Patch)
        ).Build();

    using var fixture = new EmptyRepositoryFixture("main");

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("0.0.1+1", configuration);

    fixture.ApplyTag($"0.0.{patchNumber}-alpha.1");

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-alpha.1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-alpha.2+1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-alpha.2+2", configuration);

    fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.1");

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-beta.1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-beta.2+1", configuration);

    fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.2");

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-beta.2", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}-beta.3+1", configuration);

    fixture.ApplyTag($"0.0.{patchNumber}");

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber + 1}+1", configuration);
}

Actual Behavior

[TestCase(1)]
[TestCase(2)]
public void ActualBehavior(long patchNumber)
{
    var configuration = GitHubFlowConfigurationBuilder.New
        .WithLabel(null)
        .WithBranch("main", branchBuilder => branchBuilder
            .WithLabel(null).WithIncrement(IncrementStrategy.Patch)
        ).Build();

    using var fixture = new EmptyRepositoryFixture("main");

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("0.0.1+1", configuration);

    fixture.ApplyTag($"0.0.{patchNumber}-alpha.1");

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-alpha.1
        fixture.AssertFullSemver($"0.0.{patchNumber}+1", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-alpha.1
        fixture.AssertFullSemver($"0.0.{patchNumber}", configuration);

    fixture.MakeACommit();

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-alpha.2+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+2", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-alpha.2+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+1", configuration);

    fixture.MakeACommit();

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-alpha.2+2
        fixture.AssertFullSemver($"0.0.{patchNumber}+3", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-alpha.2+2
        fixture.AssertFullSemver($"0.0.{patchNumber}+2", configuration);

    fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.1");

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-beta.1
        fixture.AssertFullSemver($"0.0.{patchNumber}+4", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-beta.1
        fixture.AssertFullSemver($"0.0.{patchNumber}", configuration);

    fixture.MakeACommit();

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-beta.2+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+5", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-beta.2+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+1", configuration);

    fixture.MakeATaggedCommit($"0.0.{patchNumber}-beta.2");

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-beta.2
        fixture.AssertFullSemver($"0.0.{patchNumber}+6", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-beta.2
        fixture.AssertFullSemver($"0.0.{patchNumber}", configuration);

    fixture.MakeACommit();

    if (patchNumber == 1)
        // ❌ expected: 0.0.{patchNumber}-beta.3+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+7", configuration);
    else
        // ❌ expected: 0.0.{patchNumber}-beta.3+1
        fixture.AssertFullSemver($"0.0.{patchNumber}+1", configuration);

    fixture.ApplyTag($"0.0.{patchNumber}");

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber}", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver($"0.0.{patchNumber + 1}+1", configuration);
}

Possible Fix

  1. The business logic how the pre-release label are created needs to be changed in NextVersionCalculator::FindVersion
  2. Removing the FallbackVersionStrategy and move the logic to NextVersionCalculator::GetNextVersions

Steps to Reproduce

Please see the integration tests above.

Context

Your Environment

I have used the 6.0.0-beta.1 version

@arturcic
Copy link
Member

arturcic commented Apr 6, 2023

🎉 This issue has been resolved in version 6.0.0-beta.2 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants