checkout icon indicating copy to clipboard operation
checkout copied to clipboard

tag checkout action overwrites tag with pointed-to commit

Open jwise opened this issue 1 year ago • 1 comments

I have an action that does some stuff that reads the output of git tag -l --format=%(contents) to generate a version file.

On my laptop, I get the tag message if I do something like:

git commit -a -m 'Commit message!'
git tag -a -m 'Tag message!' mytags/v1.0
git tag -l mytags/v1.0 '--format=%(contents)'

But if I do that very same git tag command in CI in a push action that is

 on:
  push:
    branches: [ "master" ]
    tags: [ "mytags/*" ]

then the git tag command returns the commit message, instead!

After an hour of hunting, I tracked it down to this logic: https://github.com/actions/checkout/blob/b32f140b0c872d58512e0a66172253c302617b90/src/git-source-provider.ts#L177-L182

Roughly, what's happening here is that CI first does:

/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*

And then it immediately after does this:

/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules origin +[the pointed to tag commit]:refs/tags/mytags/v1.0

as a result of the above logic. But this is wrong: it should not fetch the pointed to tag commit! It should fetch the tag object itself!

jwise avatar Mar 03 '24 08:03 jwise

I got the same issue, and agree that this behavior is wrong. it is possible to fix it by passing ref: ${{ github.ref }} to the action.

rafaelmartins avatar May 20 '24 03:05 rafaelmartins

I'm sorting my tags by taggerdate. This doesn't work since github action replaces the tag (afaiu). Thanks for the workaround!

NickeZ avatar Aug 12 '25 10:08 NickeZ