我為 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 Action 運行時它失敗并且我得到錯誤:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@org/repo/
npm ERR! 404
npm ERR! 404 '@org/[email protected]' 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.
我的研究試圖解決這個問題:
uj5u.com熱心網友回復:
您必須使用 URL 令牌在 CI 上添加授權 - 它是通過
.npmrc檔案完成的。創建令牌:
npm token create --read-only將其添加到 GitHub 上名為 NPM_TOKEN 的機密
在運行之前
npm ci使用您的令牌創建本地檔案:添加一個步驟:
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
其他一切都保持原樣。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/424111.html標籤:节点.js 单元测试 测试 yaml github-动作
上一篇:如何在使用`@WebMvcTest`和`@WithMockUser`注釋的測驗中測驗基于注釋的角色特定安全性
下一篇:如何在R中測驗無限回圈錯誤
