Skip to content

Add hardware configuration in the loop #14

Add hardware configuration in the loop

Add hardware configuration in the loop #14

name: Verify Submodule Commits
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
# Allow manual triggering
workflow_dispatch:
jobs:
verify-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout repository with submodules
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Verify submodule commits
run: |
# Initialize output variables
invalid_submodules=""
all_valid=true
# Get list of submodules
submodules=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
# Check each submodule
for submodule in $submodules; do
echo "Checking submodule: $submodule"
# Enter submodule directory
cd "$submodule" || { echo "Failed to enter $submodule directory"; exit 1; }
# Get current commit of submodule
current_commit=$(git rev-parse HEAD)
echo " Current commit: $current_commit"
# Fetch all branches to ensure we have the latest data
git fetch --all
# Check if main branch exists, if not try master
if git show-ref --verify --quiet refs/remotes/origin/main; then
target_branch="origin/main"
elif git show-ref --verify --quiet refs/remotes/origin/master; then
target_branch="origin/master"
else
echo "::error::Neither main nor master branch found in submodule $submodule"
invalid_submodules="$invalid_submodules\n- $submodule (no main/master branch found)"
all_valid=false
cd - > /dev/null
continue
fi
# Get commit of target branch (main or master)
target_commit=$(git rev-parse $target_branch)
echo " $target_branch commit: $target_commit"
# Check if current commit is on the target branch
if git merge-base --is-ancestor $current_commit $target_branch && git merge-base --is-ancestor $target_branch $current_commit; then
echo " Submodule $submodule is at the tip of $target_branch"
elif git merge-base --is-ancestor $current_commit $target_branch; then
echo " Submodule $submodule is behind $target_branch but on the branch"
echo "::warning::Submodule $submodule is behind on $target_branch"
invalid_submodules="$invalid_submodules\n- $submodule (behind on $target_branch)"
else
# Check if the commit is in the history of target branch
if git merge-base --is-ancestor $current_commit $target_branch; then
echo " Submodule $submodule commit is in the history of $target_branch"
else
echo " Submodule $submodule commit is not on $target_branch"
echo "::error::Submodule $submodule is not on $target_branch"
invalid_submodules="$invalid_submodules\n- $submodule (not on $target_branch)"
all_valid=false
fi
fi
# Return to main repo directory
cd - > /dev/null
done
# Output results
if [ "$all_valid" = true ]; then
echo "All submodules are using commits from main or master branches."
else
echo "The following submodules have issues:"
echo -e "$invalid_submodules"
exit 1 # Fail the workflow
fi