Reason for this Q&A-Style question: It took me a few hours to get this to run because I had some typos and thought the solution is more complicated. If I would have found a tutorial like this on google or Stackoverflow I would have checked for typos.
Git Repository Setup:
A
- name: repoA
B
(public repository) - name: repoB
Goal:
gradle build
in repository A > Github Actions
Github Action Workflow
name: Test
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Problem:
actions/checkout@v1
step fails to access the submodule.gitmodules
[submodule "library"]
path = library
url = [email protected]:organization/repoB.git
Github Actions Step Build with Gradle
error
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
What I tried:
with: submodules: true
to actions/checkout@v1
- uses: actions/checkout@v1
with:
submodules: true
Github Actions Step Run actions/checkout@v1
error
(...)
git submodule sync
git -c http.https://github.com.extraheader="AUTHORIZATION: basic ***" submodule update --init --force
Submodule 'repoB' ([email protected]: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.
textbook/[email protected]
Run textbook/[email protected] error:
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
Add a personal access token to the actions/checkout
repo
permissions - uses: actions/checkout@v1
with:
submodules: true
token: ${{ secrets.GITHUB_REPO_TOKEN }}
Run actions/checkout@v1 error:
git submodule sync
git -c http.https://github.com.extraheader="AUTHORIZATION: basic ***" submodule update --init --force
Submodule 'repoB' ([email protected]: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.
I.e. with the that token which has access to both, repoA and repoB I was not even able to checkout the parent repoA.
Cloning a Project with SubmodulesIf you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.
Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .
Now you can use actions/checkout@v2
As https://github.com/actions/checkout#checkout-submodules said:
- 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 "[email protected]:"
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
You can use actions/checkout@v2 without additional scripting. I used this on Mac, Linux and Windows. Meanwhile v3 is available:
- uses: actions/checkout@v3
with:
submodules: true
For recursive submodules (where a submodule requires another submodule), use
- uses: actions/checkout@v3
with:
submodules: recursive
Changing the submodule URL from the SSH to the HTTPS format fixed it:
.gitmodules
[submodule "repoB"]
path = repoB
#Before:
url = [email protected]:organization/repoB.git
# After:
url = https://github.com/organization/repoB.git
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With