Home > Enterprise >  how to access a private npm package via github actions?
how to access a private npm package via github actions?

Time:07-15

I think this is a pretty straightforward question. Still, I'm finding lots of different resources suggesting going down different paths, installing different things, and generally speaking, so far everything seems all over the place.

In my case, I made a private package on npm. I'm trying to do a basic on push to main > run ci and build github action. However, I have my own custom private npm package, part of an org I made on npm. When the pipeline triggers I get the following response:

enter image description here

The current node.js.yml file looks like so:

name: Node.js CI

env:
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

on:
  push:
    branches: ['main']
  pull_request:
    branches: ['main']

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - run: echo "Running pipeline."
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

There's not enough information in it yet, other than a read-only key provide (per npm docs), but I don't know if that's a step in the right direction or if I need to do something entirely different. As I said, I'm not too familiar with this space and any help would be appreciated.

CodePudding user response:

Turns out I needed to add an .npmrc file, with NPM_TOKEN as a github secret.

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

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 "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
    echo "@raycast:registry=https://npm.pkg.github.com" >> .npmrc

Then you can call npm install.

  • Related