ci: dynamic submodule check for build_release (#1114)

* ci: dynamic submodule check for build_release

* test opendbc diff

* somem fix

* this way

* use path

* use master branch instead

* less verbose

* test bump

* test 1 more sub change

* unbump

* only echo if there's a diff
This commit is contained in:
Jason Wen
2025-08-02 23:11:59 -04:00
committed by GitHub
parent 582671e006
commit a93f1caf1f
2 changed files with 49 additions and 7 deletions

View File

@@ -67,7 +67,23 @@ jobs:
- name: Check submodules
if: github.repository == 'sunnypilot/sunnypilot'
timeout-minutes: 3
run: release/check-submodules.sh
run: |
if [ "${{ github.ref }}" != "refs/heads/master" ]; then
git fetch origin master:refs/remotes/origin/master
SUBMODULE_PATHS=$(git diff origin/master HEAD --name-only | grep -E '^[^/]+$' | while read path; do
if git ls-files --stage "$path" | grep -q "^160000"; then
echo "$path"
fi
done | tr '\n' ' ')
if [ -n "$SUBMODULE_PATHS" ]; then
echo "Changed submodule paths: $SUBMODULE_PATHS"
export SUBMODULE_PATHS="$SUBMODULE_PATHS"
export CHECK_PR_REFS=true
fi
fi
release/check-submodules.sh
build:
runs-on: ${{

View File

@@ -1,17 +1,43 @@
#!/usr/bin/env bash
has_submodule_changes() {
local submodule_path="$1"
if [ -n "$SUBMODULE_PATHS" ]; then
echo "$SUBMODULE_PATHS" | grep -q "$submodule_path"
return $?
fi
return 1
}
while read hash submodule ref; do
if [ -z "$hash" ] || [ -z "$submodule" ]; then
continue
fi
hash=$(echo "$hash" | sed 's/^[+-]//')
if [ "$submodule" = "tinygrad_repo" ]; then
echo "Skipping $submodule"
continue
fi
git -C $submodule fetch --depth 100 origin master
git -C $submodule branch -r --contains $hash | grep "origin/master"
if [ "$?" -eq 0 ]; then
echo "$submodule ok"
if [ "$CHECK_PR_REFS" = "true" ] && has_submodule_changes "$submodule"; then
echo "Checking $submodule (non-master): verifying hash $hash exists"
git -C $submodule fetch --depth 100 origin
if git -C $submodule cat-file -e $hash 2>/dev/null; then
echo "$submodule ok (hash exists)"
else
echo "$submodule: $hash does not exist in the repository"
exit 1
fi
else
echo "$submodule: $hash is not on master"
exit 1
git -C $submodule fetch --depth 100 origin master
git -C $submodule branch -r --contains $hash | grep "origin/master"
if [ "$?" -eq 0 ]; then
echo "$submodule ok"
else
echo "$submodule: $hash is not on master"
exit 1
fi
fi
done <<< $(git submodule status --recursive)