GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

Consecutive pushes to a pull request branch results in conflicting nuget versions

Open simonejsing opened this issue 10 years ago • 8 comments

When GitVersion runs on a PR branch the default logic is to capture the PR id from the branch name and use that for versioning. However, this results in conflicting Nuget version strings when a pull request branch is updated with additional changes.

E.g. assuming I'm proposing to merge a new feature into a repo, I submit a PR that gets the id 1234. Now when the build runs on VSTS it produces Nuget packages with the version number 0.1.0-PullRequest1234, if the build is successful these packages are published to a Nuget feed. Now a colleague gives me feedback on the PR, and I go back and implement these suggestions and push an update to the feed. VSTS build will now kick off a new build on the same branch, resulting in yet another Nuget package versioned 0.1.0-PullRequest1234, after the build completes the publish step fails and the CI build is now failed.

This behavior is governed by: tag-number-pattern: '[/-](?<number>\d+)[-/]'

It seems to me that instead of this pattern dictating the number, it should dictate the tag name. E.g. I should be able to use: tag-suffix-pattern: '[/-](?<number>\d+)[-/]'

Which would append the number to the tag, and keep the default numbering schema where it counts the number of commits. That would make the pull request generate unique Nuget version numbers like: PullRequest1234-0001 PullRequest1234-0002 ...

simonejsing avatar Jun 13 '16 22:06 simonejsing

An alternative solution that I've seen people do in practice is to tag based on the current commit hash. Is that supported through branch specific configuration?

simonejsing avatar Jun 14 '16 00:06 simonejsing

Hey,

This is the default for all branches but I agree that maybe pull requests should have an exception. The main reason for this behaviour is when you release something you tag. The thing is that a PR shouldn't be tagged like that (because then it can't be rebased etc).

Happy to receive a pull request which appends _{commitcount} to pull requests

It will have to be an underscore because I don't think NuGet supports multiple dashes.

JakeGinnivan avatar Jun 14 '16 01:06 JakeGinnivan

Actually Nuget happily accepts dashes in prerelease tags (maybe that is new?). Today '/' in branch names are converted to dashes, resulting in nuget version strings with multiple dashes in them.

simonejsing avatar Jun 14 '16 02:06 simonejsing

Ok cool. All good then.

JakeGinnivan avatar Jun 14 '16 02:06 JakeGinnivan

While working on this I realized that the behavior can almost be obtained by setting the pull request branches to use ContinuousDeployment mode. The only problem with that is that the branch names are captured generically using just their id. E.g. for PR 1234 I would get this version: 7.1.0-1234-0013

In order to preserve the ability to explicitly tag the pull request builds, I introduced the above mentioned construct where you can specify a regex match on the branch to use in the tag: tag-name-pattern: '[/-](?<number>\d+)[-/]'

By setting the mode to be ContinuousDeployment and changing from using tag-number-pattern to the new tag-name-pattern I can make GitVersion version pull request branches uniquely in ContinuousDeployment mode: 7.1.0-pullrequest1234-0013 7.1.0-pullrequest1234-0014 ...

Let me know what you think. I will send a pull request shortly.

simonejsing avatar Jun 14 '16 19:06 simonejsing

Fixed by #906, will be released shortly

JakeGinnivan avatar Jul 10 '16 06:07 JakeGinnivan

I have exactly the same issue at the moment. I'm using GitVersion 4.0-beta11.

I'm also getting duplicate NuGet versions because the PR number is not taken into account.

{
  "Major":1,
  "Minor":0,
  "Patch":4,
  "PreReleaseTag":"PullRequest.15",
  "PreReleaseTagWithDash":"-PullRequest.15",
  "PreReleaseLabel":"PullRequest",
  "PreReleaseNumber":15,
  "BuildMetaData":"",
  "BuildMetaDataPadded":"",
  "FullBuildMetaData":"Branch.pr/39.Sha.9fedfe7f934a4cb9355475f82f79cc7866966760",
  "MajorMinorPatch":"1.0.4",
  "SemVer":"1.0.4-PullRequest.15",
  "LegacySemVer":"1.0.4-PullRequest15",
  "LegacySemVerPadded":"1.0.4-PullRequest0015",
  "AssemblySemVer":"1.0.4.0",
  "FullSemVer":"1.0.4-PullRequest.15",
  "InformationalVersion":"1.0.4-PullRequest.15+Branch.pr/39.Sha.9fedfe7f934a4cb9355475f82f79cc7866966760",
  "BranchName":"pr/39",
  "Sha":"9fedfe7f934a4cb9355475f82f79cc7866966760",
  "NuGetVersionV2":"1.0.4-pullrequest0015",
  "NuGetVersion":"1.0.4-pullrequest0015",
  "NuGetPreReleaseTagV2":"pullrequest0015",
  "NuGetPreReleaseTag":"pullrequest0015",
  "CommitsSinceVersionSource":15,
  "CommitsSinceVersionSourcePadded":"0015",
  "CommitDate":"2017-04-06"
}

In this case the PR number is 39 and the number of commits is 15. 39 does appear in the FullBuildMetaData Using Jenkins as a build system.

@JakeGinnivan @simonejsing Do you have any idea what it could be?

erik-am avatar Apr 06 '17 16:04 erik-am

@simonejsing I could somehow fix it by changing tag-number-pattern: '[/-](?<number>\d+)[-/]' to tag-number-pattern: '[/-](?<number>\d+)' (removing the last character)

erik-am avatar Apr 06 '17 16:04 erik-am