Skip to content

Commit 46e7f5d

Browse files
committed
Fix
1 parent 81f8dee commit 46e7f5d

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

.github/actions/submodules-checkout/action.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ runs:
2323

2424
- name: Verify SSH Connection (Optional)
2525
if: ${{ inputs.submodules-ssh-key }}
26-
run: ssh -T [email protected] || true
26+
run: |
27+
ssh -T [email protected] || true
28+
shell: bash
29+
30+
- name: Verify SSH Connection (Optional)
31+
if: ${{ inputs.submodules-ssh-key }}
32+
run: |
33+
echo Branch is ${{ github.ref_name }}
2734
shell: bash
2835

2936
- name: Try checkout submodules to the same branch as main repo
3037
if: ${{ inputs.submodules-ssh-key }}
3138
run: |
32-
./submodules.sh
39+
./submodules.sh ${{ github.ref_name }}
3340
shell: bash
3441

3542
- name: Show main readme

submodules.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#!/bin/bash
22

3+
BRANCH="$1"
4+
5+
36
git submodule update --init --recursive
47

58
git submodule foreach '
6-
BRANCH=$(git -C $toplevel rev-parse --abbrev-ref HEAD);
7-
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null; then
8-
git checkout "$BRANCH" && git pull origin "$BRANCH";
9-
else
10-
git checkout "main" && git pull origin "main";
11-
fi;'
9+
# If a branch parameter is provided, use it; otherwise, determine the branch dynamically
10+
if [ -n "'"$BRANCH"'" ]; then
11+
SUBMODULE_BRANCH="'"$BRANCH"'"
12+
else
13+
SUBMODULE_BRANCH=$(git -C $toplevel rev-parse --abbrev-ref HEAD)
14+
fi
15+
16+
echo "Checking out \"$SUBMODULE_BRANCH\" branch in \"$name\" submodule"
17+
18+
# Check if the branch exists in the remote
19+
if git ls-remote --exit-code --heads origin "$SUBMODULE_BRANCH" > /dev/null; then
20+
git checkout "$SUBMODULE_BRANCH" && git pull origin "$SUBMODULE_BRANCH"
21+
else
22+
# Fallback to "main" if the branch does not exist
23+
git checkout "main" && git pull origin "main"
24+
fi
25+
'

0 commit comments

Comments
 (0)