How to Check Out Another Private Repo With a GitHub App Token
GITHUB_TOKEN cannot read a different private repo, so mint an App token scoped to include it and pass that to checkout.
Scope the installation token to the extra repositories with the repositories input, then pass the token to a second actions/checkout step targeting that repo.
Steps
- Install the App on both repos.
- Set
repositories:oncreate-github-app-tokento include the private repo. - Pass the token to
actions/checkoutwithrepository:set to the other repo.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: my-org
repositories: shared-libs
- uses: actions/checkout@v4
with:
repository: my-org/shared-libs
token: ${{ steps.app-token.outputs.token }}
path: shared-libsGotchas
- The App needs
contents: readpermission on the other repo. - Use distinct
path:values so the two checkouts do not overwrite each other.
Related guides
How to Generate a GitHub App Installation Token in a WorkflowGenerate a short-lived GitHub App installation access token inside GitHub Actions with actions/create-github-…
How to Check Out Private Submodules With a GitHub App TokenClone a repo with private Git submodules in GitHub Actions by passing a GitHub App installation token to acti…