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

Pull Request Version Calculation Not Based on source branch #2821

Closed
Tracked by #3445
anderson-dev opened this issue Aug 22, 2021 Discussed in #2818 · 8 comments
Closed
Tracked by #3445

Pull Request Version Calculation Not Based on source branch #2821

anderson-dev opened this issue Aug 22, 2021 Discussed in #2818 · 8 comments
Labels
Milestone

Comments

@anderson-dev
Copy link

Discussed in #2818

Originally posted by anderson-dev August 19, 2021
I'm using mainline versioning mode where my feature branches increment by minor. In my scenario below, pull request version reflects the current version of master rather than the feature branch that the pull request is based on:

master
0.1.0
master -> feature/foo
commit
0.2.0-foo.1
feature/foo -> pull/8/merge
0.1.1-PullRequest00008.1
pull/8/merge -> master
0.2.0 (as expected)

I've tried changing the increment mode for pullrequests in my gitversion.yml branch config but it just changes the increment based on master. How would I tell it to simply take its version from the calculated version of the feature branch for which the pull request was created?

Find an integration test below, XenoLibPackages#CanCalculatePullRequestChanges, that reproduces my issue. I tried 'track-merge-target: true' with no dice.

using GitTools.Testing;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;
using LibGit2Sharp;
using NUnit.Framework;
using System.Collections.Generic;

namespace GitVersion.Core.Tests.IntegrationTests
{
    public class XenoLibPackages : TestBase
    {
        private readonly Config config = new Config
        {
            VersioningMode = VersioningMode.Mainline,
            Branches = new Dictionary<string, BranchConfig>
            {
                {
                    "feature", new BranchConfig
                    {
                        Increment = IncrementStrategy.Minor
                    }
                },
                {
                    "pull-request", new BranchConfig
                    {
                        Regex = @"^(pull|pull\-requests|pr)[/-]",
                        Increment = IncrementStrategy.None,
                        TrackMergeTarget = true
                    }
                }
            }
        };

        [Test]
        public void IncrementFeatureByMinor()
        {
            using var fixture = new EmptyRepositoryFixture();
            fixture.MakeATaggedCommit("0.1.0");

            // feature workflow
            fixture.BranchTo("feature/foo", "foo");
            fixture.MakeACommit();
            fixture.AssertFullSemver("0.2.0-foo.1", config);
            fixture.MakeACommit();
            fixture.AssertFullSemver("0.2.0-foo.2", config);
            fixture.Checkout(MainBranch);
            fixture.MergeNoFF("feature/foo");
            fixture.AssertFullSemver("0.2.0", config);
        }

        [Test]
        public void CanCalculatePullRequestChanges()
        {
            using var fixture = new EmptyRepositoryFixture();
            fixture.Repository.MakeATaggedCommit("0.1.0");
            Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/foo"));
            fixture.Repository.MakeACommit();
            fixture.AssertFullSemver("0.2.0-foo.1", config);

            fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, normalise: true);

            fixture.Repository.DumpGraph();
            fixture.AssertFullSemver("0.2.0-PullRequest0002.2");
        }
    }
}
@asbjornu
Copy link
Member

Can you please submit a PR containing these tests?

@anderson-dev
Copy link
Author

anderson-dev commented Sep 13, 2021

Can you please submit a PR containing these tests?

I submitted the pr 14 days ago. It was looked at but because the CI system treated the unit test failure as successful when it shouldn't it appears to have been ignored. It's there, if you look at the CI build system logs, you can see the test failure.

Is there something I'm missing or that would help in answering my question in how to support my intended branch strategy?

@anderson-dev
Copy link
Author

Is there just no way to support the branch strategy I'm asking about? The PR was submitted 6 months ago with no suggestions. Does this need to be changed to a feature request rather than a simple question?

@asbjornu
Copy link
Member

asbjornu commented Mar 5, 2022

Sorry, but it has been an extremely hectic autumn and Christmas for me, but I've finally surfaced and have found some time to invest in GitVersion again. I've replied in #2830 (comment).

@anderson-dev
Copy link
Author

thanks I've replied there as well

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs.

@HHobeck
Copy link
Contributor

HHobeck commented Mar 22, 2023

public class XenoLibPackages : TestBase
{
    private readonly GitVersionConfiguration configuration = GitFlowConfigurationBuilder.New
        .WithVersioningMode(VersioningMode.Mainline)
        .WithBranch("feature", _ => _
            .WithIncrement(IncrementStrategy.Minor)
            .WithVersioningMode(VersioningMode.ContinuousDeployment)
        ).WithBranch("pull-request", _ => _
            .WithIncrement(IncrementStrategy.Inherit)
        ).Build();

    [Test]
    public void IncrementFeatureByMinor()
    {
        using var fixture = new EmptyRepositoryFixture();
        fixture.MakeATaggedCommit("0.1.0");

        fixture.BranchTo("feature/foo", "foo");
        fixture.MakeACommit();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("0.2.0-foo.1", configuration);
        fixture.MakeACommit();

        // ✅ succeeds as expected
        fixture.AssertFullSemver("0.2.0-foo.2", configuration);
        fixture.Checkout("main");
        fixture.MergeNoFF("feature/foo");

        // ✅ succeeds as expected
        fixture.AssertFullSemver("0.2.0", configuration);
    }

    [Test]
    public void CanCalculatePullRequestChanges()
    {
        using var fixture = new EmptyRepositoryFixture();
        fixture.MakeATaggedCommit("0.1.0");
        fixture.BranchTo("feature/foo");
        fixture.MakeACommit();

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

        fixture.Repository.CreatePullRequestRef("feature/foo", "main", normalise: true);

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

@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

4 participants