ruby - 如何在 github 操作中捆绑安装私有 gem
问题描述
我想priv_gem_a
通过 github 操作在 gem 上运行 rspec(调用它)。
priv_gem_a
取决于私人回购中的另一个宝石(称之为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.
我认为这与跑步者无法访问同一组织中的不同私人仓库有关。
所以我尝试将环境变量添加到我的工作流文件中,包括GITHUB_TOKEN
s,但这不起作用:
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
解决方案
我相当确定GITHUB_TOKEN
存储库中的默认机密仅适用于该存储库。您不能使用它来访问其他存储库。
尝试改用repo
作用域令牌。在https://github.com/settings/tokens创建一个,然后将其作为机密添加到您的工作流运行的存储库中。它将位于https://github.com/[username]/[repo]/settings /秘密
在您的工作流程中使用该密钥,而不是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 }}
此外,我认为您需要更改对私有 gem 的引用,以便它使用 HTTPS。您现在引用它的方式意味着它将尝试使用 SSH 密钥而不是BUNDLE_GITHUB__COM
.
gem 'my_private_repo', git: 'https://github.com/username/my_private_repo.git'
推荐阅读
- vue.js - Nuxt 布局和获取静态内容
- elasticsearch - Elasticsearch:双重嵌套对象上的术语聚合
- powershell - Powershell ISE 无法识别脚本中的更改
- javascript - ReferenceError:变量未定义 - Node.js
- javascript - 为什么我不能用 javascript 提交我的表单
- cmake - 如何让 cmake4eclipse 实际运行 CMake?
- c++ - 通过在 C++ 中实现类似“map”函数的 python 问题:调用类成员函数
- r - 如何测试数据以适应 Poisson 分布与 goodfit?
- css - CSS - 试图复制文本阴影
- python - 在python中将列表作为参数传递时出现未定义的错误