node.js - 无法从 travis 发布到 github 包注册表 : 401 unauthorized despite including github personal access token

标签 node.js git github travis-ci lerna

我正在尝试从 Travis CI 将包发布到 github 包注册表。一切似乎都工作正常(构建和测试成功),但当它尝试发布时,我收到 401 错误。我已将 github 个人访问 token 添加为 travis 配置中的安全环境变量,并且使用包含 github 注册表和访问 token 的 npmrc 手动覆盖根 .npmrc,但是我仍然遇到许可问题。我该如何授予 lerna/npm 发布 github 包的权限?

这是我的.travis.yml

env:
  global:
    secure: "my encrypted GH_TOKEN value (github personal access token with package registry permissions)"
language: node_js
node_js:
  - "12"
cache:
  directories:
    - "node_modules"
before_install:
  - echo "@my-org:registry=https://npm.pkg.github.com/:_authToken=\${GH_TOKEN}" > .npmrc
install:
  - npm ci
  - npm run bootstrap
script:
  - npm run test
  - npm run build
deploy:
  provider: script
  script: "npm run publish"
  skip_cleanup: true
  on:
    node: "12"
    tags: true

当 travis 部署运行时,会出现以下错误:

> lerna publish from-git --yes --npm-tag beta

WARN deprecated --npm-tag has been renamed --dist-tag

lerna notice cli v3.20.2

lerna info ci enabled

Found 1 package to publish:

 - @my-org/example-pkg => 1.0.2-beta.8

lerna info auto-confirmed 

lerna info publish Publishing packages to npm...

lerna notice Skipping all user and access validation due to third-party registry

lerna notice Make sure you're authenticated properly ¯\_(ツ)_/¯

lerna WARN ENOLICENSE Package @my-org/example-pkg is missing a license.

lerna WARN ENOLICENSE One way to fix this is to add a LICENSE.md file to the root of this repository.

lerna WARN ENOLICENSE See https://choosealicense.com for additional guidance.

lerna WARN lifecycle Skipping root "prepublish" because it has already been called

lerna http fetch PUT 401 https://npm.pkg.github.com/:_authToken=[secure]/@my-org%2fexample-pkg 153ms

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

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! ts-utilities@1.0.0 publish: `lerna publish from-git --yes --npm-tag beta`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the ts-utilities@1.0.0 publish script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

npm ERR!     /home/travis/.npm/_logs/2020-02-25T19_46_08_862Z-debug.log

Script failed with status 1

failed to deploy

我在这里做错了什么?

最佳答案

问题最终是我的 .npmrc 文件中需要两行。一种将 org @my-org 与 github 包注册表关联:另一种为 github 包注册表提供身份验证 token 。所以整个 .npmrc 看起来像这样:

@my-org:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}

然后我可以将 GITHUB_TOKEN 环境变量设置为我的 github 个人访问 token (具有包读取权限),然后我可以运行 npm install @my-org/示例-pkg.

关于node.js - 无法从 travis 发布到 github 包注册表 : 401 unauthorized despite including github personal access token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60402265/

相关文章:

node.js - 带环回的电子邮件连接器 3

Node.js/Express 每月从 API 提取的流程

git - 从 Bazaar 迁移到 Git : fatal: Path xxx not in branch 失败

git - Teamcity:在带有通配符的标签上触发构建

node.js - gulp 找不到模块 'readable-stream/transform'

GitHub Google Cloud Build - 多个存储库

node.js - Socket.io fs.readFileSync 同时用于多个连接

javascript - 如何在 Node.js 中的变量中存储 JSON 响应?

python - 在我的 Mac 上哪里可以找到我的 git 克隆存储库?

git - 如何在 github 提交中设置用户名别名?