private submodule checkout fails @v2
I've private git submodule, which contains our shared i18n resouces, with same organization owner as my main repo
I've configured git submodule in main repository as
$ cat .gitmodules
[submodule "xxx-i18n"]
path = xxx-i18n
url = ../xxx-i18n
branch = master
Then I added this one from README to my github action workflow.
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
shell: bash
run: |
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
I expected this to work.
Instead I got
Checkout submodules
2s
##[error]Process completed with exit code 1.
Run auth_header="$(git config --local --get http.https://github.com/.extraheader)"
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
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
Submodule 'xxx-i18n' (https://github.com/myprivateorg/xxx-i18n) registered for path 'xxx-i18n'
Cloning into '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n'...
remote: Repository not found.
fatal: repository 'https://github.com/myprivateorg/xxx-i18n/' not found
fatal: clone of 'https://github.com/myprivateorg/xxx-i18n' into submodule path '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n' failed
Failed to clone 'xxx-i18n'. Retry scheduled
Cloning into '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n'...
remote: Repository not found.
fatal: repository 'https://github.com/myprivateorg/xxx-i18n/' not found
fatal: clone of 'https://github.com/myprivateorg/xxx-i18n' into submodule path '/home/runner/work/my-main-repo/my-main-repo/xxx-i18n' failed
Failed to clone 'xxx-i18n' a second time, aborting
##[error]Process completed with exit code 1.
Sub-modules support was removed in v2, I'm not sure why though
https://github.com/actions/checkout/releases/tag/v2.0.0
Sub-modules support was removed in v2, I'm not sure why though
I understood that it refers to another syntax with: submodules as the README I linked gives this new syntax I used.
I also need to have sub-module support. When I use v2, there's no .git directory so I cannot perform any commands like checking out sub-modules. For now I'm using v1 to continue my development.
I have the exact same issue but I just made it work using the Checkout multiple repos (private) example
- name: Checkout submodule
uses: actions/[email protected]
with:
token: '${{ secrets.GITHUB_PAT }}'
repository: myOrg/myRepo
path: path/to/submodule
ref: 'master'
This is working just as a workaround and might not be practical for a project with a lot of submodules, but I hope it helps until #72 is resolved
@rodrigorn It works for some use cases. Even with a single submodule, it can become inconsistent when the master branch myOrg/myRepo adds commits which are not tracked by the main repo.
This is actually blocking us from using GitHub actions. I hope it can be prioritized..
@tvainika the default token embedded in the main repo does not have access to fetch other private repositories. Instead if you supply token: ${{ secrets.MY_GITHUB_PAT }} then it should work.
@neutrinog no .git folder indicates git 2.18 or higher is not in your PATH. I updated the readme earlier today to make that more clear.
I have the exact same issue but I just made it work using the Checkout multiple repos (private) example
- name: Checkout submodule uses: actions/[email protected] with: token: '${{ secrets.GITHUB_PAT }}' repository: myOrg/myRepo path: path/to/submodule ref: 'master'This is working just as a workaround and might not be practical for a project with a lot of submodules, but I hope it helps until #72 is resolved
@ericsciplec @rodrigorn is there a better alternative? I would like to avoid maintaining submodule hashes/branches in two different places. This is very error prone..
I'm having the same issue, came here from the readme where it has a section on "Checkout Submodules" that does not work at all for me (I can't checkout any submodule, public or private).
@ericsciplec @rodrigorn is there a better alternative? I would like to avoid maintaining submodule hashes/branches in two different places. This is very error prone..
I agree completely but haven't found any better solution yet
FYI this is what I have been using:
- name: Checkout submodule
run: |
git config --file=.gitmodules submodule.lib/YOUR_SUBMODULE.url https://${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com/ORG/YOUR_SUBMODULE.git
git submodule sync
git submodule update --init --recursive
@Lauszus is the CI_TOKEN a personal access token?
@ashwinvis yes it is. I have updated my comment to make it more clear.
mm.. I am tempted to make a python script that does what @Lauszus suggests automatically for for all repositories defined in .gitmodules @ericsciple what is the timeline for a real fix/improvement to the action?
@jleni here's a version that will checkout all repositories defined in .gitmodules :)
It works for both ssh and https:
- name: Checkout submodules using a PAT
run: |
git config --file .gitmodules --get-regexp url | while read url; do
git config --file=.gitmodules $(echo "$url" | sed -E "s/[email protected]:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//")
done
git submodule sync
git submodule update --init --recursive
oh wow! that's awesome!! thanks!!
@tvainika the default token embedded in the main repo does not have access to fetch other private repositories. Instead if you supply
token: ${{ secrets.MY_GITHUB_PAT }}then it should work.
The url in .gitmodules needs to be the https one for this to work.
Example .gitmodules
[submodule "module"]
path = module
url = https://github.com/example/module
Example action.yml
name: Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.MY_GITHUB_PAT }}
- name: Checkout submodules
shell: bash
run: |
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
@samkit-jain yeah, that is why I ended up using my code above: https://github.com/actions/checkout/issues/116#issuecomment-573880976, as my private repositories use ssh and I do not want to change all my submodules just because of the CI.
@Lauszus +1 good point. i think adding inputs for ssh support + submodule support would create a generally frictionless experience for folks looking to checkout submodules.