GitVersion
GitVersion copied to clipboard
GitVersion not incrementing as expected on mainline mode
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:
masteris currently at0.1.2preview(currently identical tomaster) is at0.1.2-preview0088- We create a new feature off of
previewin a branchfeature/somethingand it gets the version0.1.3-feature-something0001 - We merge
feature/somethingintopreviewandpreviewgets the version0.1.3-preview0001 - We merge
previewintomasterandmastergets the version0.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 tomaster) is at0.1.2-preview0088- We create a new feature off of
previewin a branchfeature/somethingnewand it gets the version0.1.2-feature-somethingnew0001
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.
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?
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?
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.
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);
}