question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Tag checkout on GitHub Actions generates unexpected branch

See original GitHub issue

We have a GitHub Action that triggers on tag push. When it runs, GitVersion generates a version like this: 1.3.0-tags-1-2-1.1+6. The 1.2.1 tag is defined on the tip of the release-1.2 branch.

When I run GitVersion locally, it generates the expected version 1.2.1. When I configure my local environment to replicate the GitHub Actions environment, I do get the same incorrect version number.

Expected Behavior

When checking out a tag in GitHub actions that relates to a version number, that version number should be generated.

> git branch
* (HEAD detached at 1.2.1)

> dotnet-gitversion
{
  // ...
  "SemVer": "1.2.1"
  // ...
}

Actual Behavior

Normalization and checking out the GITHUB_REF as a branch is causing an unexpected branch to be created and checked out and that is giving us an incorrect version number.

> git branch
* (HEAD detached at 1.2.1)

> SET GITHUB_ACTIONS=true

> SET GITHUB_REF=refs/tags/1.2.1

> dotnet-gitversion
{
  // ...
  "SemVer": "1.3.0-tags-1-2-1.1"
  // ...
}

> git branch
  master
  release-1.0
  release-1.2
  release-1.3
* tags/1.2.1

Possible Fix

The GITHUB_REF environment variable is set to the tag ref (i.e. refs/tags/1.2.1) but this gets treated like a branch name. Ultimately this ref gets mangled into a canonical name like this refs/heads/tags/1.2.1, and turned into a branch named tags/1.2.1. This branch name is used in the SemVer version.

Steps to Reproduce

NOTE: The repo experiencing this issue is this one.

This is the cmd script that I have used to reproduce this locally

@REM Pretending to be GitHub Actions
set GITHUB_ACTIONS=true
set GITHUB_REF=refs/tags/1.2.1

@REM Simulate actions/checkout@v2.3.4 with fetch-depth 0
git init .
git remote add origin https://github.com/Particular/NServiceBus.AzureFunctions.InProcess.ServiceBus
git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
git checkout --progress --force refs/tags/1.2.1

@REM Build
dotnet build src --configuration Release

Context

Your Environment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeminutillocommented, Sep 8, 2021

I did a little more digging and I think I can narrow down the cause. When normalization puts us on a tags/... branch, we don’t have a matching branch configuration, so it creates the default one and inherits from main. Our main config tracks release branches. That means, even though our tag is on a release branch, it gets applied on top of all of the other release branches and then the wrong one is selected.

I will try and put together a minimal test to prove that this is what is happening.

If this is what it is, we may be able to keep normalization by having an explicit branch configuration for tags/....

0reactions
ausarbcommented, Jan 25, 2023

This appears to have been broken sometime between 5.10.0 and 5.12.0. I’ve had to lock in GitVersion to 5.10.0 to keep this fix.

- name: Install GitVersion
  uses: gittools/actions/gitversion/setup@v0.9.15
  with:
    # v5.10.0 of GitVersion has a fix for incorrect versions when building tags. See https://github.com/GitTools/GitVersion/issues/2838
    # It appears that the fix then had a regression in a later version, so locking in 5.10.0.  See https://github.com/GitTools/GitVersion/issues/3351#issuecomment-1403657689
    versionSpec: '5.10.0' 
Read more comments on GitHub >

github_iconTop Results From Across the Web

GitVersionTask fails when building from a tag · Issue #2301
Describe the bug I'm using GitHub actions to create a new build ... [Bug] Tag checkout on GitHub Actions generates unexpected branch #2838....
Read more >
v3 `on: [pull_request]` doesn't actually check out branch, it ...
This issue isn't resolved on v3. It's very unexpected that instead of checking out the actual code I'm working on in the PR,...
Read more >
RFC: `fetch-depth: 1` and not cloning tags are dangerous ...
This happens because by default, the https://github.com/actions/checkout will only fetch the git repository with --depth=1 and will not fetch ...
Read more >
[Bug] `track-merge-changes` produces unexpected result ...
Describe the bug It appears that track-merge-changes does not work when combining hotfix and support branches. I have the following test ...
Read more >
repository not found · Issue #254 · actions/checkout
It's a private repository I don't know if that can help debug the issue. Workflow stack. /usr/bin/git -c protocol.version=2 fetch --no-tags ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found