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

Shim /v3/repos API for actions/checkout #29676

Closed
silverwind opened this issue Mar 8, 2024 · 9 comments
Closed

Shim /v3/repos API for actions/checkout #29676

silverwind opened this issue Mar 8, 2024 · 9 comments
Labels
topic/api Concerns mainly the API topic/gitea-actions related to the actions of Gitea

Comments

@silverwind
Copy link
Member

silverwind commented Mar 8, 2024

Description

Under condition !ref && !commit, actions/checkout calls out to the GitHub API:

https://github.com/actions/checkout/blob/8eb1f6a495037164bea451156472f35fdd6bafc0/src/github-api-helper.ts#L26

::group::Determining the default branch
Retrieving the default branch name
Not found.

It will fetch /api/v3/repos/[user]/[reponame] which is not available on Gitea's API. I wonder whether we should make some shims specific for this because the action it by far the most commonly action to use.

Original issue report: #29654

@silverwind silverwind added type/bug topic/gitea-actions related to the actions of Gitea and removed type/bug labels Mar 8, 2024
@silverwind silverwind changed the title Make actions/checkout fully compatible Shim v3 repos API for actions/checkout Mar 8, 2024
@silverwind silverwind added the topic/api Concerns mainly the API label Mar 8, 2024
@silverwind silverwind changed the title Shim v3 repos API for actions/checkout Shim /v3/repos API for actions/checkout Mar 8, 2024
@ChristopherHX
Copy link
Contributor

This action would also call the api if you use an docker image / system without git tool / ancient version to download a zip archive
However I never debugged this specfic case and have no idea if this also just needs a shim for /v3/repos as well to work.

@silverwind
Copy link
Member Author

This was reported in Discord, I asked the user to share more details on how they are running into this issue.

@silverwind
Copy link
Member Author

Yes, this section confirms that the affected code is only used when git is not available:

https://github.com/actions/checkout/blob/8eb1f6a495037164bea451156472f35fdd6bafc0/src/git-source-provider.ts#L74

@silverwind
Copy link
Member Author

silverwind commented Mar 8, 2024

I think we may consider just requiring git in the image. It's unfortunate that actions/checkout fails with such an confusing error message. We could just validate presence of git in act-runner to make the error reason clear.

@ChristopherHX
Copy link
Contributor

The issue mentioned in the discord is this one

on: push
jobs:
  _:
    runs-on: k8s # <--- change this to match what you use
    container: buildpack-deps:noble # <--- any image with git would trigger this
    steps:
    - uses: https://github.com/actions/checkout@v3
      with:
        repository: christopher/service-container # <--- This also trigger the /v3 path

log with the actions/runner on gitea with usable git is installed

##[group]Run https~//github.com/actions/checkout@v3
with:
  repository: christopher/service-container
  token: ***
  ssh-strict: true
  persist-credentials: true
  clean: true
  sparse-checkout-cone-mode: true
  fetch-depth: 1
  fetch-tags: false
  lfs: false
  submodules: false
  set-safe-directory: true
##[endgroup]
##[group]Run '/home/runner/k8s/index.js'
shell: /home/runner/externals/node16/bin/node {0}
##[endgroup]
Syncing repository: christopher/service-container
##[group]Getting Git version info
Working directory is '/__w/test-actions/test-actions'
[command]/usr/bin/git version
git version [2](http://rpi2server.fritz.box:3000/christopher/test-actions/actions/runs/83#jobstep-2-2).4[3](http://rpi2server.fritz.box:3000/christopher/test-actions/actions/runs/83#jobstep-2-3).0
##[endgroup]
Temporarily overriding HOME='/__w/_temp/ff9d86a2-ffe[4](http://rpi2server.fritz.box:3000/christopher/test-actions/actions/runs/83#jobstep-2-4)-4d01-b6bc-f[5](http://rpi2server.fritz.box:3000/christopher/test-actions/actions/runs/83#jobstep-2-5)5f5894[6](http://rpi2server.fritz.box:3000/christopher/test-actions/actions/runs/83#jobstep-2-6)cb3' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
[command]/usr/bin/git config --global --add safe.directory /__w/test-actions/test-actions
Deleting the contents of '/__w/test-actions/test-actions'
##[group]Initializing the repository
[command]/usr/bin/git init /__w/test-actions/test-actions
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /__w/test-actions/test-actions/.git/
[command]/usr/bin/git remote add origin http://rpi2server.fritz.box:3000/christopher/service-container
##[endgroup]
##[group]Disabling automatic garbage collection
[command]/usr/bin/git config --local gc.auto 0
##[endgroup]
##[group]Setting up auth
[command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
[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' || :"
[command]/usr/bin/git config --local --name-only --get-regexp http\.http\:\/\/rpi2server\.fritz\.box\:3000\/\.extraheader
[command]/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.http\:\/\/rpi2server\.fritz\.box\:3000\/\.extraheader' && git config --local --unset-all 'http.http://rpi2server.fritz.box:3000/.extraheader' || :"
[command]/usr/bin/git config --local http.http://rpi2server.fritz.box:3000/.extraheader AUTHORIZATION: basic ***
##[endgroup]
##[group]Determining the default branch
Retrieving the default branch name
Not found.

I think we may consider just requiring git in the image.

That's what I'm doing for my own purposes, since 2021...

@silverwind
Copy link
Member Author

The only other two API calls I see in this fallback code are here:

https://github.com/actions/checkout/blob/8eb1f6a495037164bea451156472f35fdd6bafc0/src/github-api-helper.ts#L135-L136

These go to /repos/{owner}/{repo}/tarball/{ref} and /repos/{owner}/{repo}/zipball/{ref}. I think this is unversioned API that is likely present on Gitea.

@silverwind
Copy link
Member Author

I don't think it's wise to require git after all. There may be more scenarios where it won't be there and I assume GitHub must have had good reasons for adding that fallback download via archive.

@nyanotech
Copy link

This was reported in Discord, I asked the user to share more details on how they are running into this issue.

I guess I should say on this bug; I'm the user who reported it in discord, and #29654 is my report of this.

The details are in #29654, but in short, the actions workflow that I have that runs into this is basically this example; the second repo's ref isn't plumbed in via the normal means.

Manually specifying a ref to check out in the action works around this issue.

@silverwind
Copy link
Member Author

Closing in favor of #29654.

@silverwind silverwind closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/api Concerns mainly the API topic/gitea-actions related to the actions of Gitea
Projects
None yet
Development

No branches or pull requests

3 participants