Skip to content
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 (in Azure Devops) calculating wrong version when building a tag #4015

Open
2 tasks done
arnoschuring-miele opened this issue Apr 30, 2024 · 8 comments
Open
2 tasks done

Comments

@arnoschuring-miele
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

AzureDevops task

GitVersion version

5.12.0

Operating system

Linux

What are you seeing?

When building on a tag in Azure Devops, GitVersion is generating a new pre-release version rather than using the already-placed tag. This seems entirely similar to #2074 and #2456.

The current config is quite minimal:

commit-date-format: yyyyMMdd
mode: Mainline
tag-prefix: '[vV]_'

I cannot run this locally to get more info, because a) when I do a git checkout of the tag locally, it generates the correct version number, and b) it seems to completely ignore any -verbosity argument specified.

I suspect this line (from the log) is the problem:

Detected forward merge [..] ; rewinding mainline to previous commit

And that may be because we merged the same branch twice:

*   dc43f3b (HEAD, tag: v_0.1.2, origin/main, main)
|\
| * 9e67e70 (origin/feature/1648-snip-branch-name, feature/1648-snip-branch-name)
* | 0ec823e
|\|
| * 7648056
| * 0daea29
| * f31a425
| * f83209c
| * 1c3ef10

|/
* a102d74

What is expected?

GitVersion should generate a version number that matches exactly the already-placed tag v_0.1.2 (as it does locally)

Steps to Reproduce

I have not been able to reproduce this locally, even with the exact git checkout procedure that ADO is using:

git init
git remote add origin $devops_repo_url
git fetch origin --tags
git fetch origin +dc43f3be8e9f7d955998e0554fdfb4286bfbdfee
git checkout --progress --force dc43f3be8e9f7d955998e0554fdfb4286bfbdfee
../gitversion.exe -verbosity diagnostic -config ../deployment-automation/config/gitversion.yaml

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

