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

tag checkout action overwrites tag with pointed-to commit #1638

Open
jwise opened this issue Mar 3, 2024 · 0 comments
Open

tag checkout action overwrites tag with pointed-to commit #1638

jwise opened this issue Mar 3, 2024 · 0 comments

Comments

@jwise
Copy link

jwise commented Mar 3, 2024

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:

// When all history is fetched, the ref we're interested in may have moved to a different
// commit (push or force push). If so, fetch again with a targeted refspec.
if (!(await refHelper.testRef(git, settings.ref, settings.commit))) {
refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
await git.fetch(refSpec, fetchOptions)
}

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!

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

No branches or pull requests

1 participant