繁体   English   中英

在 Github Action 中如何引用私有 package 进行测试?

[英]In a Github Action how to reference a private package for a test?

我已经为 Github Action 编写了一个测试文件:

测试.yml

name: Test
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x, 16.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

但我的package.json使用组织私人回购。 当 Github 操作运行时失败,我得到错误:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@org/repo/
npm ERR! 404 
npm ERR! 404  '@org/repo@1.2.3' 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.

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

我的研究试图解决这个问题:

在我的 Github 操作中,我如何才能正确引用私有组织存储库,以便我的测试能够正常工作,或者我是否遗漏了一个步骤?

这个答案是正确的,现在是示例test.yml文件:

name: Test
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x, 16.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

Github 动作显示为通过:

职位

您必须使用 URL + 令牌向 CI 添加授权 - 这是通过.npmrc文件完成的。

  1. 创建令牌: npm token create --read-only

  2. 将其添加到名为 NPM_TOKEN 的 GitHub 上的秘密中

  3. 在运行npm ci之前用你的令牌创建一个本地文件:

    添加一个步骤: - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >>.npmrc

其他一切保持原样。

暂无
暂无

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

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