对于从公共 GitHub 存储库引用的包,GitHub Pull 请求上的 Npm 安装失败

发布于 2025-01-17 11:29:26 字数 900 浏览 2 评论 0原文

package.json文件中,我添加了一个依赖项,它引用了我们的一个公共存储库。 package.json中的依赖关系如下:

    "ffprobe-static": "git+https://github.com/company-name/repo-name.git",

我可以在本地成功运行npm install并使用此依赖关系,但是当我按下此代码时,我们的github工作流程在我们执行的位置时npm install在以下错误中失败:

npm ERR! Warning: Permanently added the RSA host key for IP address 'x.x.x.x' to the list of known hosts.
npm ERR! [email protected]: 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.

我不了解此错误的原因,因为我们引用的存储库是公开的,当我本地安装依赖关系时,我也可以访问相同的存储库。

请注意,正在运行此代码的存储库是一个私人存储库,但是引用的存储库是公共的,但在同一组织下。

In the package.json file, I have added a dependency that is referencing one of our public repositories. The dependency in the package.json looks like below:

    "ffprobe-static": "git+https://github.com/company-name/repo-name.git",

I can successfully run npm install locally and use this dependency, but when I push this code, our GitHub workflows where we execute npm install fails with the below error:

npm ERR! Warning: Permanently added the RSA host key for IP address 'x.x.x.x' to the list of known hosts.
npm ERR! [email protected]: 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.

I don't understand the reason for this error, since the repository we are referencing is public, and also I can access the same repository when I install dependencies locally.

Note that the repository that is running this code is a private repository, but the referenced repository is public, but under the same organization.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流心雨 2025-01-24 11:29:26

我可以通过在 YAML 文件中签出后添加以下步骤来修复它。另外,在结帐步骤中将 persist-credentials 选项设置为 false。

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false
      - name: Reconfigure git to use HTTP authentication
        run: >
          git config --global url."https://github.com/".insteadOf
          ssh://[email protected]/

I was able to fix it by adding the below step after checkout in the YAML file. Also, set the persist-credentials option to false in the checkout step.

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false
      - name: Reconfigure git to use HTTP authentication
        run: >
          git config --global url."https://github.com/".insteadOf
          ssh://[email protected]/
闻呓 2025-01-24 11:29:26

您可以尝试在 GitHub 工作流程中使用配置强制使用 https URL,至少用于测试:

- name: Fix URL access
      run: echo -e '[url "https://github.com/"]\n  insteadOf = "ssh://[email protected]/"' >> ~/.gitconfig
    - name: Checkout server
      uses: actions/checkout@v2
      ...

或者(如 在这里,只是为了说明可以在哪里放置git config代替命令):

on: push
jobs:
  check-elm:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Checkout submodules
      shell: bash
      run: |
        # From https://github.com/actions/checkout/issues/116#issuecomment-583221947
        git config --global url."https://github.com/".insteadOf
          ssh://[email protected]/
        git submodule sync --recursive
        git -c "http.extraheader=Authorization: basic ${{secrets.GITHUB_ACCESS_TOKEN}}" -c protocol.version=2 submodule update --init --force --recursive --depth=1
    - uses: actions/setup-node@v1
      with:
        node-version: '8.16.0'
    - run: npm run test

You might try a config to force https URLs, at least for testing, in your GitHub workflow:

- name: Fix URL access
      run: echo -e '[url "https://github.com/"]\n  insteadOf = "ssh://[email protected]/"' >> ~/.gitconfig
    - name: Checkout server
      uses: actions/checkout@v2
      ...

Or (as in here, just to illustrate where you can put the git config insteadOf command):

on: push
jobs:
  check-elm:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Checkout submodules
      shell: bash
      run: |
        # From https://github.com/actions/checkout/issues/116#issuecomment-583221947
        git config --global url."https://github.com/".insteadOf
          ssh://[email protected]/
        git submodule sync --recursive
        git -c "http.extraheader=Authorization: basic ${{secrets.GITHUB_ACCESS_TOKEN}}" -c protocol.version=2 submodule update --init --force --recursive --depth=1
    - uses: actions/setup-node@v1
      with:
        node-version: '8.16.0'
    - run: npm run test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文