Tag is fetched but checkout complains for not existing ref
In my action, I need to checkout an external repository. It works well if I checkout branches, but it fails with tags.
This is the configuration, which references this tag :
- uses: actions/checkout@v4
with:
repository: 'geoserver/geoserver'
ref: ${{ github.ref }}
fetch-tags: 'true'
path: 'geoserver'
and this is the error:
Run actions/checkout@v4
Syncing repository: geoserver/geoserver
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/acac2333-334b-4142-adb2-0c290c9f6b17' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/geoserver-geonode-ext/geoserver-geonode-ext/geoserver
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=1 origin +refs/heads/2.24.2:refs/remotes/origin/2.24.2
Error: fatal: couldn't find remote ref refs/heads/2.24.2
The process '/usr/bin/git' failed with exit code 128
Waiting 16 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=1 origin +refs/heads/2.24.2:refs/remotes/origin/2.24.2
Error: fatal: couldn't find remote ref refs/heads/2.24.2
The process '/usr/bin/git' failed with exit code 128
Waiting 12 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=1 origin +refs/heads/2.24.2:refs/remotes/origin/2.24.2
Error: fatal: couldn't find remote ref refs/heads/2.24.2
Error: The process '/usr/bin/git' failed with exit code 128
Notice that even if I use fetch-depth > 1 the error still happens
What branch/tag is triggering the workflow? i.e. what is the content of {{ github.ref }} ?
The logs imply that it is a branch named 2.24.2.
If its refs/heads/2.24.2, you should instead have it as refs/tags/2.25.0
github.ref is going to be the fully formed ref that caused the workflow to run. If you want this to then checkout a tag, it would have to be a workflow run that triggered off a tag (such as pushing to that tag). Assuming the repository with the workflow has the same tag as geoserver/geoserver then this should be work by pushing 2.24.2 tag to the other repository. Based on the logs you provided, it looks like instead the other repository has a branch named 2.24.2 that caused the workflow to trigger. Is that the case?
You can consider using github.ref_name instead if you want to trigger off changes to a branch name that matches tags in geoserver/geoserver. actions/checkout should try both refs/heads and refs/tags:
https://github.com/actions/checkout/blob/8459bc0c7e3759cdf591f513d9f141a95fef0a8f/src/ref-helper.ts#L104-L109