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

Github actions result is inconsistent with local #2852

Closed
trondhindenes-nomono opened this issue Sep 21, 2021 · 3 comments · Fixed by #3033
Closed

Github actions result is inconsistent with local #2852

trondhindenes-nomono opened this issue Sep 21, 2021 · 3 comments · Fixed by #3033
Labels
Milestone

Comments

@trondhindenes-nomono
Copy link

trondhindenes-nomono commented Sep 21, 2021

Describe the bug
We're seeing inconsistencies between local version calculation and in github actions. Here's some info:
gitversion config file:

---
mode: Mainline

Relevant parts of github actions workflow:

---
name: build
on:
  push:
jobs:
  calculate-version:
    runs-on: ubuntu-latest
    outputs: 
      semVer: ${{ steps.gitversion.outputs.semver }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Install GitVersion
      uses: gittools/actions/gitversion/setup@v0.9.7
      with:
        versionSpec: '5.x'

    - name: Determine Version
      id: gitversion_initial
      uses: gittools/actions/gitversion/execute@v0.9.7
      with:
        useConfigFile: true

Expected Behavior

running github locally and in github actions should produce the same results.

Actual Behavior

I am unable to make gitversion running in github actions actually reflect tags. As long as I just keep using gitversion's auto-incrementing functionality, everything's fine. However, in some cases we want to explicitly set a semver and that's when problems occur.
Here's what we're seeing:

  • running gitversion the calculated version is always the expected one, so that's good
  • when github actions trigger in the context of a tag instead of a commit, GitVersion will generate a semver looking like this:
    "SemVer": "2.6.1-tags-2-6-0.1". I have tried configuring my actions so that they only trigger on commit branches and not tags, but that causes GitVersion to disregard any tagging I've done and just continue it's auto-incrementing.
  • I saw some comment in another repo about running gitversion with the /nonormalize flag but that just caused it to crash.
  • All in all, we're unable to make gitversion reliably set a "main" branch to the value of a tag no matter what we're doing
  • I have used gitversion before, albeit not in github actions, and I have not encountered this problem before. I don't know if there's something weird with how github actions work. I would assume that being able to check out a commit even when actions trigger on a tag would help, but I have no idea if that's possible.

So I guess I'm looking for some guidance here, it feels like what we're trying to achieve is about the simplest possible use case for GitVersion, but we can't seem to be able to get it to produce a reliable version. Any pointers deeply appreciated.

Log file from gitversion in GH actions if its of any interest:

Click to expand!
Command: dotnet-gitversion /home/runner/work/gitversion-testing-ground/gitversion-testing-ground /output json /output buildserver /config GitVersion.yml
/opt/hostedtoolcache/GitVersion.Tool/5.7.0/x64/dotnet-gitversion /home/runner/work/gitversion-testing-ground/gitversion-testing-ground /output json /output buildserver /config GitVersion.yml
INFO [09/21/21 12:27:49:29] Working directory: /home/runner/work/gitversion-testing-ground/gitversion-testing-ground
INFO [09/21/21 12:27:49:31] Branch from build environment: refs/tags/2.6.0
INFO [09/21/21 12:27:49:31] Project root is: /home/runner/work/gitversion-testing-ground/gitversion-testing-ground/
INFO [09/21/21 12:27:49:31] DotGit directory is: /home/runner/work/gitversion-testing-ground/gitversion-testing-ground/.git
INFO [09/21/21 12:27:49:31] Begin: Normalizing git directory for branch 'refs/tags/2.6.0'
  INFO [09/21/21 12:27:49:34] One remote found (origin -> 'https://github.com/nomonosound/gitversion-testing-ground').
  INFO [09/21/21 12:27:49:34] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [09/21/21 12:27:49:35] Creating local branch tags/2.6.0 pointing at 2595c5c
  INFO [09/21/21 12:27:49:37] Creating local branch from remote tracking 'refs/remotes/origin/NEB-STUFF'.
  INFO [09/21/21 12:27:49:38] Creating local branch from remote tracking 'refs/remotes/origin/NEB-wakkawakka'.
  INFO [09/21/21 12:27:49:38] Creating local branch from remote tracking 'refs/remotes/origin/main'.
  INFO [09/21/21 12:27:49:38] Creating local branch from remote tracking 'refs/remotes/origin/what'.
  INFO [09/21/21 12:27:49:39] HEAD points at branch 'refs/heads/tags/2.6.0'.
  INFO [09/21/21 12:27:49:39] End: Normalizing git directory for branch 'refs/tags/2.6.0' (Took: 85.91ms)
  INFO [09/21/21 12:27:49:41] Begin: Loading version variables from disk cache
    INFO [09/21/21 12:27:49:41] Cache file /home/runner/work/gitversion-testing-ground/gitversion-testing-ground/.git/gitversion_cache/2577ECA82A19A27FD1BC34F712AE11A608E12ADC.yml not found.
  INFO [09/21/21 12:27:49:41] End: Loading version variables from disk cache (Took: 0.76ms)
  INFO [09/21/21 12:27:49:49] Using latest commit on specified branch
  INFO [09/21/21 12:27:49:49] No branch configuration found for branch tags/2.6.0, falling back to default configuration
  INFO [09/21/21 12:27:49:50] Begin: Attempting to inherit branch configuration from parent branch
    INFO [09/21/21 12:27:49:50] Begin: Finding branch source of 'tags/2.6.0'
      INFO [09/21/21 12:27:49:51] Begin: Finding merge base between 'tags/2.6.0' and 'main'.
        INFO [09/21/21 12:27:49:52] Found merge base of 2595c5c what
        INFO [09/21/21 12:27:49:53] Merge base of tags/2.6.0' and 'main is 2595c5c what
      INFO [09/21/21 12:27:49:53] End: Finding merge base between 'tags/2.6.0' and 'main'. (Took: 15.49ms)
      INFO [09/21/21 12:27:49:53] Begin: Finding merge base between 'tags/2.6.0' and 'origin/main'.
        INFO [09/21/21 12:27:49:53] Found merge base of 2595c5c what
        INFO [09/21/21 12:27:49:53] Merge base of tags/2.6.0' and 'origin/main is 2595c5c what
      INFO [09/21/21 12:27:49:53] End: Finding merge base between 'tags/2.6.0' and 'origin/main'. (Took: 0.73ms)
      INFO [09/21/21 12:27:49:53] Multiple source branches have been found, picking the first one (main).
This may result in incorrect commit counting.
Options were:
main, origin/main
    INFO [09/21/21 12:27:49:53] End: Finding branch source of 'tags/2.6.0' (Took: 29.82ms)
    INFO [09/21/21 12:27:49:54] Begin: Getting branches containing the commit '2595c5c'.
      INFO [09/21/21 12:27:49:54] Trying to find direct branches.
      INFO [09/21/21 12:27:49:54] No direct branches found, searching through all branches.
      INFO [09/21/21 12:27:49:54] Searching for commits reachable from 'main'.
      INFO [09/21/21 12:27:49:54] The branch 'main' has a matching commit.
      INFO [09/21/21 12:27:49:54] Searching for commits reachable from 'origin/main'.
  "PreReleaseLabelWithDash": "-tags-2-6-0",
  "PreReleaseNumber": 1,
  "WeightedPreReleaseNumber": 1,
  "BuildMetaData": null,
  "BuildMetaDataPadded": "",
  "FullBuildMetaData": "Branch.tags-2.6.0.Sha.2595c5c47ff1671252b44e7d6ea83e9e4e5979d2",
  "MajorMinorPatch": "2.6.1",
  "SemVer": "2.6.1-tags-2-6-0.1",
  "LegacySemVer": "2.6.1-tags-2-6-0-1",
  "LegacySemVerPadded": "2.6.1-tags-2-6-0-0001",
  "AssemblySemVer": "2.6.1.0",
  "AssemblySemFileVer": "2.6.1.0",
  "FullSemVer": "2.6.1-tags-2-6-0.1",
  "InformationalVersion": "2.6.1-tags-2-6-0.1+Branch.tags-2.6.0.Sha.2595c5c47ff1671252b44e7d6ea83e9e4e5979d2",
  "BranchName": "tags/2.6.0",
  "EscapedBranchName": "tags-2-6-0",
  "Sha": "2595c5c47ff1671252b44e7d6ea83e9e4e5979d2",
  "ShortSha": "2595c5c",
  "NuGetVersionV2": "2.6.1-tags-2-6-0-0001",
  "NuGetVersion": "2.6.1-tags-2-6-0-0001",
  "NuGetPreReleaseTagV2": "tags-2-6-0-0001",
  "NuGetPreReleaseTag": "tags-2-6-0-0001",
  "VersionSourceSha": "796fe906285fd2e3c97647fe6fc00e65771a59c8",
  "CommitsSinceVersionSource": 1,
  "CommitsSinceVersionSourcePadded": "0001",
  "UncommittedChanges": 0,
  "CommitDate": "2021-09-21"
}
  INFO [09/21/21 12:27:49:78] Done writing 
@trondhindenes-nomono
Copy link
Author

Suspecting this is related: actions/checkout#6
I'm seeing the "detached head" issue for my github actions when theyre triggered on a tag.

@asbjornu
Copy link
Member

This is a duplicate of #2838, no?

@github-actions
Copy link

🎉 This issue has been resolved in version 5.10.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants