Description
I'm trying to achieve the following:
Versioning NuGet packages using GitVersion. I do not intend to use develop or release branches because it's just overkill for me and my team and would frankly just be a waste of time and effort.
We want to be able to use master as our released branch. Versions on the master branch will always be format {major}.{minor}.{patch}. We would like to use feature branches for new functionality and would like feature branches to also trigger package builds but of a pre-release format such as {major}.{minor}.{patch}-{tag}.{number}. Feature branches merged into master would increment the minor version automatically. Finally, we would like to use hotfix branches for bug fixes. Hotfixes builds would have the same pre-release format as feature branches but when they're merged into master, they'd increment the patch version.
I have tried using both Mainline and Continuous Deployment modes to achieve this but both have failed me so far. I might just be doing something wrong so please advise as to whether this is possible and how.
The documentation shows that my desired outcome should indeed be possible with mainline mode, however this does not seem to be the case in reality.
The documentation contains a graphic which begins like this:
Firstly, this shows that a feature branch has been tagged with 1.0.1-foo.1+1. The current mainline functionality creates a tag with name 1.0.1-foo.1 (missing the +1). Is this documentation just old? Has the +1 part been removed now?
Secondly, the diagram shows that once the feature branch is merged into master, master is then tagged with 1.0.1 (same issue with +2). This is not the case, GitVersion outputs version 1.0.1-foo.2 for me.
Attempt 1
The best I have managed to achieve is by using the following config:
mode: mainline
branches:
master:
tag: ''
regex: ^master$|^main$
increment: minor
feature:
increment: minor
tag: 'alpha'
ignore:
sha: []
merge-message-formats: {}
This results in something like the following:
- master has 1.0.0
- feature branch from master
- commit to feature branch -> 1.1.0-alpha.1 (correct)
- merge feature into master -> 1.1.0 (correct)
- branch hotfix from master
- commit to hotfix branch -> 1.2.0-alpha.1 (incorrect, should be 1.1.1-alpha.1)
- merge hotfix into master -> 1.2.0 (incorrect, should be 1.1.1)
This seems to work for features but not hotfixes, I guess because hotfix is set to increment: inherit by default so it's inheriting the minor from master.
Attempt 2
If I remove increment: minor from master and let it use the default value of patch then I get the following:
mode: mainline
branches:
master:
tag: ''
regex: ^master$|^main$
feature:
increment: minor
tag: 'alpha'
ignore:
sha: []
merge-message-formats: {}
- master has 1.0.0
- feature branch from master
- commit to feature branch -> 1.1.0-alpha.1 (correct)
- merge feature into master -> Exception "Mainline development mode doesn't yet support pre-release tags on master" as it's trying to tag master with 1.1.0-alpha.2.
Attempt 3
I have also tried using Continuous Deployment with the following configuration:
mode: ContinuousDeployment
branches:
master:
tag: ''
regex: ^master$|^main$
feature:
tag: alpha
increment: minor
ignore:
sha: []
merge-message-formats: {}
and this results in the following:
- master has 1.1.0
- feature branch from master
- commit to feature branch -> 1.2.0-alpha.1 (correct)
- merge feature into master -> 1.2.0-alpha.2 (incorrect, should be 1.2.0)
I am using GitVersion through the GitTools Azure Devops tasks (setup and execute) and tagging sources on a successful pipeline build. I can see from the output for this attempt that it's calculating the base version as 1.2.0-alpha.1. Should pre-release tags not be ignored and it should fall back to a base version of 1.1.0 which would then be incremented to 1.2.0? See below for raw output.
2020-12-16T16:57:24.4080029Z ##[section]Starting: Determine Version
2020-12-16T16:57:24.4217819Z ==============================================================================
2020-12-16T16:57:24.4218129Z Task : Execute GitVersion Task
2020-12-16T16:57:24.4218513Z Description : Easy Semantic Versioning (http://semver.org) for projects using Git
2020-12-16T16:57:24.4218760Z Version : 0.9.7
2020-12-16T16:57:24.4218966Z Author : GitTools Contributors
2020-12-16T16:57:24.4219246Z Help : See the documentation for help
2020-12-16T16:57:24.4219548Z ==============================================================================
2020-12-16T16:57:24.7989336Z Command: dotnet-gitversion D:/a/1/s /output json /output buildserver /config D:\a\1\s\GitVersion.yml
2020-12-16T16:57:24.8075944Z [command]C:\hostedtoolcache\windows\GitVersion.Tool\5.5.1\x64\dotnet-gitversion.exe D:/a/1/s /output json /output buildserver /config D:\a\1\s\GitVersion.yml
2020-12-16T16:57:25.6047602Z INFO [12/16/20 16:57:25:09] Working directory: D:/a/1/s
2020-12-16T16:57:25.6048388Z INFO [12/16/20 16:57:25:12] Branch from build environment: refs/heads/main
2020-12-16T16:57:25.6048866Z INFO [12/16/20 16:57:25:12] Project root is: D:\a\1\s
2020-12-16T16:57:25.6049336Z INFO [12/16/20 16:57:25:12] DotGit directory is: D:\a\1\s.git
2020-12-16T16:57:25.6049796Z INFO [12/16/20 16:57:25:12] Begin: Normalizing git directory for branch 'refs/heads/main'
2020-12-16T16:57:25.6050625Z INFO [12/16/20 16:57:25:15] One remote found (origin -> #############).
2020-12-16T16:57:25.6051424Z INFO [12/16/20 16:57:25:16] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2020-12-16T16:57:25.6052625Z INFO [12/16/20 16:57:25:16] Creating local branch refs/heads/main
2020-12-16T16:57:25.6053159Z INFO [12/16/20 16:57:25:19] Creating local branch from remote tracking 'refs/remotes/origin/cb222b104f4e5c5a0cb68e60febb5df259faac8e'.
2020-12-16T16:57:25.6053844Z INFO [12/16/20 16:57:25:21] Creating local branch from remote tracking 'refs/remotes/origin/feature/test-branch-1'.
2020-12-16T16:57:25.6054400Z INFO [12/16/20 16:57:25:21] HEAD points at branch 'refs/heads/main'.
2020-12-16T16:57:25.6054899Z INFO [12/16/20 16:57:25:21] End: Normalizing git directory for branch 'refs/heads/main' (Took: 91.91ms)
2020-12-16T16:57:25.6055326Z INFO [12/16/20 16:57:25:23] Begin: Loading version variables from disk cache
2020-12-16T16:57:25.6055730Z INFO [12/16/20 16:57:25:23] Cache file D:\a\1\s.git\gitversion_cache\6817D159E690E99F6678446CA8000B75EAEAADDF.yml not found.
2020-12-16T16:57:25.6056725Z INFO [12/16/20 16:57:25:23] End: Loading version variables from disk cache (Took: 1.79ms)
2020-12-16T16:57:25.6057072Z INFO [12/16/20 16:57:25:34] Using latest commit on specified branch
2020-12-16T16:57:25.6057425Z INFO [12/16/20 16:57:25:37] Running against branch: main (cb222b104f4e5c5a0cb68e60febb5df259faac8e)
2020-12-16T16:57:25.6057761Z INFO [12/16/20 16:57:25:37] Begin: Calculating base versions
2020-12-16T16:57:25.6058136Z INFO [12/16/20 16:57:25:51] Git tag '1.2.0-alpha.1': 1.2.0-alpha.1 with commit count source 06079f3281d3c4f325945e955c249271db3e128d
2020-12-16T16:57:25.6058608Z INFO [12/16/20 16:57:25:51] Git tag '1.1.0': 1.1.0 with commit count source 32c67b8ede2ffd0a87068b881a072386deb7ce29
2020-12-16T16:57:25.6059059Z INFO [12/16/20 16:57:25:51] Git tag '1.1.0-alpha.1': 1.1.0-alpha.1 with commit count source 736717e810ee3059d4b0d9cf60ff388df7c3cd15
2020-12-16T16:57:25.6059515Z INFO [12/16/20 16:57:25:51] Git tag '1.0.0': 1.0.0 with commit count source 0feb9d80f8e8379a17824a314295cbbd2d2debe4
2020-12-16T16:57:25.6060091Z INFO [12/16/20 16:57:25:51] Found multiple base versions which will produce the same SemVer (1.2.0-alpha.2), taking oldest source for commit counting (Git tag '1.2.0-alpha.1')
2020-12-16T16:57:25.6060852Z INFO [12/16/20 16:57:25:52] Base version used: Git tag '1.2.0-alpha.1': 1.2.0-alpha.1 with commit count source 06079f3281d3c4f325945e955c249271db3e128d
2020-12-16T16:57:25.6064191Z INFO [12/16/20 16:57:25:52] End: Calculating base versions (Took: 145.82ms)
2020-12-16T16:57:25.6064744Z INFO [12/16/20 16:57:25:52] 1 commits found between 06079f3281d3c4f325945e955c249271db3e128d and cb222b104f4e5c5a0cb68e60febb5df259faac8e
2020-12-16T16:57:25.6065096Z INFO [12/16/20 16:57:25:52] Begin: Creating dictionary
2020-12-16T16:57:25.6065377Z INFO [12/16/20 16:57:25:53] End: Creating dictionary (Took: 4.47ms)
2020-12-16T16:57:25.6065826Z INFO [12/16/20 16:57:25:53] Begin: Storing version variables to cache file D:\a\1\s.git\gitversion_cache\6817D159E690E99F6678446CA8000B75EAEAADDF.yml
2020-12-16T16:57:25.6066992Z INFO [12/16/20 16:57:25:56] End: Storing version variables to cache file D:\a\1\s.git\gitversion_cache\6817D159E690E99F6678446CA8000B75EAEAADDF.yml (Took: 31.94ms)
2020-12-16T16:57:25.6067471Z Executing GenerateSetVersionMessage for 'AzurePipelines'.
2020-12-16T16:57:25.6927966Z Executing GenerateBuildLogOutput for 'AzurePipelines'.
2020-12-16T16:57:25.6970940Z {
2020-12-16T16:57:25.6971317Z "Major":1,
2020-12-16T16:57:25.6971494Z "Minor":2,
2020-12-16T16:57:25.6971624Z "Patch":0,
2020-12-16T16:57:25.6971776Z "PreReleaseTag":"alpha.2",
2020-12-16T16:57:25.6971967Z "PreReleaseTagWithDash":"-alpha.2",
2020-12-16T16:57:25.6972178Z "PreReleaseLabel":"alpha",
2020-12-16T16:57:25.6972348Z "PreReleaseNumber":2,
2020-12-16T16:57:25.6972533Z "WeightedPreReleaseNumber":55002,
2020-12-16T16:57:25.6972730Z "BuildMetaData":"",
2020-12-16T16:57:25.6972898Z "BuildMetaDataPadded":"",
2020-12-16T16:57:25.6973148Z "FullBuildMetaData":"Branch.main.Sha.cb222b104f4e5c5a0cb68e60febb5df259faac8e",
2020-12-16T16:57:25.6973396Z "MajorMinorPatch":"1.2.0",
2020-12-16T16:57:25.6973582Z "SemVer":"1.2.0-alpha.2",
2020-12-16T16:57:25.6973760Z "LegacySemVer":"1.2.0-alpha2",
2020-12-16T16:57:25.6973967Z "LegacySemVerPadded":"1.2.0-alpha0002",
2020-12-16T16:57:25.6974179Z "AssemblySemVer":"1.2.0.0",
2020-12-16T16:57:25.6974366Z "AssemblySemFileVer":"1.2.0.0",
2020-12-16T16:57:25.6974553Z "FullSemVer":"1.2.0-alpha.2",
2020-12-16T16:57:25.6974830Z "InformationalVersion":"1.2.0-alpha.2+Branch.main.Sha.cb222b104f4e5c5a0cb68e60febb5df259faac8e",
2020-12-16T16:57:25.6975105Z "BranchName":"main",
2020-12-16T16:57:25.6975280Z "EscapedBranchName":"main",
2020-12-16T16:57:25.6975485Z "Sha":"cb222b104f4e5c5a0cb68e60febb5df259faac8e",
2020-12-16T16:57:25.6976330Z "ShortSha":"cb222b1",
2020-12-16T16:57:25.6976524Z "NuGetVersionV2":"1.2.0-alpha0002",
2020-12-16T16:57:25.6976722Z "NuGetVersion":"1.2.0-alpha0002",
2020-12-16T16:57:25.6976937Z "NuGetPreReleaseTagV2":"alpha0002",
2020-12-16T16:57:25.6977141Z "NuGetPreReleaseTag":"alpha0002",
2020-12-16T16:57:25.6977377Z "VersionSourceSha":"06079f3281d3c4f325945e955c249271db3e128d",
2020-12-16T16:57:25.6977611Z "CommitsSinceVersionSource":1,
2020-12-16T16:57:25.6977850Z "CommitsSinceVersionSourcePadded":"0001",
2020-12-16T16:57:25.6978051Z "UncommittedChanges":0,
2020-12-16T16:57:25.6978681Z "CommitDate":"2020-12-16"
2020-12-16T16:57:25.6978840Z }
2020-12-16T16:57:25.6978997Z INFO [12/16/20 16:57:25:58] Done writing
2020-12-16T16:57:25.7034054Z ##[section]Async Command Start: Update Build Number
2020-12-16T16:57:26.6298412Z Update build number to 1.2.0-alpha.2 for build 2815
2020-12-16T16:57:26.6298754Z ##[section]Async Command End: Update Build Number
2020-12-16T16:57:26.6299983Z ##[section]Finishing: Determine Version