Skip to content

Instantly share code, notes, and snippets.

@nandorojo
Created August 3, 2021 23:52
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save nandorojo/46b3e46de12177b9ad7e4d454310de21 to your computer and use it in GitHub Desktop.
Save nandorojo/46b3e46de12177b9ad7e4d454310de21 to your computer and use it in GitHub Desktop.
Use private NPM packages in your GitHub actions

1 NPM_TOKEN

Add an NPM_TOKEN secret on GitHub. Get your secret key from the NPM dashboard.

2 Add a step to your action

- name: Authenticate with private NPM package
  run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

A full example might look like:

name: Install cached packages
jobs:
  install-with-cache:
    name: Create new build on EAS
    runs-on: ubuntu-latest
    steps:
      - name: Setup repo
        uses: actions/checkout@v2
      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
      - name: Find yarn cache
        id: yarn-cache-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - name: Restore cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Authenticate with private NPM package
        run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
      - name: Install dependencies
        run: yarn install --frozen-lockfile --check-files 
@pavelbinar
Copy link

Thank you!

@juliodialpad
Copy link

It works, thank you!

@nandorojo
Copy link
Author

I’m glad that this niche gist helped some internet strangers haha

@jamesmhaley
Copy link

And so it rolls on. +1 @nandorojo

@ssagli
Copy link

ssagli commented Sep 23, 2022

omg don't know how thankful I am to have found this gist ✨ Thank you so much!

@nandorojo
Copy link
Author

🕺

@tiholic
Copy link

tiholic commented Nov 5, 2022

A better way using GITHUB_TOKEN directly:

actions/setup-node#49 (comment)

@Emmanuerl
Copy link

Can someone help explain what this NPM_TOKEN is and how i can get it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment