diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 3253525..191e196 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -46,7 +46,7 @@ jobs: sed -i 's/--abort-on-container-exit/-d/' bin/first-build.sh TAB=$'\t' export FALLBACK_BRANCH=$([ "$GITHUB_BRANCH" == "master" ] && echo "main" && echo "master" || echo "develop") - git submodule foreach bash -c '(git checkout "${GITHUB_BRANCH}" || git checkout main || git checkout develop || git checkout master || git checkout "${FALLBACK_BRANCH}") && git pull' + ./bin/checkout-submodules.sh "$GITHUB_BRANCH" "$FALLBACK_BRANCH" git submodule foreach git rev-parse --abbrev-ref HEAD - name: Run Script diff --git a/bin/checkout-submodules.sh b/bin/checkout-submodules.sh new file mode 100755 index 0000000..ad6236f --- /dev/null +++ b/bin/checkout-submodules.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +GITHUB_BRANCH="$1" +FALLBACK_BRANCH="$2" + +git submodule foreach --recursive bash -c ' + GITHUB_BRANCH="$1" + FALLBACK_BRANCH="$2" + + for b in "$GITHUB_BRANCH" main develop master "$FALLBACK_BRANCH"; do + echo "Trying branch: $b" + if git ls-remote --exit-code origin "$b" &>/dev/null; then + echo "Found branch $b in remote. Checking out..." + if git checkout -B "$b" "origin/$b"; then + echo "Pulling latest changes for $b..." + git pull + exit 0 + fi + else + echo "Branch $b not found in remote." + fi + done + + echo "No matching branch found in submodule $name" +' _ "$GITHUB_BRANCH" "$FALLBACK_BRANCH"