Skip to content

Commit fce8bd8

Browse files
committed
ci(push): Fix chunk generation for compilation
1 parent 6c20c90 commit fce8bd8

File tree

4 files changed

+101
-75
lines changed

4 files changed

+101
-75
lines changed

.github/scripts/on-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then
108108

109109
if [ "$BUILD_LOG" -eq 1 ]; then
110110
#remove last comma from the last JSON object
111-
sed -i '$ s/.$//' "$sizes_file"
111+
sed -i '$ s/,$//' "$sizes_file"
112112
#echo end of JSON array
113113
echo "]}" >> $sizes_file
114114
fi

.github/scripts/set_push_chunks.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
build_all=false
2+
chunks_count=0
3+
4+
if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then
5+
echo "Core files changed or not a PR. Building all."
6+
build_all=true
7+
chunks_count=$MAX_CHUNKS
8+
elif [[ $LIB_CHANGED == 'true' ]]; then
9+
echo "Libraries changed. Building only affected sketches."
10+
if [[ $NETWORKING_CHANGED == 'true' ]]; then
11+
echo "Networking libraries changed. Building networking related sketches."
12+
networking_sketches="$(find libraries/WiFi -name *.ino) "
13+
networking_sketches+="$(find libraries/Ethernet -name *.ino) "
14+
networking_sketches+="$(find libraries/PPP -name *.ino) "
15+
networking_sketches+="$(find libraries/NetworkClientSecure -name *.ino) "
16+
networking_sketches+="$(find libraries/WebServer -name *.ino) "
17+
fi
18+
if [[ $FS_CHANGED == 'true' ]]; then
19+
echo "FS libraries changed. Building FS related sketches."
20+
fs_sketches="$(find libraries/SD -name *.ino) "
21+
fs_sketches+="$(find libraries/SD_MMC -name *.ino) "
22+
fs_sketches+="$(find libraries/SPIFFS -name *.ino) "
23+
fs_sketches+="$(find libraries/LittleFS -name *.ino) "
24+
fs_sketches+="$(find libraries/FFat -name *.ino) "
25+
fi
26+
sketches="$networking_sketches $fs_sketches"
27+
for file in $LIB_FILES; do
28+
if [[ $file == *.ino ]]; then
29+
# If file ends with .ino, add it to the list of sketches
30+
echo "Sketch found: $file"
31+
sketches+="$file "
32+
elif [[ $(basename $(dirname $file)) == "src" ]]; then
33+
# If file is in a src directory, find all sketches in the parent/examples directory
34+
echo "Library src file found: $file"
35+
lib=$(dirname $(dirname $file))
36+
if [[ -d $lib/examples ]]; then
37+
lib_sketches=$(find $lib/examples -name *.ino)
38+
sketches+="$lib_sketches "
39+
echo "Library sketches: $lib_sketches"
40+
fi
41+
else
42+
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
43+
echo "File in example folder found: $file"
44+
sketch=$(find $(dirname $file) -name *.ino)
45+
sketches+="$sketch "
46+
echo "Sketch in example folder: $sketch"
47+
fi
48+
echo ""
49+
done
50+
fi
51+
52+
if [[ -n $sketches ]]; then
53+
# Remove duplicates
54+
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
55+
for sketch in $sketches; do
56+
echo $sketch >> sketches_found.txt
57+
chunks_count=$((chunks_count+1))
58+
done
59+
echo "Number of sketches found: $chunks_count"
60+
echo "Sketches:"
61+
echo "$sketches"
62+
63+
if [[ $chunks_count -gt $MAX_CHUNKS ]]; then
64+
echo "More sketches than the allowed number of chunks found. Limiting to $MAX_CHUNKS chunks."
65+
chunks_count=$MAX_CHUNKS
66+
fi
67+
fi
68+
69+
chunks='["0"'
70+
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
71+
chunks+=",\"$i\""
72+
done
73+
chunks+="]"
74+
75+
echo "build_all=$build_all" >> $GITHUB_OUTPUT
76+
echo "build_libraries=$BUILD_LIBRARIES" >> $GITHUB_OUTPUT
77+
echo "build_static_sketches=$BUILD_STATIC_SKETCHES" >> $GITHUB_OUTPUT
78+
echo "build_idf=$BUILD_IDF" >> $GITHUB_OUTPUT
79+
echo "build_platformio=$BUILD_PLATFORMIO" >> $GITHUB_OUTPUT
80+
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
81+
echo "chunks=$chunks" >> $GITHUB_OUTPUT

.github/scripts/sketch_utils.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
192192

193193
exit_status=$?
194194
if [ $exit_status -ne 0 ]; then
195-
echo ""ERROR: Compilation failed with error code $exit_status""
195+
echo "ERROR: Compilation failed with error code $exit_status"
196196
exit $exit_status
197197
fi
198198

@@ -236,7 +236,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
236236

