actions / checkout

Action for checking out a repo
https://github.com/features/actions
MIT License
5.87k stars 1.73k forks source link

Can't fetch with `fetch-tags` when triggered by tag #1467

Open Molkree opened 1 year ago

Molkree commented 1 year ago

Getting the following error: Error: fatal: Cannot fetch both <sha> and refs/tags/<tag> to refs/tags/<tag>

Example workflow:

name: Release

on:
  workflow_dispatch:
  # Triggers the workflow on tag events
  push:
    tags: '*'

jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 250
          fetch-tags: true

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.defaultBranch 2023-09-06T20:54:19.0346914Z hint: 2023-09-06T20:54:19.0349701Z hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and 2023-09-06T20:54:19.0352666Z hint: 'development'. The just-created branch can be renamed via this command: 2023-09-06T20:54:19.0355422Z hint: 2023-09-06T20:54:19.0358966Z hint: git branch -m 2023-09-06T20:54:19.0434933Z Initialized empty Git repository in /home/runner/work/github_actions/github_actions/.git/ 2023-09-06T20:54:19.0436097Z [command]/usr/bin/git remote add origin https://github.com/Molkree/github_actions 2023-09-06T20:54:19.0448271Z ##[endgroup] 2023-09-06T20:54:19.0449725Z ##[group]Disabling automatic garbage collection 2023-09-06T20:54:19.0474091Z [command]/usr/bin/git config --local gc.auto 0 2023-09-06T20:54:19.0529491Z ##[endgroup] 2023-09-06T20:54:19.0530029Z ##[group]Setting up auth 2023-09-06T20:54:19.0530602Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand 2023-09-06T20:54:19.0557039Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :" 2023-09-06T20:54:19.0924414Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader 2023-09-06T20:54:19.0956478Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :" 2023-09-06T20:54:19.1182729Z [command]/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic *** 2023-09-06T20:54:19.1245799Z ##[endgroup] 2023-09-06T20:54:19.1246486Z ##[group]Fetching the repository 2023-09-06T20:54:19.1256140Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=250 origin +ec23d78ecbc48f9a867575b74a5416b78213d380:refs/tags/V1 2023-09-06T20:54:19.3386207Z ##[error]fatal: Cannot fetch both ec23d78ecbc48f9a867575b74a5416b78213d380 and refs/tags/V1 to refs/tags/V1 2023-09-06T20:54:19.3401260Z The process '/usr/bin/git' failed with exit code 128 2023-09-06T20:54:19.3401907Z Waiting 19 seconds before trying again 2023-09-06T20:54:38.3455042Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=250 origin +ec23d78ecbc48f9a867575b74a5416b78213d380:refs/tags/V1 2023-09-06T20:54:38.4980618Z ##[error]fatal: Cannot fetch both ec23d78ecbc48f9a867575b74a5416b78213d380 and refs/tags/V1 to refs/tags/V1 2023-09-06T20:54:38.5018376Z The process '/usr/bin/git' failed with exit code 128 2023-09-06T20:54:38.5019247Z Waiting 16 seconds before trying again 2023-09-06T20:54:54.5093632Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules --depth=250 origin +ec23d78ecbc48f9a867575b74a5416b78213d380:refs/tags/V1 2023-09-06T20:54:54.6735953Z ##[error]fatal: Cannot fetch both ec23d78ecbc48f9a867575b74a5416b78213d380 and refs/tags/V1 to refs/tags/V1 2023-09-06T20:54:54.6833580Z ##[error]The process '/usr/bin/git' failed with exit code 128 2023-09-06T20:54:54.7213201Z Post job cleanup. 2023-09-06T20:54:54.8171576Z [command]/usr/bin/git version 2023-09-06T20:54:54.8204035Z git version 2.41.0 2023-09-06T20:54:54.8270408Z Temporarily overriding HOME='/home/runner/work/_temp/355ee677-37c5-4dd2-a63a-280e77b4a35e' before making global git config changes 2023-09-06T20:54:54.8271182Z Adding repository directory to the temporary git global config as a safe directory 2023-09-06T20:54:54.8271822Z [command]/usr/bin/git config --global --add safe.directory /home/runner/work/github_actions/github_actions 2023-09-06T20:54:54.8311274Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand 2023-09-06T20:54:54.8359349Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :" 2023-09-06T20:54:54.8627983Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader 2023-09-06T20:54:54.8648042Z http.https://github.com/.extraheader 2023-09-06T20:54:54.8659258Z [command]/usr/bin/git config --local --unset-all http.https://github.com/.extraheader 2023-09-06T20:54:54.8697155Z [command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :" 2023-09-06T20:54:54.9259704Z Cleaning up orphan processes ```

What am I doing wrong here?

huxuan commented 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

dfeinstein-coremap commented 1 year ago

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.

sodevel commented 11 months ago

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.

aghand0ur commented 6 months ago

any update on this issue?

ulidtko commented 6 months ago

also hit this on actions/cache@v3, with: { fetch-depth: 1, fetch-tags: true }.

any update?

onelshina commented 6 months ago

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 }

ulidtko commented 6 months ago

@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.

asbjornu commented 4 months ago

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:

  1. Be much better documented and warnings should be given that it doesn't work with tagged commits.
  2. Be fixed to do get fetch --tags as most people seem to expect that it should do already.
  3. Be deprecated and replaced by an option that actually does 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.

ulidtko commented 4 months ago

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:

  1. We always have the fallback of doing 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.

  1. There're indeed possible optimizations that can speed up checkout, potentially by a large margin in repos with long history and many tags. (Remember, not all but virtually all workflows start with git checkout, it's a "hot path", any savings matter). For example, consider this combination, 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.

rewathkafley commented 4 months ago

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 }}
john-funk commented 3 weeks ago

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.