github Actions的registry-url不生效,求解
发布于 5 年前 作者 zy445566 5234 次浏览 来自 问答

一开始推gpr老是失败并且还报:

npm ERR! 401 Unauthorized - PUT https://registry.npmjs.org/my-i18n - You must be logged in to publish packages.

可是明明用了在registry-url里面指定了registry-url:

publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: '@zy445566'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

后来根据提示在package.json里面加了

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

结果gpr成功了,npm却失败了 npm的报错变成了

npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

给我的感觉就是在执行job的时候registry-url没有生效,求大佬解答

4 回复

完整flow:

name: my-i18n build&publish

on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

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

  publish-npm:
    needs: build
    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}}

  publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: '@zy445566'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

把 url 写到packages.json 中应该没问题

@waitingsong 我不是只要推送npm仓库或gpr仓库,我是想两个一起推送。但始终只能推送成功一个,所以我觉得可能是flows写的有问题。 如果我修改package. json相当于强制指定了其中一个仓库,就不能同时推送到两个仓库上了

应该还是 beta 版缘故。

回到顶部