237237
exit_status=$?
238238
if [ $exit_status -ne 0 ]; then
239-
echo ""ERROR: Compilation failed with error code $exit_status""
239+
echo "ERROR: Compilation failed with error code $exit_status"
240240
exit $exit_status
241241
fi
242242
# $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
@@ -398,6 +398,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
398398
else
399399
start_index=$(( $chunk_index * $chunk_size ))
400400
if [ "$sketchcount" -le "$start_index" ]; then
401+
echo "No sketches to build for $target in this chunk"
401402
return 0
402403
fi
403404

@@ -437,7 +438,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
437438
continue
438439
fi
439440
echo ""
440-
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
441+
echo "Building Sketch Index $sketchnum - $sketchdirname"
441442
build_sketch $args -s $sketchdir $xtra_opts
442443
local result=$?
443444
if [ $result -ne 0 ]; then

.github/workflows/push.yml

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ jobs:
7777
libraries:
7878
- 'libraries/**/examples/**'
7979
- 'libraries/**/src/**'
80+
networking:
81+
- 'libraries/Network/src/**'
82+
fs:
83+
- 'libraries/FS/src/**'
8084
static_sketeches:
8185
- 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino'
8286
- 'libraries/BLE/examples/Server/Server.ino'
@@ -97,78 +101,18 @@ jobs:
97101
id: set-chunks
98102
env:
99103
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
104+
IS_PR: ${{ github.event_name == 'pull_request' }}
105+
MAX_CHUNKS: ${{ env.MAX_CHUNKS }}
106+
BUILD_PLATFORMIO: ${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
107+
BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
108+
BUILD_LIBRARIES: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
109+
BUILD_STATIC_SKETCHES: ${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
110+
FS_CHANGED: ${{ steps.changed-files.outputs.fs_any_changed == 'true' }}
111+
NETWORKING_CHANGED: ${{ steps.changed-files.outputs.networking_any_changed == 'true' }}
112+
CORE_CHANGED: ${{ steps.changed-files.outputs.core_any_changed == 'true' }}
113+
LIB_CHANGED: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
100114
run: |
101-
build_all=false
102-
chunks_count=0
103-
is_pr=${{ github.event_name == 'pull_request' }}
104-
105-
build_platformio=${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
106-
build_idf=${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
107-
build_libraries=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
108-
build_static_sketches=${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
109-
110-
core_changed=${{ steps.changed-files.outputs.core_any_changed == 'true' }}
111-
lib_changed=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
112-
113-
if [[ $core_changed == 'true' ]] || [[ $is_pr != 'true' ]]; then
114-
echo "Core files changed or not a PR. Building all."
115-
build_all=true
116-
chunks_count=${{ env.MAX_CHUNKS }}
117-
elif [[ $lib_changed == 'true' ]]; then
118-
echo "Libraries changed. Building only affected sketches."
119-
sketches=""
120-
for file in $LIB_FILES; do
121-
if [[ $file == *.ino ]]; then
122-
# If file ends with .ino, add it to the list of sketches
123-
echo "Sketch found: $file"
124-
sketches+="$file "
125-
elif [[ $(basename $(dirname $file)) == "src" ]]; then
126-
# If file is in a src directory, find all sketches in the parent/examples directory
127-
echo "Library src file found: $file"
128-
lib=$(dirname $(dirname $file))
129-
lib_sketches=$(find $lib/examples -name *.ino)
130-
sketches+="$lib_sketches "
131-
echo "Library sketches: $lib_sketches"
132-
else
133-
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
134-
echo "File in example folder found: $file"
135-
sketch=$(find $(dirname $file) -name *.ino)
136-
sketches+="$sketch "
137-
echo "Sketch in example folder: $sketch"
138-
fi
139-
echo ""
140-
done
141-
fi
142-
143-
if [[ -n $sketches ]]; then
144-
# Remove duplicates
145-
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
146-
for sketch in $sketches; do
147-
echo $sketch >> sketches_found.txt
148-
chunks_count=$((chunks_count+1))
149-
done
150-
echo "Number of sketches found: $chunks_count"
151-
echo "Sketches: $sketches"
152-
153-
if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then
154-
echo "More sketches than the allowed number of chunks found. Limiting to ${{ env.MAX_CHUNKS }} chunks."
155-
chunks_count=${{ env.MAX_CHUNKS }}
156-
fi
157-
fi
158-
159-
chunks='["0"'
160-
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
161-
chunks+=",\"$i\""
162-
done
163-
chunks+="]"
164-
165-
echo "build_all=$build_all" >> $GITHUB_OUTPUT
166-
echo "build_libraries=$build_libraries" >> $GITHUB_OUTPUT
167-
echo "build_static_sketches=$build_static_sketches" >> $GITHUB_OUTPUT
168-
echo "build_idf=$build_idf" >> $GITHUB_OUTPUT
169-
echo "build_platformio=$build_platformio" >> $GITHUB_OUTPUT
170-
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
171-
echo "chunks=$chunks" >> $GITHUB_OUTPUT
115+
bash ./.github/scripts/set_push_chunks.sh
172116
173117
- name: Upload sketches found
174118
if: ${{ steps.set-chunks.outputs.build_all == 'false' && steps.set-chunks.outputs.build_libraries == 'true' }}

0 commit comments

Comments
 (0)