【问题标题】:GitHub Actions throws Git Error when npm installing private GitHub reponpm 安装私有 GitHub 存储库时,GitHub Actions 引发 Git 错误
【发布时间】:2021-11-24 10:39:55
【问题描述】:

我有一个包含一些测试工作流程的 GitHub 存储库:

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!"

不幸的是,它抛出了一个退出代码为 128 的 git 错误:

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 install 依赖项时,有一个私有 GitHub 存储库 REPONAME 需要从我的帐户安装。

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

在 ci/cd 环境中进行这项工作的最佳方法是什么?

【问题讨论】:

    标签: node.js git github npm repository


    【解决方案1】:

    您可以使用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 }}
        - ...
    

    有关此操作的更多详细信息here

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2022-08-08
      • 2019-05-05
      • 2022-11-04
      • 2022-01-03
      • 2014-06-06
      • 2020-09-04
      • 2020-10-06
      • 2014-01-18
      相关资源
      最近更新 更多