我正在尝试创建一个 GH Actions 作业,它将从私有(private)存储库下载两个子模块。我希望使用我已经生成的 SSH key 下载它们。
我一直在尝试这样做:
- uses: actions/checkout@v2
with:
submodules: repo_1
ssh-key: ${{ secrets.REPO_1 }}
- uses: actions/checkout@v2
with:
submodules: repo_2
ssh-key: ${{ secrets.REPO_2 }}
此代码将创建 repo_1
和 repo_2
文件夹,但将为空。
我还没有找到可能的解决方案。有谁知道如何使用单独的 SSH key 下载多个私有(private)子模块?
最佳答案
文档提到:
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
# recursively checkout submodules.
#
# When the `ssh-key` input is not provided, SSH URLs beginning with
# `git@github.com:` are converted to HTTPS.
#
# Default: false
submodules: ''
所以 submodules: repo_2
不应该是正确的。
例如,这是一个递归检查子模块(在现有存储库引用中)的工作流
# Submodules recursive
- name: Checkout submodules recursive
uses: ./
with:
ref: test-data/v2/submodule-ssh-url
path: submodules-recursive
submodules: recursive
- name: Verify submodules recursive
run: __test__/verify-submodules-recursive.sh
它将检查存储库 github.com/actions/checkout
branch test-data/v2%2Fsubmodule-ssh-url
,其中包括 .gitmodules
包含子模块的名称和 SSH URL。
回答你原来的问题:
- 将您的 .gitmodules URL 更改为
repo1:org1/repo1
repo2:org2/repo2
- 将 GIT_SSH_COMMAND 环境变量添加到
ssh -F config
,config
是一个包含以下内容的文件:
Host repo2
Hostname github.com
User git
IdentityFile key2
Host repo2
Hostname github.com
User git
IdentityFile key2
我不知道是否可以引用使用正确的 secrets.REPO_x
生成的文件,但我从结帐操作中可以看出,您不会拥有本地为多个子模块存储库指定多个键的方法。
关于具有多个私有(private)子模块的 GitHub Actions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69076098/