Skip to content

Commit e842a54

Browse files
committed
ci(refactor): Improvements and compilation of only related files
1 parent 5c5a84a commit e842a54

File tree

6 files changed

+212
-25
lines changed

6 files changed

+212
-25
lines changed

.github/scripts/on-push.sh

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function build(){
1010
local chunk_index=$3
1111
local chunks_cnt=$4
1212
local build_log=$5
13-
shift; shift; shift; shift; shift;
13+
local sketches_file=$6
14+
shift; shift; shift; shift; shift; shift;
1415
local sketches=$*
1516

1617
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
@@ -23,6 +24,9 @@ function build(){
2324
if [ "$OS_IS_LINUX" == "1" ]; then
2425
args+=" -p $ARDUINO_ESP32_PATH/libraries"
2526
args+=" -i $chunk_index -m $chunks_cnt"
27+
if [ -n "$sketches_file" ]; then
28+
args+=" -f $sketches_file"
29+
fi
2630
if [ $build_log -eq 1 ]; then
2731
args+=" -l $build_log"
2832
fi
@@ -50,6 +54,7 @@ fi
5054
CHUNK_INDEX=$1
5155
CHUNKS_CNT=$2
5256
BUILD_LOG=$3
57+
SKETCHES_FILE=$4
5358
BUILD_PIO=0
5459
if [ "$#" -lt 2 ] || [ "$CHUNKS_CNT" -le 0 ]; then
5560
CHUNK_INDEX=0
@@ -94,12 +99,12 @@ if [ "$BUILD_PIO" -eq 0 ]; then
9499
fi
95100

96101
#build sketches for different targets
97-
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
98-
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
99-
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
100-
build "esp32c6" $FQBN_ESP32C6 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
101-
build "esp32h2" $FQBN_ESP32H2 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
102-
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
102+
build "esp32s3" $FQBN_ESP32S3 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
103+
build "esp32s2" $FQBN_ESP32S2 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
104+
build "esp32c3" $FQBN_ESP32C3 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
105+
build "esp32c6" $FQBN_ESP32C6 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
106+
build "esp32h2" $FQBN_ESP32H2 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
107+
build "esp32" $FQBN_ESP32 "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "$SKETCHES_ESP32"
103108

104109
if [ "$BUILD_LOG" -eq 1 ]; then
105110
#remove last comma from the last JSON object

.github/scripts/sketch_utils.sh

+21-6
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,28 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
259259
unset options
260260
}
261261

262-
function count_sketches(){ # count_sketches <path> [target]
262+
function count_sketches(){ # count_sketches <path> [target] [file]
263263
local path=$1
264264
local target=$2
265+
local file=$3
265266

266267
if [ $# -lt 1 ]; then
267268
echo "ERROR: Illegal number of parameters"
268269
echo "USAGE: ${0} count <path> [target]"
269270
fi
270271

271272
rm -rf sketches.txt
273+
touch sketches.txt
272274
if [ ! -d "$path" ]; then
273-
touch sketches.txt
274275
return 0
275276
fi
276277

277-
local sketches=$(find $path -name *.ino | sort)
278+
if [ -n "$file" ]; then
279+
local sketches=$(cat $file)
280+
else
281+
local sketches=$(find $path -name *.ino | sort)
282+
fi
283+
278284
local sketchnum=0
279285
for sketch in $sketches; do
280286
local sketchdir=$(dirname $sketch)
@@ -338,6 +344,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
338344
shift
339345
log_compilation=$1
340346
;;
347+
-f )
348+
shift
349+
sketches_file=$1
350+
;;
341351
* )
342352
break
343353
;;
@@ -347,7 +357,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
347357

348358
local xtra_opts=$*
349359

350-
if [ -z $chunk_index ] || [ -z $chunk_max ]; then
360+
if [ -z "$chunk_index" ] || [ -z "$chunk_max" ]; then
351361
echo "ERROR: Invalid chunk paramters"
352362
echo "$USAGE"
353363
exit 1
@@ -363,8 +373,13 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
363373
fi
364374

365375
set +e
366-
count_sketches "$path" "$target"
367-
local sketchcount=$?
376+
if [ -n "$sketches_file" ]; then
377+
count_sketches "$path" "$target" "$sketches_file"
378+
local sketchcount=$?
379+
else
380+
count_sketches "$path" "$target"
381+
local sketchcount=$?
382+
fi
368383
set -e
369384
local sketches=$(cat sketches.txt)
370385
rm -rf sketches.txt

.github/workflows/publishsizes.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Sizes Results
22

33
on:
44
workflow_run:
5-
workflows: [ESP32 Arduino CI]
5+
workflows: [Compilation Tests]
66
types:
77
- completed
88

@@ -63,7 +63,7 @@ jobs:
6363
uses: juliangruber/read-file-action@v1
6464
with:
6565
path: ./artifacts/sizes-report/pr_num.txt
66-
66+
6767
- name: Report results
6868
uses: P-R-O-C-H-Y/report-size-deltas@sizes_v2
6969
with:

.github/workflows/push.yml

+172-6
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,193 @@
1-
name: ESP32 Arduino CI
1+
name: Compilation Tests
22

33
on:
44
workflow_dispatch:
55
push:
66
branches:
77
- master
88
- release/*
9+
pull_request:
910
paths:
1011
- 'cores/**'
1112
- 'libraries/**'
13+
- '!libraries/**.md'
14+
- '!libraries/**.txt'
15+
- '!libraries/**.properties'
16+
- '!libraries/**.py'
1217
- 'package/**'
1318
- 'tools/**.py'
1419
- 'platform.txt'
1520
- 'programmers.txt'
21+
- 'idf_component.yml'
22+
- 'Kconfig.projbuild'
23+
- 'package.json'
1624
- '.github/workflows/push.yml'
1725
- '.github/scripts/**'
1826
- '!.github/scripts/find_*'
1927
- '!.github/scripts/on-release.sh'
2028
- '!.github/scripts/tests_*'
2129
- '!.github/scripts/upload_*'
22-
pull_request:
2330

2431
concurrency:
2532
group: build-${{github.event.pull_request.number || github.ref}}
2633
cancel-in-progress: true
2734

28-
jobs:
35+
env:
36+
MAX_CHUNKS: 15
2937

38+
jobs:
3039
cmake-check:
3140
name: Check cmake file
3241
runs-on: ubuntu-latest
3342
steps:
3443
- uses: actions/checkout@v4
3544
- run: bash ./.github/scripts/check-cmakelists.sh
3645

46+
gen-chunks:
47+
name: Generate chunks
48+
runs-on: ubuntu-latest
49+
outputs:
50+
build_all: ${{ steps.set-chunks.outputs.build_all }}
51+
build_static_sketches: ${{ steps.set-chunks.outputs.build_static_sketches }}
52+
build_idf: ${{ steps.set-chunks.outputs.build_idf }}
53+
build_platformio: ${{ steps.set-chunks.outputs.build_platformio }}
54+
chunk_count: ${{ steps.set-chunks.outputs.chunk_count }}
55+
chunks: ${{ steps.set-chunks.outputs.chunks }}
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
with:
60+
fetch-depth: 2
61+
62+
- name: Get changed files
63+
id: changed-files
64+
uses: tj-actions/changed-files@v44
65+
with:
66+
files_yaml: |
67+
core:
68+
- '.github/**'
69+
- '!.github/scripts/install-platformio-esp32.sh'
70+
- 'cores/**'
71+
- 'package/**'
72+
- 'tools/**'
73+
- '!tools/platformio-build.py'
74+
- 'platform.txt'
75+
- 'programmers.txt'
76+
libraries:
77+
- 'libraries/**/examples/**'
78+
- 'libraries/**/src/**'
79+
static_sketeches:
80+
- 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino'
81+
- 'libraries/BLE/examples/Server/Server.ino'
82+
- 'libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino'
83+
- 'libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino'
84+
- 'libraries/NetworkClientSecure/src/**'
85+
- 'libraries/BLE/src/**'
86+
- 'libraries/Insights/src/**'
87+
idf:
88+
- 'idf_component.yml'
89+
- 'Kconfig.projbuild'
90+
platformio:
91+
- 'package.json'
92+
- '.github/scripts/install-platformio-esp32.sh'
93+
- 'tools/platformio-build.py'
94+
95+
- name: Set chunks
96+
id: set-chunks
97+
env:
98+
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
99+
run: |
100+
build_all=false
101+
chunks_count=0
102+
is_pr=${{ github.event_name == 'pull_request' }}
103+
104+
build_platformio=${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
105+
build_idf=${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
106+
build_static_sketches=${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
107+
108+
core_changed=${{ steps.changed-files.outputs.core_any_changed == 'true' }}
109+
lib_changed=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
110+
111+
if [[ $core_changed == 'true' ]] || [[ $is_pr != 'true' ]]; then
112+
echo "Core files changed or not a PR. Building all."
113+
build_all=true
114+
chunks_count=${{ env.MAX_CHUNKS }}
115+
elif [[ $lib_changed == 'true' ]]; then
116+
echo "Libraries changed. Building only affected sketches."
117+
sketches=""
118+
for file in $LIB_FILES; do
119+
if [[ $file == *.ino ]]; then
120+
# If file ends with .ino, add it to the list of sketches
121+
echo "Sketch found: $file"
122+
sketches+="$file "
123+
elif [[ $(basename $(dirname $file)) == "src" ]]; then
124+
# If file is in a src directory, find all sketches in the parent/examples directory
125+
echo "Library src file found: $file"
126+
lib=$(dirname $(dirname $file))
127+
lib_sketches=$(find $lib/examples -name *.ino)
128+
sketches+="$lib_sketches "
129+
echo "Library sketches: $lib_sketches"
130+
else
131+
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
132+
echo "File in example folder found: $file"
133+
sketch=$(find $(dirname $file) -name *.ino)
134+
sketches+="$sketch "
135+
echo "Sketch in example folder: $sketch"
136+
fi
137+
echo ""
138+
done
139+
else
140+
echo "Unhandled change triggered the build. This should not happen."
141+
exit 1
142+
fi
143+
144+
if [[ -n $sketches ]]; then
145+
# Remove duplicates
146+
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
147+
for sketch in $sketches; do
148+
echo $sketch >> sketches_found.txt
149+
chunks_count=$((chunks_count+1))
150+
done
151+
echo "Number of sketches found: $chunks_count"
152+
echo "Sketches: $sketches"
153+
154+
if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then
155+
echo "More sketches than the allowed number of chunks found. Limiting to ${{ env.MAX_CHUNKS }} chunks."
156+
chunks_count=${{ env.MAX_CHUNKS }}
157+
fi
158+
fi
159+
160+
chunks='["0"'
161+
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
162+
chunks+=",\"$i\""
163+
done
164+
chunks+="]"
165+
166+
echo "build_all=$build_all" >> $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
172+
173+
- name: Upload sketches found
174+
if: ${{ steps.set-chunks.outputs.build_all == 'false' }}
175+
uses: actions/upload-artifact@v4
176+
with:
177+
name: sketches_found
178+
path: sketches_found.txt
179+
overwrite: true
180+
if-no-files-found: error
181+
37182
# Ubuntu
38183
build-arduino-linux:
39184
name: Arduino ${{ matrix.chunk }} on ubuntu-latest
185+
needs: gen-chunks
40186
runs-on: ubuntu-latest
41187
strategy:
42188
fail-fast: false
43189
matrix:
44-
chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
190+
chunk: ${{ fromJson(needs.gen-chunks.outputs.chunks) }}
45191

46192
steps:
47193
- uses: actions/checkout@v4
@@ -62,8 +208,19 @@ jobs:
62208
./tools/riscv32-*
63209
./tools/xtensa-*
64210
65-
- name: Build Sketches
66-
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15 1
211+
- name: Build all sketches
212+
if: ${{ needs.gen-chunks.outputs.build_all == 'true' }}
213+
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} ${{ env.MAX_CHUNKS }} 1
214+
215+
- name: Download sketches found
216+
if: ${{ needs.gen-chunks.outputs.build_all == 'false' }}
217+
uses: actions/download-artifact@v4
218+
with:
219+
name: sketches_found
220+
221+
- name: Build selected sketches
222+
if: ${{ needs.gen-chunks.outputs.build_all == 'false' }}
223+
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} ${{ needs.gen-chunks.outputs.chunk_count }} 1 sketches_found.txt
67224

68225
#Upload cli compile json as artifact
69226
- name: Upload cli compile json
@@ -76,6 +233,8 @@ jobs:
76233
# Windows and MacOS
77234
build-arduino-win-mac:
78235
name: Arduino on ${{ matrix.os }}
236+
needs: gen-chunks
237+
if: ${{ needs.gen-chunks.outputs.build_all == 'true' || needs.gen-chunks.outputs.build_static_sketches == 'true' }}
79238
runs-on: ${{ matrix.os }}
80239
strategy:
81240
fail-fast: false
@@ -93,6 +252,11 @@ jobs:
93252
# PlatformIO on Windows, Ubuntu and Mac
94253
build-platformio:
95254
name: PlatformIO on ${{ matrix.os }}
255+
needs: gen-chunks
256+
if: |
257+
needs.gen-chunks.outputs.build_all == 'true' ||
258+
needs.gen-chunks.outputs.build_static_sketches == 'true' ||
259+
needs.gen-chunks.outputs.build_platformio == 'true'
96260
runs-on: ${{ matrix.os }}
97261
strategy:
98262
fail-fast: false
@@ -109,6 +273,8 @@ jobs:
109273

110274
build-esp-idf-component:
111275
name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
276+
needs: gen-chunks
277+
if: ${{ needs.gen-chunks.outputs.build_all == 'true' || needs.gen-chunks.outputs.build_idf == 'true' }}
112278
runs-on: ubuntu-20.04
113279
strategy:
114280
fail-fast: false

.github/workflows/tests.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: Unit Tests
22

33
on:
44
workflow_dispatch:
@@ -8,6 +8,9 @@ on:
88
- 'tests/**'
99
- 'cores/**'
1010
- 'libraries/**'
11+
- '!libraries/**.md'
12+
- '!libraries/**.txt'
13+
- '!libraries/**.properties'
1114
- 'package/**'
1215
- '.github/workflows/tests.yml'
1316
- '.github/workflows/build_tests.yml'

0 commit comments

Comments
 (0)