/opt/hostedtoolcache/GitVersion.Tool/5.12.0/x64/dotnet-gitversion /home/vsts/work/1/s /output json /output buildserver /config /home/vsts/work/1/_automation/config/gitversion.yaml
INFO [04/30/24 8:03:23:92] Working directory: /home/vsts/work/1/s
INFO [04/30/24 8:03:23:95] Project root is: /home/vsts/work/1/s/
INFO [04/30/24 8:03:23:95] DotGit directory is: /home/vsts/work/1/s/.git
INFO [04/30/24 8:03:23:95] Branch from build environment: refs/tags/v_0.1.2
INFO [04/30/24 8:03:23:95] Begin: Normalizing git directory for branch 'refs/tags/v_0.1.2'
  INFO [04/30/24 8:03:23:98] One remote found (origin -> 'https://xxx@dev.azure.com/$org/$proj/_git/$repo').
  INFO [04/30/24 8:03:23:98] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/30/24 8:03:23:99] Creating local branch tags/v_0.1.2 pointing at dc43f3b
  INFO [04/30/24 8:03:24:02] Creating local branch from remote tracking 'refs/remotes/origin/feature/1648-snip-branch-name'.
  INFO [04/30/24 8:03:24:03] Creating local branch from remote tracking 'refs/remotes/origin/main'.
  INFO [04/30/24 8:03:24:03] HEAD points at branch 'refs/heads/tags/v_0.1.2'.
  INFO [04/30/24 8:03:24:04] End: Normalizing git directory for branch 'refs/tags/v_0.1.2' (Took: 85.69ms)
  INFO [04/30/24 8:03:24:05] Begin: Loading version variables from disk cache
    INFO [04/30/24 8:03:24:05] Cache file /home/vsts/work/1/s/.git/gitversion_cache/533DF5CDE0896219ADDB98A2ACCB99A576CC506E.yml not found.
  INFO [04/30/24 8:03:24:05] End: Loading version variables from disk cache (Took: 0.46ms)
  INFO [04/30/24 8:03:24:05] Using latest commit on specified branch
  INFO [04/30/24 8:03:24:17] Running against branch: tags/v_0.1.2 (dc43f3b Merged PR 5351: [snip PR message])
  INFO [04/30/24 8:03:24:17] Current commit is tagged with version 0.1.2, version calculation is for metadata only.
  INFO [04/30/24 8:03:24:18] 0 commits found between dc43f3b Merged PR 5351: [snip PR message] and dc43f3b Merged PR 5351: [snip PR message]
  INFO [04/30/24 8:03:24:18] Begin: Calculating base versions
    INFO [04/30/24 8:03:24:19] No branch configuration found for branch tags/v_0.1.2, falling back to default configuration
    INFO [04/30/24 8:03:24:19] Begin: Attempting to inherit branch configuration from parent branch
      INFO [04/30/24 8:03:24:19] HEAD is merge commit, this is likely a pull request using feature/1648-snip-branch-name as base
      INFO [04/30/24 8:03:24:20] Begin: Finding branch source of 'feature/1648-snip-branch-name'
        INFO [04/30/24 8:03:24:21] Begin: Finding merge base between 'feature/1648-snip-branch-name' and 'main'.
          INFO [04/30/24 8:03:24:22] Found merge base of 7648056 follow template variable renames
          INFO [04/30/24 8:03:24:22] Merge base was due to a forward merge, next merge base is a102d74 bundle init
          INFO [04/30/24 8:03:24:22] Merge base of feature/1648-snip-branch-name' and 'main is a102d74 bundle init
        INFO [04/30/24 8:03:24:22] End: Finding merge base between 'feature/1648-snip-branch-name' and 'main'. (Took: 10.27ms)
      INFO [04/30/24 8:03:24:22] End: Finding branch source of 'feature/1648-snip-branch-name' (Took: 21.60ms)
      INFO [04/30/24 8:03:24:23] Begin: Getting branches containing the commit 'a102d74'.
        INFO [04/30/24 8:03:24:23] Trying to find direct branches.
        INFO [04/30/24 8:03:24:23] No direct branches found, searching through all branches.
        INFO [04/30/24 8:03:24:23] Searching for commits reachable from 'main'.
        INFO [04/30/24 8:03:24:23] The branch 'main' has a matching commit.
      INFO [04/30/24 8:03:24:23] End: Getting branches containing the commit 'a102d74'. (Took: 1.66ms)
      INFO [04/30/24 8:03:24:23] Found possible parent branches: main
    INFO [04/30/24 8:03:24:23] End: Attempting to inherit branch configuration from parent branch (Took: 38.50ms)
    INFO [04/30/24 8:03:24:23] Fallback base version: 0.1.0 with commit count source a102d7409179ba5d4b5e3dd443e80f67dc5411f0
    INFO [04/30/24 8:03:24:28] Git tag 'v_0.1.2': 0.1.2 with commit count source dc43f3be8e9f7d955998e0554fdfb4286bfbdfee
    INFO [04/30/24 8:03:24:30] Found multiple base versions which will produce the same SemVer (0.1.2), taking oldest source for commit counting (Git tag 'v_0.1.2')
    INFO [04/30/24 8:03:24:30] Base version used: Git tag 'v_0.1.2': 0.1.2 with commit count source dc43f3be8e9f7d955998e0554fdfb4286bfbdfee
  INFO [04/30/24 8:03:24:30] End: Calculating base versions (Took: 116.91ms)
  INFO [04/30/24 8:03:24:30] 0 commits found between dc43f3b Merged PR 5351: [snip PR message] and dc43f3b Merged PR 5351: [snip PR message]
  INFO [04/30/24 8:03:24:30] Begin: Using mainline development mode to calculate current version
    INFO [04/30/24 8:03:24:30] '^master$|^main$' does not match 'feature/1648-snip-branch-name'.
    INFO [04/30/24 8:03:24:30] '^support[/-]' does not match 'feature/1648-snip-branch-name'.
    INFO [04/30/24 8:03:24:30] '^master$|^main$' matches 'main'.
    INFO [04/30/24 8:03:24:30] Found merge base dc43f3be8e9f7d955998e0554fdfb4286bfbdfee for 'main'.
    INFO [04/30/24 8:03:24:30] '^master$|^main$' does not match 'tags/v_0.1.2'.
    INFO [04/30/24 8:03:24:31] '^support[/-]' does not match 'tags/v_0.1.2'.
    INFO [04/30/24 8:03:24:31] '^master$|^main$' does not match 'feature/1648-snip-branch-name'.
    INFO [04/30/24 8:03:24:31] '^support[/-]' does not match 'feature/1648-snip-branch-name'.
    INFO [04/30/24 8:03:24:31] '^master$|^main$' matches 'main'.
    INFO [04/30/24 8:03:24:31] Found merge base dc43f3be8e9f7d955998e0554fdfb4286bfbdfee for 'origin/main'.
    INFO [04/30/24 8:03:24:31] Found possible mainline branches: main, origin/main
    INFO [04/30/24 8:03:24:31] Multiple mainlines (main, origin/main) have the same merge base for the current branch, choosing main because we found that branch first...
    INFO [04/30/24 8:03:24:31] Detected forward merge at dc43f3b Merged PR 5351: [snip PR message]; rewinding mainline to previous commit 0ec823e Merged PR [snip PR message]
    INFO [04/30/24 8:03:24:31] Current branch (tags/v_0.1.2) was branch from 0ec823e Merged PR 5349: [snip PR message]
    INFO [04/30/24 8:03:24:31] 2 commits found between 0ec823e Merged PR 5349: [snip PR message] and dc43f3b Merged PR 5351: [snip PR message]
    INFO [04/30/24 8:03:24:32] Performing Patch increment for current branch 
  INFO [04/30/24 8:03:24:32] End: Using mainline development mode to calculate current version (Took: 21.16ms)
  INFO [04/30/24 8:03:24:32] Using branch name to calculate version tag
  INFO [04/30/24 8:03:24:32] Begin: Getting version tags from branch 'refs/heads/tags/v_0.1.2'.
  INFO [04/30/24 8:03:24:33] End: Getting version tags from branch 'refs/heads/tags/v_0.1.2'. (Took: 4.22ms)
  INFO [04/30/24 8:03:24:33] Begin: Creating dictionary
  INFO [04/30/24 8:03:24:34] End: Creating dictionary (Took: 3.97ms)
  INFO [04/30/24 8:03:24:34] Begin: Storing version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/533DF5CDE0896219ADDB98A2ACCB99A576CC506E.yml
  INFO [04/30/24 8:03:24:37] End: Storing version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/533DF5CDE0896219ADDB98A2ACCB99A576CC506E.yml (Took: 27.00ms)
Executing GenerateSetVersionMessage for 'AzurePipelines'.
Executing GenerateBuildLogOutput for 'AzurePipelines'.

{
  "Major": 0,
  "Minor": 1,
  "Patch": 3,
  "PreReleaseTag": "tags-v-0-1-2.2",
  "PreReleaseTagWithDash": "-tags-v-0-1-2.2",
  "PreReleaseLabel": "tags-v-0-1-2",
  "PreReleaseLabelWithDash": "-tags-v-0-1-2",
  "PreReleaseNumber": 2,
  "WeightedPreReleaseNumber": 2,
  "BuildMetaData": null,
  "BuildMetaDataPadded": "",
  "FullBuildMetaData": "Branch.tags-v-0.1.2.Sha.dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "MajorMinorPatch": "0.1.3",
  "SemVer": "0.1.3-tags-v-0-1-2.2",
  "LegacySemVer": "0.1.3-tags-v-0-1-2-2",
  "LegacySemVerPadded": "0.1.3-tags-v-0-1-2-0002",
  "AssemblySemVer": "0.1.3.0",
  "AssemblySemFileVer": "0.1.3.0",
  "FullSemVer": "0.1.3-tags-v-0-1-2.2",
  "InformationalVersion": "0.1.3-tags-v-0-1-2.2+Branch.tags-v-0.1.2.Sha.dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "BranchName": "tags/v_0.1.2",
  "EscapedBranchName": "tags-v-0-1-2",
  "Sha": "dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "ShortSha": "dc43f3b",
  "NuGetVersionV2": "0.1.3-tags-v-0-1-2-0002",
  "NuGetVersion": "0.1.3-tags-v-0-1-2-0002",
  "NuGetPreReleaseTagV2": "tags-v-0-1-2-0002",
  "NuGetPreReleaseTag": "tags-v-0-1-2-0002",
  "VersionSourceSha": "0ec823e29ec9a35f811fc305220c3c212c56226e",
  "CommitsSinceVersionSource": 2,
  "CommitsSinceVersionSourcePadded": "0002",
  "UncommittedChanges": 0,
  "CommitDate": "20240426"
}
@arnoschuring-miele arnoschuring-miele changed the title [BUG]: GitVersion (again?) calculating wrong version when building a tag [BUG]: GitVersion (in Azure Devops) calculating wrong version when building a tag Apr 30, 2024
@asbjornu
Copy link
Member

I believe this is fixed in v6. Can you upgrade and try it out?

@arnoschuring-miele
Copy link
Author

It doesn't seem fixed, as GitVersion still generates a prerelease version. I had to change mode: Mainline to workflow: TrunkBased/v1 but I did not make any other changes to the config file. I'm not sure if that is correct, but I still see this line in the output logs:

INFO [04/30/24 13:09:20:46] TrunkBasedVersionStrategy: Force version increment '0.1.2' +semver 'Patch' with label 'tags-v_0-1-2' based on commit 'dc43f3b'.

and I don't think it should add any +semver here because commit dc43f3b is exactly the commit where tag v_0.1.2 points to.

This is the full output from a v6 run:

/opt/hostedtoolcache/GitVersion.Tool/6.0.0-beta.7/x64/dotnet-gitversion /home/vsts/work/1/s /output json /output buildserver /config /home/vsts/work/1/_automation/config/gitversion.yaml
INFO [04/30/24 13:09:20:01] Working directory: /home/vsts/work/1/s
INFO [04/30/24 13:09:20:02] Project root is: /home/vsts/work/1/s/
INFO [04/30/24 13:09:20:02] DotGit directory is: /home/vsts/work/1/s/.git
INFO [04/30/24 13:09:20:02] Branch from build environment: refs/tags/v_0.1.2
INFO [04/30/24 13:09:20:02] -< Begin: Normalizing git directory for branch 'refs/tags/v_0.1.2' >-
  INFO [04/30/24 13:09:20:05] One remote found (origin -> 'https://xxx@dev.azure.com/$org/$proj/_git/$repo').
  INFO [04/30/24 13:09:20:06] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/30/24 13:09:20:06] Creating local branch tags/v_0.1.2 pointing at dc43f3b
  INFO [04/30/24 13:09:20:09] Creating local branch from remote tracking 'refs/remotes/origin/feature/1648-snip-branch-name'.
  INFO [04/30/24 13:09:20:10] Creating local branch from remote tracking 'refs/remotes/origin/main'.
  INFO [04/30/24 13:09:20:11] HEAD points at branch 'refs/heads/tags/v_0.1.2'.
INFO [04/30/24 13:09:20:11] -< End: Normalizing git directory for branch 'refs/tags/v_0.1.2' (Took: 89.83ms) >-
INFO [04/30/24 13:09:20:13] -< Begin: Loading version variables from disk cache file /home/vsts/work/1/s/.git/gitversion_cache/CCA1D0FE3372DDA3A3818BCD8368D89CB00A09C7 >-
  INFO [04/30/24 13:09:20:13] Cache file /home/vsts/work/1/s/.git/gitversion_cache/CCA1D0FE3372DDA3A3818BCD8368D89CB00A09C7 not found.
INFO [04/30/24 13:09:20:13] -< End: Loading version variables from disk cache file /home/vsts/work/1/s/.git/gitversion_cache/CCA1D0FE3372DDA3A3818BCD8368D89CB00A09C7 (Took: 0.17ms) >-
INFO [04/30/24 13:09:20:31] Using latest commit on specified branch
INFO [04/30/24 13:09:20:33] Getting tagged semantic versions. TagPrefix: [vV]_ and Format: Strict
INFO [04/30/24 13:09:20:38] Running against branch: tags/v_0.1.2 ('dc43f3b' - Merged PR 5351: [snip PR message])
INFO [04/30/24 13:09:20:38] -< Begin: Fetching the base versions for version calculation... >-
  INFO [04/30/24 13:09:20:39] Calculating base versions for 'tags/v_0.1.2'
  INFO [04/30/24 13:09:20:39] -< Begin: [Using 'ConfiguredNextVersionVersionStrategy' strategy] >-
  INFO [04/30/24 13:09:20:39] -< End: [Using 'ConfiguredNextVersionVersionStrategy' strategy] (Took: 0.53ms) >-
  INFO [04/30/24 13:09:20:39] -< Begin: [Using 'MergeMessageVersionStrategy' strategy] >-
  INFO [04/30/24 13:09:20:39] -< End: [Using 'MergeMessageVersionStrategy' strategy] (Took: 0.39ms) >-
  INFO [04/30/24 13:09:20:39] -< Begin: [Using 'TaggedCommitVersionStrategy' strategy] >-
  INFO [04/30/24 13:09:20:39] -< End: [Using 'TaggedCommitVersionStrategy' strategy] (Took: 0.21ms) >-
  INFO [04/30/24 13:09:20:39] -< Begin: [Using 'TrackReleaseBranchesVersionStrategy' strategy] >-
  INFO [04/30/24 13:09:20:39] -< End: [Using 'TrackReleaseBranchesVersionStrategy' strategy] (Took: 0.14ms) >-
  INFO [04/30/24 13:09:20:39] -< Begin: [Using 'TrunkBasedVersionStrategy' strategy] >-
    INFO [04/30/24 13:09:20:40] -< Begin: Getting tagged semantic versions on branch 'refs/heads/tags/v_0.1.2'. TagPrefix: [vV]_ and Format: Strict >-
    INFO [04/30/24 13:09:20:40] -< End: Getting tagged semantic versions on branch 'refs/heads/tags/v_0.1.2'. TagPrefix: [vV]_ and Format: Strict (Took: 3.14ms) >-
    INFO [04/30/24 13:09:20:40] -< Begin: Getting tagged semantic versions of mainline branches. TagPrefix: [vV]_ and Format: Strict >-
      INFO [04/30/24 13:09:20:41] -< Begin: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]_ and Format: Strict >-
      INFO [04/30/24 13:09:20:41] -< End: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]_ and Format: Strict (Took: 0.70ms) >-
      INFO [04/30/24 13:09:20:41] -< Begin: Getting tagged semantic versions on branch 'refs/remotes/origin/main'. TagPrefix: [vV]_ and Format: Strict >-
      INFO [04/30/24 13:09:20:41] -< End: Getting tagged semantic versions on branch 'refs/remotes/origin/main'. TagPrefix: [vV]_ and Format: Strict (Took: 0.65ms) >-
    INFO [04/30/24 13:09:20:41] -< End: Getting tagged semantic versions of mainline branches. TagPrefix: [vV]_ and Format: Strict (Took: 3.94ms) >-
    INFO [04/30/24 13:09:20:42] -< Begin: Finding branches source of 'tags/v_0.1.2' >-
      INFO [04/30/24 13:09:20:42] -< Begin: Finding merge base between 'tags/v_0.1.2' and 'main'. >-
        INFO [04/30/24 13:09:20:43] Found merge base of ''dc43f3b' - Merged PR 5351: [snip PR message]'
        INFO [04/30/24 13:09:20:43] Merge base of 'tags/v_0.1.2' and 'main' is ''dc43f3b' - Merged PR 5351: [snip PR message]'
      INFO [04/30/24 13:09:20:43] -< End: Finding merge base between 'tags/v_0.1.2' and 'main'. (Took: 9.99ms) >-
      INFO [04/30/24 13:09:20:43] -< Begin: Finding merge base between 'tags/v_0.1.2' and 'origin/main'. >-
        INFO [04/30/24 13:09:20:43] Found merge base of ''dc43f3b' - Merged PR 5351: [snip PR message]'
        INFO [04/30/24 13:09:20:43] Merge base of 'tags/v_0.1.2' and 'origin/main' is ''dc43f3b' - Merged PR 5351: [snip PR message]'
      INFO [04/30/24 13:09:20:43] -< End: Finding merge base between 'tags/v_0.1.2' and 'origin/main'. (Took: 0.48ms) >-
    INFO [04/30/24 13:09:20:44] -< End: Finding branches source of 'tags/v_0.1.2' (Took: 21.45ms) >-
    INFO [04/30/24 13:09:20:46] TrunkBasedVersionStrategy: Force version increment '0.1.2' +semver 'Patch' with label 'tags-v_0-1-2' based on commit 'dc43f3b'.
    INFO [04/30/24 13:09:20:47] Using current branch name to calculate version tag
  INFO [04/30/24 13:09:20:47] -< End: [Using 'TrunkBasedVersionStrategy' strategy] (Took: 77.51ms) >-
  INFO [04/30/24 13:09:20:47] -< Begin: [Using 'VersionInBranchNameVersionStrategy' strategy] >-
  INFO [04/30/24 13:09:20:47] -< End: [Using 'VersionInBranchNameVersionStrategy' strategy] (Took: 0.39ms) >-
