1515 uses : actions/checkout@v6
1616 with :
1717 submodules : recursive
18+ fetch-depth : 0
1819 - name : Add KiCad Repository
1920 run : |
2021 sudo add-apt-repository --yes ppa:kicad/kicad-10.0-releases
@@ -28,16 +29,49 @@ jobs:
2829 with :
2930 python-version : ' 3.12'
3031 - run : pip install frugy
31- - name : Build and Validate KiCad Project
32+ - name : Determine changed project directories
33+ id : changes
3234 run : |
33- pushd ${{github.workspace}}
34- PROJECT_DIRS=$(ls -d */ | sed 's:/*$::')
35- popd
36- for DIR in $PROJECT_DIRS; do
37- if [ ! -f "${{github.workspace}}/$DIR/CMakeLists.txt" ]; then
38- echo "Skipping directory: $DIR (no CMakeLists.txt)"
39- continue
35+ if [ "${{ github.event_name }}" = "pull_request" ]; then
36+ BASE_SHA="${{ github.event.pull_request.base.sha }}"
37+ else
38+ BASE_SHA="${{ github.event.before }}"
39+ fi
40+
41+ ALL_DIRS=$(ls -d */ 2>/dev/null | sed 's:/*$::')
42+
43+ # Initial push or unknown base: build everything.
44+ if [ -z "$BASE_SHA" ] || [[ "$BASE_SHA" =~ ^0+$ ]]; then
45+ echo "No base SHA available; building all project directories."
46+ CHANGED="$ALL_DIRS"
47+ else
48+ # If the workflow file or any submodule reference changed, rebuild everything.
49+ if git diff --name-only "$BASE_SHA" HEAD | grep -qE '^(\.github/workflows/|\.gitmodules$)'; then
50+ echo "Workflow or submodules changed; building all project directories."
51+ CHANGED="$ALL_DIRS"
52+ else
53+ CHANGED=$(git diff --name-only "$BASE_SHA" HEAD | awk -F/ 'NF>1 {print $1}' | sort -u)
54+ fi
55+ fi
56+
57+ SELECTED=""
58+ for DIR in $CHANGED; do
59+ if [ -f "$DIR/CMakeLists.txt" ]; then
60+ SELECTED="$SELECTED $DIR"
4061 fi
62+ done
63+ SELECTED=$(echo "$SELECTED" | xargs)
64+
65+ if [ -z "$SELECTED" ]; then
66+ echo "No KiCad project directories touched by this change."
67+ else
68+ echo "Will build: $SELECTED"
69+ fi
70+ echo "dirs=$SELECTED" >> "$GITHUB_OUTPUT"
71+ - name : Build and Validate KiCad Project
72+ if : steps.changes.outputs.dirs != ''
73+ run : |
74+ for DIR in ${{ steps.changes.outputs.dirs }}; do
4175 echo "Processing directory: $DIR"
4276 pushd ${{github.workspace}}/$DIR
4377 cmake -B ./build -G Ninja
0 commit comments