Home > other >  npm install private github repo github actions
npm install private github repo github actions

Time:07-25

I have a nodejs project that uses a private git repo as one of it's dependencies. It's defined in package.json like this:

"repo name": "git https://{access_token}@github.com/{owner}/{repo name}.git#master"

My workflow file looks like this:

name: Tests

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install modules
        run: npm ci
      - name: Run tests
        run: npm test

npm ci however fails with npm ERR! remote: Repository not found.

Using npm ci on my local machine and on a clean ubuntu test machine works perfectly when I test it. I can't figure out what's causing this issue when on github actions.

I've read through many other forms but can't find any solution that works or is applicable to my situation. If you have any ideas as to what may be causing this I'd be happy to hear your leads.

CodePudding user response:

You can add this action after your checkout step and GitHub can access your private repo dependancy. But you should change your package name in package.json like below

"some_package": "git ssh://[email protected]:<Org_Name>/<Repo_Name>.git#<Branch_name>"

Make sure to add a server's private key as a secret, public key to GitHub SSH keys.

CodePudding user response:

You have to create an .npmrc file with proper authToken.

Add your authToken to your GitHub Environemnt Secrets (for example as: NPM_TOKEN) and then use to create a file using bash script for example:

- name: "Create .npmrc"
  run: |
    echo "registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc

Then you can call npm install.

  • Related