简体   繁体   中英

Install private github package from package.json on Github Actions

I'm trying to implement Github actions as a CI on my project. The problem is that I'm using private git URL on my package.json but CI gets an error because Github actions "somehow" doesn't have access to that repo which it's impossible because it's on the same user account.

Does anyone have any idea how to figure this out?

main.workflow file:

workflow "Github Actions" {
  on = "pull_request"
  resolves = ["Danger JS"]
}

action "Build" { <-------- This gets error
  uses = "actions/npm@master"
  args = "install"
}

action "Linter" {
  uses = "actions/npm@master"
  needs = "Build"
  runs = "lint"
}

action "Test" {
  needs = "Linter"
  uses = "actions/npm@master"
  args = "test"
}

action "Danger JS" {
  uses = "danger/danger-js@master"
  needs = ["Test"]
  secrets = ["DANGERJS_TOKEN"]
}

Error log:

Successfully built xxxxxxxxxxxxx
Successfully tagged gcr.io/xxxxxxxxxxxxx
Pulling image: gcr.io/github-actions-development/action-runner:latest
latest: Pulling from github-actions-development/action-runner
xxxxxxxxxxxxx: Pulling fs layer
xxxxxxxxxxxxx: Verifying Checksum
xxxxxxxxxxxxx: Download complete
xxxxxxxxxxxxx: Pull complete
Digest: sha256:xxxxxxxxxxxxx
Status: Downloaded newer image for gcr.io/github-actions-development/action-runner:latest
npm ERR! code ENOGIT
npm ERR! Error while executing:
This package is on same user account but github actions doesn't have access anyhow ------> npm ERR! undefined ls-remote -h -t ssh://git@github.com/test-user/react-test-package.git 
npm ERR! 
npm ERR! undefined
npm ERR! No git binary found in $PATH
npm ERR! 
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2018-12-04T13_03_05_291Z-debug.log

### FAILED Build

You can put an authToken, which has read rights to the registry into a .npmrc in repository where you run npm install .

Example:

//npm.pkg.github.com/:_authToken=**************
@youraccount:registry=https://npm.pkg.github.com

Now there is a dedicated action to automatically setup nodejs it's called actions/setup-node

Here an example:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
  with:
    node-version: '10.x'
    registry-url: 'https://registry.npmjs.org'
- run: npm install
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

It creates a local .npmrc file that is using the environment variable to get the authentication token:

//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
@youraccount:registry=https://registry.npmjs.org

You can use if to target any private registry, like GitHub packages for instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM