节点项目在 github 操作工作流程中安装 github 包

问题描述 投票:0回答:1

github文档真的让我很困惑。我应该怎么做才能在 github 操作中将 github 包中的包安装?

在github操作工作流程上,文档推荐使用

GITHUB_TOKEN
。但我不知道如何在 Node 项目中使用它
npm install

工作流程

on: push

jobs:
  install-package:
    permissions:
      packages: read
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.x
      - run: npm i

.npmrc

// MY_SCOPE is my account name.
@MY_SCOPE:registry=https://npm.pkg.github.com

错误

npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/@MY_PACKAGE - authentication token not provided

npm ERR! A complete log of this run can be found in: /home/runner/.npm/_logs/2023-11-13T04_23_29_816Z-debug-0.log
Error: Process completed with exit code 1.
github github-actions npm-install
1个回答
0
投票

我现在才明白这一点。我不确定这是否是最佳实践,但效果正确。

工作流程

on: push

jobs:
  install-package:
    permissions:
      packages: read
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      // Add the token value into .npmrc
      - run: echo -e "\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ./.npmrc
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.x
      - run: npm i
© www.soinside.com 2019 - 2024. All rights reserved.