gpt4 book ai didi

ruby - 如何在 github 操作中捆绑安装私有(private) gem

转载 作者:数据小太阳 更新时间:2023-10-29 07:06:59 25 4
gpt4 key购买 nike

我想通过 github 操作在 gem 上运行 rspec(称之为 priv_gem_a)。

priv_gem_a 依赖于私有(private)存储库中的另一个 gem(称之为 priv_gem_b)。但是,由于权限无效,我无法捆绑安装 priv_gem_b

错误:

Fetching gem metadata from https://rubygems.org/..........
Fetching git@github.com:myorg/priv_gem_b
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Host key verification failed.
Retrying `git clone 'git@github.com:myorg/priv_gem_b' "/opt/hostedtoolcache/Ruby/2.6.3/x64/lib/ruby/gems/2.6.0/cache/bundler/git/priv_gem_b-886cdb130fe04681e92ab5365f7a1c690be8e62b" --bare --no-hardlinks --quiet` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git@github.com:myorg/priv_gem_b' "/opt/hostedtoolcache/Ruby/2.6.3/x64/lib/ruby/gems/2.6.0/cache/bundler/git/priv_gem_b-886cdb130fe04681e92ab5365f7a1c690be8e62b" --bare --no-hardlinks --quiet` in directory /home/runner/work/priv_gem_a/priv_gem_a has failed.

我认为这与运行者无法访问同一组织中的不同私有(private)存储库有关。

所以我尝试将环境变量添加到我的工作流文件中,包括 GITHUB_TOKEN,但这不起作用:

name: Test Code

on:
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Install dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUNDLE_GITHUB__COM: ${{ secrets.GITHUB_TOKEN }}:x-oauth-basic
run: |
gem install bundler
gem update bundler
bundle install --without development --jobs 4 --retry 3
- name: Test with RSpec
run: |
bundle exec rspec

只是 Gemfile 中关于此的一个片段:

gem 'priv_gem_b', '>= 7.0.1', '< 8', git: 'git@github.com:my_org/priv_gem_b', branch: :master

最佳答案

我相当确定存储库中的默认 secret GITHUB_TOKEN 仅限于该存储库。您不能使用它来访问其他存储库。

请尝试使用 repo 作用域 token 。在 https://github.com/settings/tokens 创建一个然后将其作为 secret 添加到您的工作流程运行的存储库中。它将在 https://github.com/[username]/[repo]/settings/secrets

在您的工作流程中使用该 secret 而不是 GITHUB_TOKEN

BUNDLE_GITHUB__COM: ${{ secrets.REPO_SCOPED_TOKEN }}:x-oauth-basic

或者,使用我认为更可取的x-access-token 方法。

BUNDLE_GITHUB__COM: x-access-token:${{ secrets.REPO_SCOPED_TOKEN }}

此外,我认为您需要更改对私有(private) gem 的引用,以便它使用 HTTPS。您现在引用它的方式意味着它将尝试使用 SSH key 而不是 BUNDLE_GITHUB__COM 中定义的 token 。

gem 'my_private_repo', git: 'https://github.com/username/my_private_repo.git'

关于ruby - 如何在 github 操作中捆绑安装私有(private) gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57886790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com