If you’re installing a private GitHub repository with npm/Yarn in GitHub Actions, then you’ll need to set up a personal access token (PAT).
For example, with the following package.json
:
{
"dependencies": {
"mypackage": "https://github.com/my-username/my-private-package"
}
}
Create a personal access token (PAT) and add it as a new repository secret to your repository’s Settings > Secrets > Actions.
In the example, the secret is named
PAT
.
Add the checkout and git config steps before installing the dependencies in your workflow:
# .github/workflows/my-workflow.yml
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Configure Git
run: git config --global --add url."https://${{ secrets.PAT }}@github.com/".insteadOf "https://github.com/"
- name: Install dependencies
run: npm ci # or `yarn --frozen-lockfile`
Now you won’t get the errors during the install step:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.