如何在“ Github操作”中克隆公共子模块

时间:2019-12-10 16:44:30

标签: github git-submodules github-actions

这个问答式问题的原因:我花了几个小时才能运行它,因为我有一些错别字,并且认为解决方案更加复杂。如果我会在Google或Stackoverflow上找到类似的教程,那么我会检查错别字。

Git存储库设置:

  • 私人存储库A -名称:repoA
  • 带有子模块B(公共存储库)-名称:repoB

目标:

  • 我想在gradle build中运行repository A > Github Actions

Github操作工作流程

name: Test
on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1

问题:

  • actions/checkout@v1步骤无法访问子模块

.gitmodules

[submodule "library"]
    path = library
    url = git@github.com:organization/repoB.git

Github操作步骤Build with Gradle错误

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':repoA:compileReleaseAidl'.
> Could not resolve all task dependencies for configuration ':repoA:releaseCompileClasspath'.
   > Could not resolve project :repoBSubmodule1.
     Required by:
         project :repoA

我尝试过的事情:


  1. with: submodules: true添加到actions/checkout@v1
    - uses: actions/checkout@v1
      with: 
        submodules: true

Github操作步骤Run actions/checkout@v1错误

(...)
git submodule sync
git -c http.https://github.com.extraheader="AUTHORIZATION: basic ***" submodule update --init --force
Submodule 'repoB' (git@github.com:organization/repoB.git) registered for path 'repoB'
Cloning into '/home/runner/work/repoA/repoA/repoB'...
Host key verification failed.
##[error]fatal: Could not read from remote repository.

  1. 使用textbook/git-checkout-submodule-action@2.0.0之类的第三方Github操作

运行教科书/git-checkout-submodule-action@2.00错误:

fatal: Not a git repository (or any parent up to mount point /github/workspace)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
##[error]Docker run failed with exit code 128

  1. actions/checkout

    添加个人访问令牌
    • 令牌是由有权访问该存储库的github用户生成的
    • 回购协议归某个组织所有
    • 令牌具有完整的repo权限
    - uses: actions/checkout@v1
      with: 
        submodules: true
        token: ${{ secrets.GITHUB_REPO_TOKEN }}

运行操作/结帐@ v1错误:

git submodule sync
git -c http.https://github.com.extraheader="AUTHORIZATION: basic ***" submodule update --init --force
Submodule 'repoB' (git@github.com:organization/repoB.git) registered for path 'repoB'
Cloning into '/home/runner/work/repoA/repoA/repoB'...
Host key verification failed.
##[error]fatal: Could not read from remote repository.

即使用那个可以访问repoA和repoB的令牌,我什至无法签出上级repoA。

2 个答案:

答案 0 :(得分:4)

现在您可以使用action / checkout @ v2

https://github.com/actions/checkout#checkout-submodules说:

- uses: actions/checkout@v2 # checkout root
- name: Checkout submodules # checkout rest
  shell: bash
  run: |
    # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
    # git config --global url."https://github.com/".insteadOf "git@github.com:"
    auth_header="$(git config --local --get http.https://github.com/.extraheader)"
    git submodule sync --recursive
    git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1

答案 1 :(得分:0)

将子模块URL从SSH更改为HTTPS格式即可对其进行修复:

.gitmodules

[submodule "repoB"]
    path = repoB
#Before:
    url = git@github.com:organization/repoB.git
# After:
    url = https://github.com/organization/repoB.git