繁体   English   中英

无法使用 Github Actions 从 Github Package Registry 安装公共 NPM 包

[英]Unable to install public NPM-package from Github Package Registry using Github Actions

Github 包注册表中有一个公共 NPM 包,我正在尝试使用 Github Actions 安装。

我在我的package.json旁边添加了一个.npmrc文件,其中包含@instacart:registry=https://npm.pkg.github.com

我已将包添加到我的 package.json 中的依赖项;

  "dependencies": {
    "@instacart/radium": "^0.26.6"
  }

我的 Github Actions 工作流程如下;

name: Install

on: push

jobs:
  install:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - run: npm install

我可以在本地运行npm install没有任何问题,但是 Github Actions 工作流程失败;

> Run npm install
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-08-05T09_29_15_323Z-debug-0.log
Error: Process completed with exit code 1.

为什么会出现此错误? 为什么它在本地工作正常,但在 Github Actions 工作流程中却不行? 为什么在包公开时要求登录凭据?

任何帮助深表感谢:)

从 GitHub npm 注册表下载和安装公共包需要具有read:packages scope 的个人访问令牌。 有关详细信息,请参阅文档

您需要在步骤环境中设置GITHUB_ENVGITHUB_TOKEN密码由 GitHub 自动填充):

jobs:
  install:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install dependencies
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: npm install

并且您还需要在包设置中授予对您的存储库的读取权限:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM