从GH软件包中安装NPM:在本地工作,但不适用于GH操作

我已将私有软件包发布到我们组织的软件包存储库中。

根据文档,我将.npmrc文件添加到另一个项目的根目录中,其内容如下:

registry=https://npm.pkg.github.com/my-org

在我本地的〜/ .npmrc中,我的Authtoken位于npm.pkg.github.com

我将发布的软件包安装在package.json中,并在package.json中添加以下条目

"@my-org/my-package": "^1.0.0",

在本地安装时,效果很好。

通过Github actions安装时,安装失败,并显示以下错误:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/my-org/@my-org%2fmy-package - npm package "my-package" does not exist under owner "my-org"
npm ERR! 404 
npm ERR! 404  '@my-org/my-package@1.0.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

似乎“ my-org”在包的路径中使用了两次? 为什么它在本地有效,但在Github actions中无效?

最初,我的.npmrc仅是这样的(没有将组织添加到注册表URL):

registry=https://npm.pkg.github.com

在本地可以正常工作。

它也适用于github action中的所有作用域包(例如@ coogle-cloud),但不是适用于无作用域的包:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/chai
npm ERR! 404 
npm ERR! 404  'chai@4.2.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball,folder,http url,or git url.

更新: 因此,我拿起了我的个人访问令牌(在本地工作)并提交了,现在安装工作流成功了。

文档(https://help.github.com/en/github/managing-packages-with-github-packages/using-github-packages-with-github-actions)表示:“ GITHUB_TOKEN具有read:packages和write:packages范围。” 这还不够吗?

我的个人访问令牌具有delete:packages,read:packages,repo和write:packages。

caojinwan 回答:从GH软件包中安装NPM:在本地工作,但不适用于GH操作

隐藏在任意Twitter线程中的信息是GITHUB_TOKEN仅有权访问当前存储库的信息。 https://twitter.com/char_fish/status/1191442780729556993?s=21

解决方案是显式定义一个个人(sic!)访问令牌,并使用此密钥对软件包存储库进行身份验证,将其放置在存储库的秘密存储区中。

  - name: 'authenticate with GH package registry'
    run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
本文链接:https://www.f2er.com/3101973.html

大家都在问