setup-node: Unable to publish to GitHub Package Registry

I use the workflow you suggest, but the npm publish action on GitHub Package Registry doesn’t work. On npmjs it works.

Workflow

name: publish

on: release

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm ci
      - run: npm test

  # works
  publish-npm:
    name: Publish NPM
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

  # doesn't work: tries to publish on https://registry.npmjs.org
  publish-gpr:
    name: Publish GitHub Packages
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          registry-url: 'https://npm.pkg.github.com'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

npm publish on npmjs works. On gpr doesn’t. Follows the GitHub Action output of the publish-gpr job.

Run actions/setup-node@v1
   with:
    registry-url: https://npm.pkg.github.com
    node-version: 10.x
in/tar xzC /home/runner/work/_temp/bc5bc42b-b229-41ac-b8a0-e554467f0c90 -f /home/runner/work/_temp/5cda4e3f-6051-4aaa-b41f-c4761c6cac12
##[add-path]/opt/hostedtoolcache/node/10.16.3/x64/bin
##[set-env name=NPM_CONFIG_USERCONFIG;]/home/runner/work/_temp/.npmrc
##[set-env name=NODE_AUTH_TOKEN;]XXXXX-XXXXX-XXXXX-XXXXX
Added matchers: 'tsc'. Problem matchers scan action output for known warning or error strings and report these inline.
##[add-matcher]/home/runner/work/_actions/actions/setup-node/v1/.github/tsc.json
Added matchers: 'eslint-stylish'. Problem matchers scan action output for known warning or error strings and report these inline.
##[add-matcher]/home/runner/work/_actions/actions/setup-node/v1/.github/eslint-stylish.json
Added matchers: 'eslint-compact'. Problem matchers scan action output for known warning or error strings and report these inline.
##[add-matcher]/home/runner/work/_actions/actions/setup-node/v1/.github/eslint-compact.json
Run npm publish
  npm publish
  shell: /bin/bash -e {0}
  env:
    NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
    NODE_AUTH_TOKEN: ***

npm notice [...]
npm notice total files:   18                                      
npm notice 
npm ERR! code E401
npm ERR! 401 Unauthorized - PUT https://registry.npmjs.org/https-localhost - You must be logged in to publish packages.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2019-09-04T13_02_57_793Z-debug.log
##[error]Process completed with exit code 1.

As you can see in Run actions/setup-node@v1 the registry-url is right, in Run npm publish is not.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 15
  • Comments: 30 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Github Package doc

Note: GitHub Package Registry only supports scoped NPM packages. Scoped packages have names with the format of @owner/name. Scoped packages always begin with an @ symbol. You may need to update the name in your package.json to use the scoped name. For example, “name”: “@codertocat/hello-world-npm”.

Regarding occurs 500 error on publishing, I have been bumped the same error on my repo for a while, but I have confirmed it resolved on my repo today.

It works well with the following workflow:

name: Publish
on:
  release:
    types:
      - created
jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 10
          registry-url: https://npm.pkg.github.com
          scope: '@okuryu'
      - name: npm publish
        run: |
          LATEST=`npm view . version`
          CURRENT=`cat package.json | jq -r .version`
          if [ "$LATEST" != "$CURRENT" ]
          then
            npm ci
            npm publish
          fi
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Also, the following settings are not required:

  • the .npmrc file is not required
  • publishConfig in the package.json file is not required
  • creating and configuring a personal token for your repo is not required

You might want to try publishing to GPR again.

@shaodahong Try this change:

diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 86194e8..17df8cc 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -10,6 +10,7 @@ jobs:
         with:
           node-version: 10
           registry-url: 'https://npm.pkg.github.com'
-      - run: npm publish --access public
+          scope: '@shaodahong'
+      - run: npm publish
         env:
           NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/package.json b/package.json
index de10102..7d0ad50 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 {
-  "name": "@dahong/actions",
+  "name": "@shaodahong/actions",
   "version": "0.0.1",
   "main": "index.js",
   "repository": "git@github.com:shaodahong/github-action.git",

Just to keep you all informed we are investigating this on both the Actions and Package Registry side of things - and although I don’t have an update that we can share yet, we are working on it! ❤️

Github Package doc

Note: GitHub Package Registry only supports scoped NPM packages. Scoped packages have names with the format of @owner/name. Scoped packages always begin with an @ symbol. You may need to update the name in your package.json to use the scoped name. For example, “name”: “@codertocat/hello-world-npm”.

If we change a package name to a scoped package name to conform to the GPR constraints, does this change our npm package name when the package gets published to the npm registry too?

Hey folks!

I found that I had to separate registry setup and registry publishing into separate steps when configuring this: https://gist.github.com/Mattamorphic/792c2f1975c7f96065b9f9fc94311218

Here’s a repository where I applied that: https://github.com/Mattamorphic/github-actions-package-registry-example

Here’s an example of my action being executed: https://github.com/Mattamorphic/github-actions-package-registry-example/commit/5d2e3234123ba83ca8841d498f6e3ebc4ddb9301/checks


name: Deploy package to GitHub package registry
on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: "Setup actions"
        uses: actions/checkout@v1
      - name: "npm/registry setup"
        uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: "@OWNER"
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: "publish package"
        uses: actions/bin/debug@master
        run: |
          npm run test 
          npm run build
          echo @OWNER:registry=https://npm.pkg.github.com/ >> .npmrc
          npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Notice that the step I have to configure the registry is an entirely separate step to when I am publishing my package. Also that I’m providing the GITHUB_TOKEN at the setup step as well as at the publishing step.

If you are still seeing a 500 error here, then please do reach out to https://github.com/support and we’ll gladly dive into this further :octocat:

@okuryu I also confirm that my previously non functional YML scripts now work fine regarding publishing to GPR with GITHUB_TOKEN