INFO [04/30/24 13:09:20:47] -< End: Fetching the base versions for version calculation... (Took: 82.83ms) >-
INFO [04/30/24 13:09:20:47] -------------------------------------------------------
INFO [04/30/24 13:09:20:47] Found multiple base versions which will produce the same SemVer (0.1.3-tags-v_0-1-2.1), taking oldest source for commit counting (TrunkBasedVersionStrategy)
INFO [04/30/24 13:09:20:47] Base version used: TrunkBasedVersionStrategy: 0.1.2 with commit source 'dc43f3be8e9f7d955998e0554fdfb4286bfbdfee'
INFO [04/30/24 13:09:20:47] -------------------------------------------------------
INFO [04/30/24 13:09:20:47] -< Begin: Using continuous delivery workflow to calculate the incremented version. >-
  INFO [04/30/24 13:09:20:47] 0 commits found between 'dc43f3b' - Merged PR 5351: [snip PR message] and 'dc43f3b' - Merged PR 5351: [snip PR message]
INFO [04/30/24 13:09:20:47] -< End: Using continuous delivery workflow to calculate the incremented version. (Took: 2.06ms) >-
INFO [04/30/24 13:09:20:48] -< Begin: Write version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/CCA1D0FE3372DDA3A3818BCD8368D89CB00A09C7 >-
INFO [04/30/24 13:09:20:52] -< End: Write version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/CCA1D0FE3372DDA3A3818BCD8368D89CB00A09C7 (Took: 42.49ms) >-


{
  "AssemblySemFileVer": "0.1.3.0",
  "AssemblySemVer": "0.1.3.0",
  "BranchName": "tags/v_0.1.2",
  "BuildMetaData": null,
  "CommitDate": "20240426",
  "CommitsSinceVersionSource": 0,
  "EscapedBranchName": "tags-v-0-1-2",
  "FullBuildMetaData": "Branch.tags-v-0.1.2.Sha.dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "FullSemVer": "0.1.3-tags-v_0-1-2.0",
  "InformationalVersion": "0.1.3-tags-v_0-1-2.0+Branch.tags-v-0.1.2.Sha.dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "Major": 0,
  "MajorMinorPatch": "0.1.3",
  "Minor": 1,
  "Patch": 3,
  "PreReleaseLabel": "tags-v_0-1-2",
  "PreReleaseLabelWithDash": "-tags-v_0-1-2",
  "PreReleaseNumber": 0,
  "PreReleaseTag": "tags-v_0-1-2.0",
  "PreReleaseTagWithDash": "-tags-v_0-1-2.0",
  "SemVer": "0.1.3-tags-v_0-1-2.0",
  "Sha": "dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "ShortSha": "dc43f3b",
  "UncommittedChanges": 0,
  "VersionSourceSha": "dc43f3be8e9f7d955998e0554fdfb4286bfbdfee",
  "WeightedPreReleaseNumber": 30000
}

@asbjornu
Copy link
Member

asbjornu commented May 6, 2024

@HHobeck, is it expected behavior that tagged commits aren't picked up with the TrunkBased workflow?

@davidkeaveny
Copy link
Contributor

davidkeaveny commented May 7, 2024

If it's any help, I'm seeing the same issue when using GitVersion 5.10.3 on GitHub Actions. If I create a release in GitHub and tag it as e.g. 0.0.0-beta+7 and run dotnet-gitversion locally, then the pre-release tag is correctly generated as beta+7, but when my GitHub action executes, the pre-release tag is calculated as tags-0-0-1-beta-7.1

@HHobeck
Copy link
Contributor

HHobeck commented May 7, 2024

@HHobeck, is it expected behavior that tagged commits aren't picked up with the TrunkBased workflow?

To answer your question: Yes of course the TrunkBased workflow (which uses the Mainline version stratgey) considers tags. Anyway I think it has nothing to do with the used strategy. If you see the log output then you see the following:

Branch from build environment: refs/tags/v_0.1.2

That means the current branch is of name tags/v_0.1.2. Because we have no branch configuration with name tags the algorithm uses the unknown branch configuration.

  unknown:
    increment: Patch
    regex: (?<BranchName>.+)
    prevent-increment:
      when-current-commit-tagged: false
    source-branches:
    - main
    pre-release-weight: 30000

@asbjornu
Copy link
Member

asbjornu commented May 7, 2024

@HHobeck as I suspected. So it is the repository normalization that is causing this problem, which I thought was fixed. Oh well.

@HHobeck
Copy link
Contributor

HHobeck commented May 7, 2024

@HHobeck as I suspected. So it is the repository normalization that is causing this problem, which I thought was fixed. Oh well.

The normalization process is something I have not touched. I have a common understanding what this module does but don't know the overall design. I think the behavior having a branch with name e.g. tags/1.0.0 is also something I have seen with azure devops as well.

Maybe it is by design and we need to change the configuration and add a tags branch configuration? Or let me ask the question different: Which branch would you use in the normalization process when starting the artefact creation by selecting just a tag? Maybe this discussion goes in the same direction: #3907

@arnoschuring-miele
Copy link
Author

Note that this is only an issue in Mainline mode. If I change my configuration to mode: ContinuousDelivery, the tag gets used correctly (even with the weird refs/heads/tags/ local branch):

[command]/opt/hostedtoolcache/GitVersion.Tool/5.12.0/x64/dotnet-gitversion /home/vsts/work/1/s /output json /output buildserver /config /home/vsts/work/1/_automation/config/gitversion.yaml
INFO [05/01/24 12:05:45:46] Working directory: /home/vsts/work/1/s
INFO [05/01/24 12:05:45:48] Project root is: /home/vsts/work/1/s/
INFO [05/01/24 12:05:45:48] DotGit directory is: /home/vsts/work/1/s/.git
INFO [05/01/24 12:05:45:48] Branch from build environment: refs/tags/v_0.1.3
INFO [05/01/24 12:05:45:48] Begin: Normalizing git directory for branch 'refs/tags/v_0.1.3'
  INFO [05/01/24 12:05:45:51] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [05/01/24 12:05:45:52] Creating local branch tags/v_0.1.3 pointing at f68cded
  INFO [05/01/24 12:05:45:54] Creating local branch from remote tracking 'refs/remotes/origin/feature/1648-snip-branch-name'.
  INFO [05/01/24 12:05:45:55] Creating local branch from remote tracking 'refs/remotes/origin/main'.
  INFO [05/01/24 12:05:45:55] HEAD points at branch 'refs/heads/tags/v_0.1.3'.
  INFO [05/01/24 12:05:45:56] End: Normalizing git directory for branch 'refs/tags/v_0.1.3' (Took: 69.54ms)
  INFO [05/01/24 12:05:45:56] Begin: Loading version variables from disk cache
    INFO [05/01/24 12:05:45:56] Cache file /home/vsts/work/1/s/.git/gitversion_cache/E5BE13EBFDB188C579FDC6D9387C0F7C6B8A1675.yml not found.
  INFO [05/01/24 12:05:45:56] End: Loading version variables from disk cache (Took: 0.36ms)
  INFO [05/01/24 12:05:45:57] Using latest commit on specified branch
  INFO [05/01/24 12:05:45:66] Running against branch: tags/v_0.1.3 (f68cded Merged PR 5393: [snip PR message])
  INFO [05/01/24 12:05:45:66] Current commit is tagged with version 0.1.3, version calculation is for metadata only.
  INFO [05/01/24 12:05:45:67] 0 commits found between f68cded Merged PR 5393: [snip PR message] and f68cded Merged PR 5393: [snip PR message]
  INFO [05/01/24 12:05:45:67] Begin: Calculating base versions
    INFO [05/01/24 12:05:45:68] No branch configuration found for branch tags/v_0.1.3, falling back to default configuration
    INFO [05/01/24 12:05:45:68] Begin: Attempting to inherit branch configuration from parent branch
      INFO [05/01/24 12:05:45:68] HEAD is merge commit, this is likely a pull request using tags/v_0.1.3 as base
      INFO [05/01/24 12:05:45:68] Begin: Finding branch source of 'tags/v_0.1.3'
        INFO [05/01/24 12:05:45:69] Begin: Finding merge base between 'tags/v_0.1.3' and 'main'.
          INFO [05/01/24 12:05:45:69] Found merge base of f68cded Merged PR 5393: [snip PR message]
          INFO [05/01/24 12:05:45:69] Merge base of tags/v_0.1.3' and 'main is f68cded Merged PR 5393: [snip PR message]
        INFO [05/01/24 12:05:45:69] End: Finding merge base between 'tags/v_0.1.3' and 'main'. (Took: 7.10ms)
        INFO [05/01/24 12:05:45:69] Begin: Finding merge base between 'tags/v_0.1.3' and 'origin/main'.
          INFO [05/01/24 12:05:45:69] Found merge base of f68cded Merged PR 5393: [snip PR message]
          INFO [05/01/24 12:05:45:69] Merge base of tags/v_0.1.3' and 'origin/main is f68cded Merged PR 5393: [snip PR message]
        INFO [05/01/24 12:05:45:69] End: Finding merge base between 'tags/v_0.1.3' and 'origin/main'. (Took: 0.33ms)
        INFO [05/01/24 12:05:45:70] Multiple source branches have been found, picking the first one (main).
