2

到目前为止,我的 YML 不断添加基于其他 stackoverflow 线程 + 文档的位:

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}}

在我的 package.json 我有:

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

通过上面的配置,我不断得到

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.
4

1 回答 1

4

您正在向 ~/.npmrc 文件写入错误的内容。

应该是//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }},但你正在做//registry.npmjs.org/:_authToken=${{ secrets.GITHUB_TOKEN }}

于 2019-11-20T08:18:41.923 回答