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] CommitsSinceVersionSource is counting from latest minor tag or first tag instead of latest tag #3656

Closed
wiruzman opened this issue Aug 17, 2023 · 2 comments · Fixed by #3883
Labels
Milestone

Comments

@wiruzman
Copy link

Describe the bug
I am using commit message increase with Mainline mode. The commit message contains +semver:minor. The minor version increases in the pull request but CommitsSinceVersionSource does not count from latest tag.

Expected Behavior

CommitsSinceVersionSource counts from latest tag.

Actual Behavior

CommitsSinceVersionSource counts from latest minor tag or first ever tag.

Possible Fix

Steps to Reproduce

[Test]
public void Under1PlusMinor()
{
    var configuration = GetMainlineModeConfiguration();
    using var fixture = new EmptyRepositoryFixture();
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeATaggedCommit("0.1.0");
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeATaggedCommit("0.1.1");
    Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
    fixture.Repository.MakeACommit("two +semver:minor");
    fixture.Repository.MakeACommit("three");

    fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);

    fixture.Repository.DumpGraph();
    fixture.AssertFullSemver("0.2.0-PullRequest2.3", configuration);
}

private static IGitVersionConfiguration GetMainlineModeConfiguration() => GitHubFlowConfigurationBuilder.New
            .WithBranch(MainBranch, builder => builder.WithVersioningMode(VersioningMode.Mainline))
            .Build();

Context

It does not block me because after the pull request is merged and all patch versions have correct CommitsSinceVersionSource until next minor/major.
Below test shows that after minor version is merged and following patch version have the correct CommitsSinceVersionSource.

[Test]
public void Under1PlusMinorThenPatch()
{
    var configuration = GetMainlineModeConfiguration();
    using var fixture = new EmptyRepositoryFixture();
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeATaggedCommit("0.1.0");
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeACommit();
    fixture.Repository.MakeATaggedCommit("0.1.1");
    var feature12345 = fixture.Repository.CreateBranch("feature/12345-test");
    Commands.Checkout(fixture.Repository, feature12345);
    fixture.Repository.MakeACommit("two +semver:minor");
    fixture.Repository.MakeACommit("three");

    var pullRequestRef1 = fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
    Commands.Checkout(fixture.Repository, MainBranch);
    var merge = fixture.Repository.Merge(pullRequestRef1, Generate.SignatureNow(), new MergeOptions(){CommitOnSuccess = true});
    fixture.Repository.Tags.Add("0.2.0", merge.Commit);
    
    var feature54321 = fixture.Repository.CreateBranch("feature/54321-test");
    Commands.Checkout(fixture.Repository, feature54321);
    fixture.Repository.MakeACommit("four");
    
    fixture.Repository.CreatePullRequestRef("feature/54321-test", MainBranch, normalise: true, prNumber: 3);

    fixture.Repository.DumpGraph();
    fixture.AssertFullSemver("0.2.1-PullRequest3.2", configuration);
}

private static IGitVersionConfiguration GetMainlineModeConfiguration() => GitHubFlowConfigurationBuilder.New
            .WithBranch(MainBranch, builder => builder.WithVersioningMode(VersioningMode.Mainline))
            .Build();

Your Environment

Azure DevOps but also locally.

  • Version Used: 6.0.0-beta.3
  • Operating System and version (Windows 10, Ubuntu 18.04): Windows 11, Ubuntu 22.04
  • Link to your project:
  • Link to your CI build (if appropriate):
@wiruzman wiruzman added the bug label Aug 17, 2023
@wiruzman
Copy link
Author

wiruzman commented Aug 17, 2023

Flipped < to > here to pick the latest tag if matchingVersionsOnceIncremented would have more than one versions and it worked except one test fails.
But all my own tests passed(do not consider the names yet):

public class MainlineDevelopmentMode3656 : TestBase
{
    [Test]
    public void Under1()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("0.1.2-PullRequest2.3", configuration);
    }

    [Test]
    public void Under1PlusMajor()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:major");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ❌ expected: 1.0.0-PullRequest2.3
        fixture.AssertFullSemver("1.0.0-PullRequest2.6", configuration);
    }

    [Test]
    public void Under1PlusMinor()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:minor");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ❌ expected: 0.2.0-PullRequest2.3
        fixture.AssertFullSemver("0.2.0-PullRequest2.6", configuration);
    }

    [Test]
    public void Under1PlusPatch()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("0.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:patch");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("0.1.2-PullRequest2.3", configuration);
    }
    [Test]
    public void Over1()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("1.1.2-PullRequest2.3", configuration);
    }

    [Test]
    public void Over1PlusMajor()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:major");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ❌ expected: 2.0.0-PullRequest2.3
        fixture.AssertFullSemver("2.0.0-PullRequest2.6", configuration);
    }

    [Test]
    public void Over1PlusMinor()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:minor");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ❌ expected: 1.2.0-PullRequest2.3
        fixture.AssertFullSemver("1.2.0-PullRequest2.6", configuration);
    }

    [Test]
    public void Over1PlusPatch()
    {
        var configuration = GetMainlineModeConfiguration();
        using var fixture = new EmptyRepositoryFixture();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.0");
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeACommit();
        fixture.Repository.MakeATaggedCommit("1.1.1");
        Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/12345-test"));
        fixture.Repository.MakeACommit("two +semver:patch");
        fixture.Repository.MakeACommit("three");

        fixture.Repository.CreatePullRequestRef("feature/12345-test", MainBranch, normalise: true);
        fixture.Repository.DumpGraph();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("1.1.2-PullRequest2.3", configuration);
    }

    private static IGitVersionConfiguration GetMainlineModeConfiguration() => GitHubFlowConfigurationBuilder.New
        .WithBranch(MainBranch, builder => builder.WithVersioningMode(VersioningMode.Mainline))
        .Build();
}

@HHobeck HHobeck added this to the 6.x milestone Aug 21, 2023
@arturcic arturcic added stale and removed stale labels Oct 30, 2023
@HHobeck HHobeck linked a pull request Jan 28, 2024 that will close this issue
5 tasks
@HHobeck HHobeck closed this as completed Jan 28, 2024
@arturcic arturcic modified the milestones: 6.x, 6.0.0-beta.6 Mar 9, 2024
@arturcic
Copy link
Member

arturcic commented Mar 9, 2024

🎉 This issue has been resolved in version 6.0.0-beta.6 🎉
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

Successfully merging a pull request may close this issue.

3 participants