-
Notifications
You must be signed in to change notification settings - Fork 654
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 mainline always returns latest version based on master branch history, even if building for an older commit #3206
Comments
Here's my proposed change: esimkowitz@6ef5caf I tried to add a test for this behavior in NextVersionCalculatorTests that would create a commit, record the hash and version, create another commit, record the version, then checkout the first commit in detached mode and ensure that the first version is shown and not the second version. This is the way that I was able to reproduce this bug against the official release. Unfortunately, I kept getting an error from GitPreparer.EnsureHeadIsAttachedToBranch saying that I could not do this. Not sure why I can run against a detached HEAD with the release version but not when running the tests? |
I've also reproduced this bug in the latest release 5.10.3 |
Have you tried to use GitVersion with the parameter gitversion /c {commit-id}? Please see gitversion /help for more information.
Also you can use the yaml configuration to ignore commits like:
I'm not sure what you did exactly but I think detached head is not supported with gitversion. |
using the -c flag still produces the incorrect version. I haven't done anything special to the tool to get it to work in detached mode, I simply run here's my GitVersion.yml file if anyone sees something I'm doing wrong here mode: Mainline
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
branches:
master:
regex: ^(origin\/)?main$
is-mainline: true
ignore:
sha: []
merge-message-formats: {} |
Also worth noting in here that we are using the |
@asbjornu I see now that this is listed as a known issue for mainline, has anyone else attempted to correct this issue? |
May I ask you to explain your scenario based on an integration test? If you take the following example what is your expectation? [Test]
public void Just_A_Test()
{
var configuration = GitHubFlowConfigurationBuilder.New
.WithBranch("main", _ => _
.WithIncrement(IncrementStrategy.Patch).WithVersioningMode(VersioningMode.Mainline)
).WithBranch("feature", _ => _
.WithVersioningMode(VersioningMode.Mainline)
).Build();
using var fixture = new EmptyRepositoryFixture("main");
fixture.MakeATaggedCommit("1.0.0");
// ✅ succeeds as expected
fixture.AssertFullSemver("1.0.0", configuration);
fixture.BranchTo("feature/foo");
fixture.MakeACommit();
fixture.Checkout("main");
fixture.MakeACommit();
fixture.Checkout("feature/foo");
// ✅ succeeds as expected
fixture.AssertFullSemver("1.0.1-foo.1", configuration);
} Does it reflect you use case? I'm asking because I'm not sure if it is really a bug. |
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. |
@esimkowitz Could you please answer? |
🎉 This issue has been resolved in version 6.0.0-beta.7 🎉 Your GitReleaseManager bot 📦🚀 |
Describe the bug
My team's build agents sometimes slow down, meaning that new commits are checked into our main branch before old ones have been built. I'm noticing that when GitVersion runs (in separate pipeline runs) for these two backed-up commits, it is applying the same version to both commits.
Expected Behavior
I expect that when GitVersion mainline runs for a specific commit hash, it will generate the version for that hash and not for the latest commit, as it appears to be doing.
Actual Behavior
GitVersion mainline generates the commit for the latest commit hash, even if the commit that is checked out in the build agent (or locally) is older than the latest.
Possible Fix
MainlineVersionCalculator.IncrementForEachCommit should stop at the current reference hash, rather than run for all direct commits on the target master branch.
Steps to Reproduce
Run GitVersion with mainline configuration for the head of the master branch, record the version returned. Then, switch your commit to the next-oldest commit in the branch. You should see that the same version is produced.
Context
In our case, we error out a build if the same version is generated for two commits as it will cause conflicts in our container image tags. While this does not necessarily cause later builds to fail, since we tag the commit after a successful build providing a new base for versioning, it does cause our build pipelines to be flaky when handling commits in rapid succession.
Your Environment
Azure DevOps YAML pipelines and .NET .
Here's the output from gitversion showing it using the latest commit, instead of the current commit to calculate the version:
The text was updated successfully, but these errors were encountered: