how to config git to use PAT token in GitHub actions checkout

Viewed 6562

I need to checkout a private repo during a GitHub Actions workflow. I am using the checkout action, and following its README:

  1. I created a service account, i.e. a separate GitHub account just for GitHub Actions workflow.
  2. I created a PAT (Personal Access Token) for the service account, with permission to access the private repo and the current workflow repo.
  3. I created a secret to store the PAT token.

Now, when I just do the following, it does not work:

- name: Checkout
  uses: actions/checkout@v2
  with:
    token: ${{secrets.MY_TOKEN}}

it seems that I did not config git properly to allow it use the token. My question is: should I or how do I configure git config to use token in the above step?

Thanks.

EDIT: The private repo is a dependency of the main repo. Both repos are Rust programs, using Cargo. So I am trying to use the same service account to checkout the main repo first. Then cargo will checkout the private repo.

EDIT 2: Sorry this is a bad question. I didn't know what I was doing. Please ignore.

1 Answers

According to the actions/checkout documentation, you need to add the repository input as well for private repositories:

It should look like the following on your workflow .yml file:

- name: Checkout
  uses: actions/checkout@v2
  with:
    path: main

- name: Checkout private repo
  uses: actions/checkout@v2
  with:
     repository: your-private/repo_name
     token: ${{ secrets.MY_TOKEN }}

You shouldn't need to configure anything else regarding git

Except if you need a specific path, in that case you need to inform it as input as well:

- name: Checkout private repo
  uses: actions/checkout@v2
  with:
     repository: your-private/repo_name
     token: ${{ secrets.MY_TOKEN }}
     path: path-to-directory
Related