簡體   English   中英

無法從 travis 發布到 github 包注冊表:盡管包含 github 個人訪問令牌,但 401 未經授權

[英]Cannot publish to github package registry from travis: 401 unauthorized despite including github personal access token

我正在嘗試從 Travis CI 將包發布到 github 包注冊表。 一切似乎都很好(構建和測試成功),但是當它嘗試發布時,我收到 401 錯誤。 我已經在 travis 配置中添加了我的 github 個人訪問令牌作為安全環境.npmrc ,並且我正在使用包含 github 注冊表和訪問令牌的 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 deploy 運行時,它會出錯:

> 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 包注冊表提供身份驗證令牌。 所以整個.npmrc看起來像這樣:

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

然后我能夠將GITHUB_TOKEN環境變量設置為我的 github 個人訪問令牌(具有包讀取權限),然后我能夠運行npm install @my-org/example-pkg

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM