I am trying to run a build for a Node.js project using GitHub Actions. As part of the npm install
, I need to install an npm module directly from a private GitHub repository (not from GPR!).
In the package.json
I have:
"dependencies": {
...
"my-module": "github:<org>/<my-module>#master",
...
},
However, when running npm install
, I get:
npm ERR! [email protected]: Permission denied (publickey). npm ERR! fatal: Could not read from remote repository.
The repository is part of my own organization, and locally (i.e. from my machine) it works. How can I make this run?
I have already tried setting the NODE_AUTH_TOKEN
environment variable, but it didn't make a difference. Although you find this suggestion quite often, it seems to only address GPR. What I would like to avoid is having to hardcode the token into the package.json
file. Any thoughts on this?
This is how I have managed to install dependencies from private GitHub repositories.
Dependencies in package.json can be added as follows. The github:
prefix is optional. Specifying the #branch
or #tag
is also optional.
"dependencies": {
...
"myrepo": "username/myrepo#master",
"myotherrepo": "github:username/myotherrepo"
},
Here is an example workflow. PAT
is a repo
scoped Personal Access Token. It is important to disable persisted credentials on actions/checkout
, otherwise they will override your PAT
. Note that the git config
change persists between steps so you only need to run it once per job.
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: git config --global url."https://${{ secrets.PAT }}@github.com/".insteadOf ssh://[email protected]/
- run: npm ci
...
From the error and the way you've included the dependency (in package.json), it seems you are not passing authentication credentials (token, ssh.
Refer to this documentation for specifics on Git URLs as Dependencies
It can be done via https and oauth or ssh.
https and oauth: create an access token that has "repo" scope and then use this syntax:
"package-name": "git+https://<github_token>:[email protected]/<user>/<repo>.git"
or
ssh: Setup ssh and then use this syntax:
"package-name": "git+ssh://[email protected]:<user>/<repo>.git"
(note the use of colon instead of slash before user)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With