如何将Private git repo添加为另一个git repo的子模块



如何添加私有git存储库作为另一个git存储库的子模块?

在本地当我做git submodule update它工作得很好,但在github动作运行器,它失败了错误声明url未找到在结帐步骤。

的文件我已经配置工作流。

jobs:
update_submodules:
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# - name: Clone submodule
#   run: git submodule update --init --recursive
- name: Pull & update submodules recursively
run: |
git submodule update --init --recursive
git submodule update --recursive --remote

第二步失败。

您不必对submodule update init进行编码,因为它是action/checkout本身的一个选项。

例如,actions/checkoutissue 116显示:

  • 生成PAT: https://github.com/settings/tokens
  • 并添加秘密:https://github.com/<-- username -->/<-- repo -->/settings/secrets/new,给它一个唯一的名字,说MY_REPO_PAT
  • 配置动作如下:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.MY_REPO_PAT }}
submodules: recursive

然而:

在一个GitHub操作中使用PAT会明显影响其他GitHub操作。
例如,如果您有一个标记/版本控制步骤,通过标记它提交到相同的分支,默认的GITHUB_TOKEN阻止递归管道触发器。
在尝试了此处提倡使用PAT下载子模块的修复后,在我的例子中,PAT在提交标记的步骤中保持不变。这会导致管道进入递归构建,反复标记和释放.


Or (alternative), issue 287:

我有一个解决方案,不需要个人访问令牌,但保持对子repo提交的引用在一个地方(使用git子模块)

- name: clone submodule
uses: actions/checkout@v2
with:
repository: <org name>/<repo name>
path: path
ssh-key: ${{ secrets.SSH_KEY }}
persist-credentials: true
- name: checkout submodule
run: |
git submodule init
git submodule update

虽然操作检查master,但git submodule命令检查正确的提交,这避免了必须在github操作中保留ref。

关于最后一个问题(287),Matthijs Kooijman还描述了如何设置和管理Github应用程序。

和Štěpán Jákl添加:

我还意识到,您可以简单地使用签出操作来包含多个子模块部署键。
我很惊讶这里居然没有提到。

...
steps:
- uses: actions/checkout@v3
with:
ssh-key: |
${{ secrets.SSH_PRIVATE_KEY_SUBMODULE_1 }}
${{ secrets.SSH_PRIVATE_KEY_SUBMODULE_2 }}
submodules: 'recursive'
...

只需要记住键必须通过链接/注释生成到存储库,例如

ssh-keygen -t ed25519 -C "git@github.com:owner/repo.git"

然后GH检出可以将密钥连接到正确的存储库。