This may result in incorrect commit counting.
Options were:
main, origin/main
      INFO [05/01/24 12:05:45:70] End: Finding branch source of 'tags/v_0.1.3' (Took: 17.63ms)
      INFO [05/01/24 12:05:45:70] Begin: Getting branches containing the commit 'f68cded'.
        INFO [05/01/24 12:05:45:70] Trying to find direct branches.
        INFO [05/01/24 12:05:45:70] No direct branches found, searching through all branches.
        INFO [05/01/24 12:05:45:70] Searching for commits reachable from 'main'.
        INFO [05/01/24 12:05:45:70] The branch 'main' has a matching commit.
      INFO [05/01/24 12:05:45:70] End: Getting branches containing the commit 'f68cded'. (Took: 1.06ms)
      INFO [05/01/24 12:05:45:70] Found possible parent branches: main
    INFO [05/01/24 12:05:45:70] End: Attempting to inherit branch configuration from parent branch (Took: 26.63ms)
    INFO [05/01/24 12:05:45:71] Fallback base version: 0.1.0 with commit count source a102d7409179ba5d4b5e3dd443e80f67dc5411f0
    INFO [05/01/24 12:05:45:74] Git tag 'v_0.1.3': 0.1.3 with commit count source f68cded66ebfbca621449caa2e8ead3911ca0d3c
    INFO [05/01/24 12:05:45:76] Found multiple base versions which will produce the same SemVer (0.1.3), taking oldest source for commit counting (Git tag 'v_0.1.3')
    INFO [05/01/24 12:05:45:76] Base version used: Git tag 'v_0.1.3': 0.1.3 with commit count source f68cded66ebfbca621449caa2e8ead3911ca0d3c
  INFO [05/01/24 12:05:45:76] End: Calculating base versions (Took: 88.70ms)
  INFO [05/01/24 12:05:45:76] 0 commits found between f68cded Merged PR 5393: [snip PR message] and f68cded Merged PR 5393: [snip PR message]
  INFO [05/01/24 12:05:45:76] Using branch name to calculate version tag
  INFO [05/01/24 12:05:45:76] Begin: Getting version tags from branch 'refs/heads/tags/v_0.1.3'.
  INFO [05/01/24 12:05:45:77] End: Getting version tags from branch 'refs/heads/tags/v_0.1.3'. (Took: 3.47ms)
  INFO [05/01/24 12:05:45:77] Begin: Creating dictionary
  INFO [05/01/24 12:05:45:77] End: Creating dictionary (Took: 3.24ms)
  INFO [05/01/24 12:05:45:77] Begin: Storing version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/E5BE13EBFDB188C579FDC6D9387C0F7C6B8A1675.yml
  INFO [05/01/24 12:05:45:80] End: Storing version variables to cache file /home/vsts/work/1/s/.git/gitversion_cache/E5BE13EBFDB188C579FDC6D9387C0F7C6B8A1675.yml (Took: 21.51ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants