在Github操作中,如何引用私有包进行测试? [英] In a Github Action how to reference a private package for a test?
本文介绍了在Github操作中,如何引用私有包进行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为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: 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.
我的研究试图解决这个问题:
- Package is not publishing to npm (not in the npm registry)
- Getting 404 when attempting to publish new package to NPM
- Installing npm package fails with 404
- 404 error while publishing npm package -
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/
在我的Github操作中,我如何正确引用私人组织存储库以使我的测试正常工作,或者我是否遗漏了某个步骤?
推荐答案
您必须使用url+令牌向配置项添加授权-这是通过.npmrc
文件完成的。
创建令牌:
npm token create --read-only
将其添加到名为NPM_TOKEN的GitHub上的机密
在运行
npm ci
之前使用您的令牌创建本地文件:添加步骤:
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
其他所有内容保持不变。
这篇关于在Github操作中,如何引用私有包进行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文