Cloning a private repo in Github Actions

Viewed 3721

I am trying to clone another private repo in Github actions. I have set SECRET_USER and SECRET_PASSWORD in the secrets of the repo I'm running the actions on. In actions I'm running the command

git clone https://$SECRET_USER:$SECRET_PASSWORD@github.com/other-organization/other-repo.git

but getting the error

Cloning into 'other-repo'...
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/other-organization/other-repo.git/'
##[error]Process completed with exit code 128.

in Github Actions although I've verified that the user can access https://github.com/other-organization/other-repo (which is obviously not the real URL of the internal repo).

2 Answers

I added a git configuration step to my go.yml that did the trick:

- name: Configure git
  env:
    TOKEN: ${{ secrets.ACCESS_TOKEN }}
  run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

where ACCESS_TOKEN is a personal access token I added instead of the username/password combo because the private repo I was trying to access required an SSO enabled token to access it instead of the username/password combination. This was, unfortunately, not obvious from the error message and required talking to people to learn this information.

You can use git-credential-store to save your credentials in file, so then git can use it if needed. There is no need to modify urls in (my case) Podfile/specfile.

git config --global credential.helper store
echo "https://$SECRET_USER:$SECRET_PASSWORD@github.com" > ~/.git-credentials

I have mixed feelings about saving such data in plaintext file, but on CI/CD machines imo it'd fine. I use it here.

Related