簡體   English   中英

GitHub 操作引發 Git npm 安裝私有 GitHub 回購時出錯

[英]GitHub Actions throws Git Error when npm installing private GitHub repo

我有一個帶有一些測試工作流程的 GitHub Repo:

name: Tests the App

on:
  push:
    branches: [main]

jobs:
  test:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [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 }}
        cache: "npm"
    - run: echo "Testing App."
    - run: npm install
    - run: echo "Using ESLint."
    - run: npm run lint
    - run: echo "Testing App."
    - run: npm run test
    - run: echo "Test completed!"

不幸的是,它拋出一個 git 錯誤,退出代碼為 128:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/MYNAME/REPONAME.git
npm ERR! Warning: Permanently added the RSA host key for IP address 'SOMEIPADDR' to the list of known hosts.
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
[…]
Error: Process completed with exit code 128.

當它嘗試 npm 安裝依賴項時,有一個私有的 GitHub Repo REPONAME需要從我的帳戶安裝。

"dependencies": {
   "pckgname": "git+ssh://git@github.com:MYNAME/REPONAME.git#main"
}

在 ci/cd 環境中進行這項工作的最佳方法是什么?

您可以使用webfactory/ssh-agent@v0.5.3 您要做的第一件事是在REPONAME.git存儲庫中創建一個 SSH 密鑰對(最好專用於 Github 操作),然后將私鑰作為秘密放入 Github 操作中,對於此示例,我們將其稱為SSH_PRIVATE_KEY ,然后簡單地像這樣更新您的工作流程:

 steps:
    - uses: actions/checkout@v2
    - uses: webfactory/ssh-agent@v0.5.3
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
    - ...

有關此操作的更多詳細信息,請點擊此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM