Skip to content

Instantly share code, notes, and snippets.

@thinkjrs
Last active October 3, 2020 00:13
Show Gist options
  • Select an option

  • Save thinkjrs/9e971b76a093efa761a282f8ec550267 to your computer and use it in GitHub Desktop.

Select an option

Save thinkjrs/9e971b76a093efa761a282f8ec550267 to your computer and use it in GitHub Desktop.
Github Actions setup - Private NPM Package

Installing a private NPM package in a Github Action

Firstly, this is based on the short post here.

The problem?

You need to create an .npmrc file on the fly via your github actions .yml script.

The solution

Separate steps and echo your environment variable from NPM, set in Github (at Musicfox NPM_AUTH_TOKEN), and pre-write a fresh .npmrc.

⚠️ Steps are not in order! ⚠️

See this sample:

---
name: "Chromatic"

on: [push]

jobs:
  build-test-publish-components:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v2
        with: 
          fetch-depth: 0  # required for git history retrieval
          scope: '@musicfox'
      - name: Setup NPMrc
        run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" > .npmrc

      - name: Install source 
        run: |
          npm install
      - name: Build source
        run: |
          npm build
      - name: Run and publish chromatic tests
        uses: chromaui/action@v1
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          token: ${{ secrets.GITHUB_TOKEN }}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment