3

My YML so far, kept adding bits based on other stackoverflow threads + docs:

name: Node install, build and test

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Create NPMRC
        run: echo "//registry.npmjs.org/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN}}
      - name: Publish to Github Packages
        run: |
          npm config set _auth $NODE_AUTH_TOKEN
          npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN}}

In my package.json I have:

  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },

And with the above config I keep getting

E400 Bad Request
Your request could not be authenticated by the Github Pacakges service. Please ensure your access token is valid and has the appropriate scopes configured.
SebastianG
  • 8,563
  • 8
  • 47
  • 111

1 Answers1

6

You are writing the wrong content to the ~/.npmrc file.

It should be //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} but you are doing //registry.npmjs.org/:_authToken=${{ secrets.GITHUB_TOKEN }}

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I was trying to run `npm publish` with different node env variables, but never worked. Your solution did the job. thanks! – Alberto S. May 06 '21 at 13:18