Open Molkree opened 1 year ago
UPDATE: seems just removing the fetch-tags
configuration works for me. Even with fetch-depth
> 0, it will still detect the tag when the workflow is triggered by tags.
Same problem here: https://github.com/serious-scaffold/serious-scaffold-python/actions/runs/6142805118/job/16665155663
When I run an action on a tag, I noticed that:
- uses: actions/checkout@v4
with:
fetch-tags: true
Doesn't work and results in "Error: fatal: Cannot fetch both...". When I run this however:
- uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-tags: true
Does work. This seems like a bug because the default for fetch-depth is 1 so you would expect the first version to work too.
For some reason the fetch-depth: 1
workaround does not work for me. After some painful try-and-error i reverted back to a manual tag fetching approach.
Looking at my build logs, it seems like the commit the tag is pointing to is fetched by its hash but stored under the ref of the tag. Since git sees that a tag is attached to this commit, it tries to fetch this as well and store it under the same ref. That is causing the conflict git complains about.
Right now, when i fetch the tags manually after checkout, i have to specify --force
to overwrite the existing ref. This doesn't seem to break anything, git describe
finds the tag and the working copy is intact.
any update on this issue?
also hit this on actions/cache@v3
, with: { fetch-depth: 1, fetch-tags: true }
.
any update?
did anyone find a work-around that works with actions/checkout@v4
?
also running into this with actions/checkout@v4
, with: { fetch-depth: 1, fetch-tags: true }
or with: { fetch-depth: 0, fetch-tags: true }
or with: { fetch-depth: 1 }
or with: { fetch-depth: 0 }
@oshina-gravity I worked around the issue by fetching my tag of interest manually from bash
:
- uses: actions/checkout@v3
with:
fetch-depth: 1
#-- done manually in bash below, because https://github.com/actions/checkout/issues/1467
#fetch-tags: true
- name: Setup variables -- changelog from tag annotation message
if: startsWith(github.ref, 'refs/tags/')
run: |
git fetch origin --deepen=1 +refs/tags/$TAG:refs/tags/$TAG
# ...
This has also resolved another issue with actions/checkout
for me, where fetch-tags
would somehow not fetch tag annotation messages.
I'm a bit bewildered regarding how fetch-tags
is supposed to work. I assumed that it was just a way for actions/checkout
to do the following for me:
git fetch --tags
…which is a safe operation that should never fail. However, this does not seem to be the case at all. With the only provided documentation being:
# Whether to fetch tags, even if fetch-depth > 0. # Default: false fetch-tags: ''
…what fetch-tags
is supposed to be doing is a mystery. However, what fetch-tags
actually does seems to be both wrong and unexpected since it fails spectacularly when the commit being checked out is tagged. This seems like a major design error and a bug to me. The feature should either:
get fetch --tags
as most people seem to expect that it should do already.git fetch --tags
.Until point 2 or 3 of the above is completed, I'll remove fetch-tags
and will do git fetch --tags
manually.
Hi @asbjornu, I agree with you. This is much more puzzling than it should be. Also, IMO the handling of #579 by GitHub was very unfortunate: a +43 −11
patch by @RobertWieczoreck was awaiting review for two years... :weary:
But just for sake of discussion: I can see responses that argue your points:
git fetch --tags
in bash. Literally the one-liner:
- run: git fetch --tags
So it's a somewhat silly goal to set for actions/checkout
... If the action can improve on the default behavior in whatever way, it should totally do it; expecting it to exactly replicate git fetch --tags
behavior by default pointlessly limits those improvements/optimizations.
fetch-depth: 1
+ git fetch origin --deepen=1 +refs/tags/$TAG:refs/tags/$TAG
. In a tag-triggered workflow, if all that's needed is the "latest" triggering tag — this is much faster than git fetch --tags
. Why? Because git fetch --tags
will fetch all tags in the repo, which necessarily entails (re)fetching all of the tagged commits, and their parents; it will basically re-clone the entire repo. OTOH, git fetch --depth 1 && git fetch --deepen=1 +refs/tags/$TAG:refs/tags/$TAG
will fetch only two commits: the tagged one, and its parent. Depending on repo size, this can be orders of magnitude faster; it's O(nCommits)
VS O(1)
speed.Yet again, I'm not opposing what you said, just explaining relevant nuance. I also don't find this
# Whether to fetch tags, even if fetch-depth > 0.
# Default: false
entirely satisfactory documentation.
Edit: oh, and the original Error: fatal: Cannot fetch both <sha> and refs/tags/<tag> to refs/tags/<tag>
is definitely a bug that should be fixed.
I have also faced similar issue using this flag. In may case, I am reading the tag annotation message. But it seems this flag overrides the annotation message with the first line of commit message the tag points to.
For now i am resorting to using the below option:
with:
fetch-depth: 0
ref: ${{ github.ref }}
Looking at https://github.com/actions/checkout/blob/eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871/dist/index.js#L657 it seems to me, that all fetch-tags: 1
does, is prevent setting --no-tags
, so that only tags that point into the histories being fetched are also fetched.
Getting the following error:
Error: fatal: Cannot fetch both <sha> and refs/tags/<tag> to refs/tags/<tag>
Example workflow:
Example of a failing run.
Raw log
``` 2023-09-06T20:54:11.5281780Z Requested labels: ubuntu-latest 2023-09-06T20:54:11.5282085Z Job defined at: Molkree/github_actions/.github/workflows/workflow.yml@refs/tags/V1 2023-09-06T20:54:11.5282200Z Waiting for a runner to pick up this job... 2023-09-06T20:54:12.2788574Z Job is waiting for a hosted runner to come online. 2023-09-06T20:54:15.6896729Z Job is about to start running on the hosted runner: GitHub Actions 2 (hosted) 2023-09-06T20:54:17.8444082Z Current runner version: '2.308.0' 2023-09-06T20:54:17.8473502Z ##[group]Operating System 2023-09-06T20:54:17.8474111Z Ubuntu 2023-09-06T20:54:17.8474513Z 22.04.3 2023-09-06T20:54:17.8474765Z LTS 2023-09-06T20:54:17.8475076Z ##[endgroup] 2023-09-06T20:54:17.8475431Z ##[group]Runner Image 2023-09-06T20:54:17.8475752Z Image: ubuntu-22.04 2023-09-06T20:54:17.8476128Z Version: 20230821.1.0 2023-09-06T20:54:17.8476673Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230821.1/images/linux/Ubuntu2204-Readme.md 2023-09-06T20:54:17.8477311Z Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230821.1 2023-09-06T20:54:17.8477802Z ##[endgroup] 2023-09-06T20:54:17.8478168Z ##[group]Runner Image Provisioner 2023-09-06T20:54:17.8478513Z 2.0.266.1 2023-09-06T20:54:17.8478820Z ##[endgroup] 2023-09-06T20:54:17.8480162Z ##[group]GITHUB_TOKEN Permissions 2023-09-06T20:54:17.8480834Z Actions: write 2023-09-06T20:54:17.8481218Z Checks: write 2023-09-06T20:54:17.8481797Z Contents: write 2023-09-06T20:54:17.8482190Z Deployments: write 2023-09-06T20:54:17.8482577Z Discussions: write 2023-09-06T20:54:17.8482935Z Issues: write 2023-09-06T20:54:17.8483217Z Metadata: read 2023-09-06T20:54:17.8483553Z Packages: write 2023-09-06T20:54:17.8483914Z Pages: write 2023-09-06T20:54:17.8484212Z PullRequests: write 2023-09-06T20:54:17.8484605Z RepositoryProjects: write 2023-09-06T20:54:17.8484990Z SecurityEvents: write 2023-09-06T20:54:17.8485340Z Statuses: write 2023-09-06T20:54:17.8485656Z ##[endgroup] 2023-09-06T20:54:17.8489434Z Secret source: Actions 2023-09-06T20:54:17.8489965Z Prepare workflow directory 2023-09-06T20:54:17.9244286Z Prepare all required actions 2023-09-06T20:54:17.9441016Z Getting action download info 2023-09-06T20:54:18.1502062Z Download action repository 'actions/checkout@v4' (SHA:3df4ab11eba7bda6032a0b82a6bb43b11571feac) 2023-09-06T20:54:18.6047878Z Complete job name: release 2023-09-06T20:54:18.7039155Z ##[group]Run actions/checkout@v4 2023-09-06T20:54:18.7039717Z with: 2023-09-06T20:54:18.7040031Z fetch-depth: 250 2023-09-06T20:54:18.7040298Z fetch-tags: true 2023-09-06T20:54:18.7040608Z repository: Molkree/github_actions 2023-09-06T20:54:18.7041197Z token: *** 2023-09-06T20:54:18.7041482Z ssh-strict: true 2023-09-06T20:54:18.7041770Z persist-credentials: true 2023-09-06T20:54:18.7042069Z clean: true 2023-09-06T20:54:18.7042378Z sparse-checkout-cone-mode: true 2023-09-06T20:54:18.7042696Z show-progress: true 2023-09-06T20:54:18.7042970Z lfs: false 2023-09-06T20:54:18.7043230Z submodules: false 2023-09-06T20:54:18.7043513Z set-safe-directory: true 2023-09-06T20:54:18.7043798Z ##[endgroup] 2023-09-06T20:54:19.0017138Z Syncing repository: Molkree/github_actions 2023-09-06T20:54:19.0076797Z ##[group]Getting Git version info 2023-09-06T20:54:19.0077771Z Working directory is '/home/runner/work/github_actions/github_actions' 2023-09-06T20:54:19.0079224Z [command]/usr/bin/git version 2023-09-06T20:54:19.0091807Z git version 2.41.0 2023-09-06T20:54:19.0121375Z ##[endgroup] 2023-09-06T20:54:19.0207526Z Temporarily overriding HOME='/home/runner/work/_temp/2678c0f7-1146-4df1-ba64-9dafbaaf9b22' before making global git config changes 2023-09-06T20:54:19.0208204Z Adding repository directory to the temporary git global config as a safe directory 2023-09-06T20:54:19.0208921Z [command]/usr/bin/git config --global --add safe.directory /home/runner/work/github_actions/github_actions 2023-09-06T20:54:19.0265359Z Deleting the contents of '/home/runner/work/github_actions/github_actions' 2023-09-06T20:54:19.0266187Z ##[group]Initializing the repository 2023-09-06T20:54:19.0266618Z [command]/usr/bin/git init /home/runner/work/github_actions/github_actions 2023-09-06T20:54:19.0330716Z hint: Using 'master' as the name for the initial branch. This default branch name 2023-09-06T20:54:19.0334071Z hint: is subject to change. To configure the initial branch name to use in all 2023-09-06T20:54:19.0337832Z hint: of your new repositories, which will suppress this warning, call: 2023-09-06T20:54:19.0341189Z hint: 2023-09-06T20:54:19.0344118Z hint: git config --global init.defaultBranchWhat am I doing wrong here?