GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

GitVersion not incrementing as expected on mainline mode

Open jeff-simeon opened this issue 4 years ago • 5 comments

Describe the bug We are not getting build versions as desired when using mainline mode.

Our GitVersion.yml is simply

mode: Mainline

Expected Behavior

Some background: We have a master branch and a preview branch to represent release rings. We do features and fixes in features/* and fix/* branches and then merge to preview...and then finally to master.

We have CI that builds and publishes a nuget package and we use the syntax *-preview* to lock in consumers to our preview ring.

Example:

  • master is currently at 0.1.2
  • preview (currently identical to master) is at 0.1.2-preview0088
  • We create a new feature off of preview in a branch feature/something and it gets the version 0.1.3-feature-something0001
  • We merge feature/something into preview and preview gets the version 0.1.3-preview0001
  • We merge preview into master and master gets the version 0.1.3
  • Repeat the process

Actual Behavior

This seems to work sometimes, but not others, and when it doesn't work, it is very difficult to get things re-aligned.

  • preview (currently identical to master) is at 0.1.2-preview0088
  • We create a new feature off of preview in a branch feature/somethingnew and it gets the version 0.1.2-feature-somethingnew0001

jeff-simeon avatar Oct 24 '21 01:10 jeff-simeon

It doesn't sound like you're actually using Mainline mode at all. Try changing to mode: ContinuousDeployment and see whether that behaves more like you expect. Also, in some situations, GitVersion doesn't like version numbers below 1.0.0 for some reason. Tagging version 1.0.0 will often make it behave more predictably.

asbjornu avatar Oct 26 '21 21:10 asbjornu

I will try that - thanks!

I thought Mainline mode was when you wanted master to build your current stable release version. Can you help me understand the difference, please?

jeff-simeon avatar Oct 26 '21 22:10 jeff-simeon

Ok but it says “Mainline Development is enabled when using GitHubFlow or any other strategy where you develop on main. The main rule of mainline development is that main is always in a state that it could be deployed to production. This means that pull requests should not be merged until they are ready to go out.”

so what about our process suggests mainline is wrong?

jeff-simeon avatar Oct 26 '21 22:10 jeff-simeon

TL;DR: You are using too many branches. :) You can read about GitHub Flow here. It's very basic; you only have main, all branches are in the nature of feature/* branches in GitFlow and they are usually squash-merged into main without a merge-commit; i.e. added to main as a single commit per feature. There is no distinction between hotfix, release, develop, support and everything else you may be used to from GitFlow.

asbjornu avatar Mar 02 '22 23:03 asbjornu

Please tak a look to the following integration test which I have been executed on current main branch:

[Test]
public void JustATestFor2888()
{
    var configuration = GitFlowConfigurationBuilder.New
        .WithVersioningMode(VersioningMode.Mainline)
        .WithBranch("develop", _ => _
            .WithRegularExpression("^preview$")
            .WithVersioningMode(VersioningMode.ContinuousDeployment)
            .WithIncrement(IncrementStrategy.Patch)
            .WithLabel("preview")
        )
        .WithBranch("feature", _ => _
            .WithVersioningMode(VersioningMode.ContinuousDeployment)
            .WithIncrement(IncrementStrategy.Patch)
            .WithLabel("{BranchName}")
        )
        .Build();

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

    fixture.MakeATaggedCommit("0.1.2");

    fixture.BranchTo("preview");
    fixture.BranchTo("feature/something");
    fixture.MakeACommit();

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

    fixture.MakeACommit();

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

    fixture.Checkout("preview");
    fixture.MergeNoFF("feature/something");
    fixture.Remove("feature/something");

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

    fixture.Checkout("main");
    fixture.MergeNoFF("preview");

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

    fixture.ApplyTag("0.1.3");

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

HHobeck avatar Mar 20 '23 16:03 HHobeck