这个问题被设计为问答式,原因是我花了几个小时才让它运行,因为我有一些拼写错误并认为解决方案更复杂。如果我在谷歌或Stackoverflow上找到像这样的教程,我会检查拼写错误。
Git仓库设置:
- 私有仓库
A
-名称:repoA
- 子模块
B
(公共仓库)-名称:repoB
目标:
- 我想在
repository A > Github Actions
中运行gradle build
Github Action工作流程
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 Actions步骤使用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
我尝试的方法:
- 将
with: submodules: true
添加到actions/checkout@v1
中。
- uses: actions/checkout@v1
with:
submodules: true
Github Actions步骤运行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.
- 使用第三方Github Actions,例如
textbook/git-checkout-submodule-action@2.0.0
运行 textbook/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
在
actions/checkout
中添加一个个人访问令牌- 该令牌由具有对该存储库访问权限的Github用户生成
- repoA是由一家组织拥有
- 该令牌具有完整的
repo
权限
- uses: actions/checkout@v1
with:
submodules: true
token: ${{ secrets.GITHUB_REPO_TOKEN }}
运行 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.
也就是说,使用那个能够访问repoA和repoB的令牌,我甚至无法检出父级repoA。