Last active
April 18, 2024 13:19
-
-
Save doutv/54098c2c283ed8141ba961c88a2d5bb0 to your computer and use it in GitHub Desktop.
GitHub Actions Pull Private Git Submodule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone main repository | |
uses: actions/checkout@v4 | |
- name: Add SSH private keys for submodule repositories | |
uses: webfactory/ssh-agent@v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.READ_ONLY_DEPLOY_KEY }} | |
- name: Clone submodules | |
run: git submodule update --init --recursive --remote |
You can also use relative paths in the .gitmodules
url, like ../other-repo.git
You can also use relative paths in the
.gitmodules
url, like../other-repo.git
https://stackoverflow.com/a/44630028/11844720
I finally solved this problem by specifying the submodules url as a [relative path](https://git-scm.com/docs/git-submodule):
So lets say your main git repository can be reached
either via https://gitlabserver.com/my/path/main.git
or via user@gitlabserver.com:my/path/main.git
And the .gitmodules file looks like this:
[submodule "utils"]
path = libs/utils
url = https://gitlabserver.com/my/path/utils.git
That would mean that even when you check out the main application via ssh, the submodule utils would still be accessed via https.
However, you can replace the absolute path with a relative one like this:
[submodule "utils"]
path = libs/utils
url = ../utils.git
and from now on use
either git clone --recursive https://gitlabserver.com/my/path/main.git
or git clone --recursive user@gitlabserver.com:my/path/main.git
to get the whole repository structure which ever way you want. Obviously that doesn't work for cases where the relative ssh and the https paths are not the same, but at least for gitlab hosted repositories this is the case.
This is also handy if you (for whatever reason) mirror your repository structure at two different remote sites.
I think I found the cleanest solution to this so far
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check this issue for future solution: actions/checkout#287
Read ssh-agent Usage section to learn how to:
https://github.com/marketplace/actions/webfactory-ssh-agent
Also, in
.gitmodules
, change the repo url to the ssh formatgit@
: