Skip to content

Commit 7c21e3f

Browse files
committed
test
1 parent 037c898 commit 7c21e3f

File tree

5 files changed

+157
-19
lines changed

5 files changed

+157
-19
lines changed

.github/scripts/on-push.sh

Lines changed: 12 additions & 7 deletions
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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ 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"
@@ -274,7 +275,12 @@ function count_sketches(){ # count_sketches <path> [target]
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,7 +373,11 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
363373
fi
364374

365375
set +e
366-
count_sketches "$path" "$target"
376+
if [ -n "$sketches_file" ]; then
377+
count_sketches "$path" "$target" "$sketches_file"
378+
else
379+
count_sketches "$path" "$target"
380+
fi
367381
local sketchcount=$?
368382
set -e
369383
local sketches=$(cat sketches.txt)

.github/workflows/push.yml

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ on:
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'
@@ -19,29 +24,130 @@ on:
1924
- '!.github/scripts/on-release.sh'
2025
- '!.github/scripts/tests_*'
2126
- '!.github/scripts/upload_*'
22-
pull_request:
2327

2428
concurrency:
2529
group: build-${{github.event.pull_request.number || github.ref}}
2630
cancel-in-progress: true
2731

28-
jobs:
32+
env:
33+
MAX_CHUNKS: 15
2934

35+
jobs:
3036
cmake-check:
3137
name: Check cmake file
3238
runs-on: ubuntu-latest
3339
steps:
3440
- uses: actions/checkout@v4
3541
- run: bash ./.github/scripts/check-cmakelists.sh
3642

43+
gen-chunks:
44+
name: Generate chunks
45+
runs-on: ubuntu-latest
46+
outputs:
47+
build_all: ${{ steps.set-chunks.outputs.build_all }}
48+
chunk_count: ${{ steps.set-chunks.outputs.chunk_count }}
49+
chunks: ${{ steps.set-chunks.outputs.chunks }}
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 2
55+
56+
- name: Get changed files
57+
id: changed-files
58+
uses: tj-actions/changed-files@v44
59+
with:
60+
files_yaml: |
61+
core:
62+
- '.github/**'
63+
- 'cores/**'
64+
- 'package/**'
65+
- 'tools/**'
66+
- 'platform.txt'
67+
- 'programmers.txt'
68+
libraries:
69+
- 'libraries/**/src/**'
70+
- '!libraries/**/src/dummy.h'
71+
examples:
72+
- 'libraries/**/examples/**'
73+
74+
- name: Set chunks
75+
id: set-chunks
76+
env:
77+
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
78+
EXAMPLES_FILES: ${{ steps.changed-files.outputs.examples_all_changed_files }}
79+
run: |
80+
build_all=false
81+
is_pr=${{ github.event_name == 'pull_request' }}
82+
core_changed=${{ steps.changed-files.outputs.core_any_changed == 'true' }}
83+
lib_changed=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
84+
examples_changed=${{ steps.changed-files.outputs.examples_any_changed == 'true' }}
85+
chunks_count=0
86+
87+
if [[ $core_changed == 'true' ]] || [[ $is_pr != 'true' ]]; then
88+
build_all=true
89+
chunks_count=${{ env.MAX_CHUNKS }}
90+
elif [[ $lib_changed == 'true' ]] || [[ $examples_changed == 'true' ]]; then
91+
local sketches=""
92+
local files="$LIB_FILES $EXAMPLES_FILES"
93+
for file in $files; do
94+
if [[ $file == "*.ino" ]]; then
95+
# If file ends with .ino, add it to the list of sketches
96+
sketches+="$file "
97+
continue
98+
elif [[ $(dirname $file) == "**/src" ]]; then
99+
# If file is in a src directory, find all sketches in the parent/examples directory
100+
local lib=$(dirname $(dirname $file))
101+
sketches+=$(find $lib/examples -name *.ino)
102+
else
103+
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
104+
sketches+=$(find $(dirname $file) -name *.ino)
105+
fi
106+
done
107+
108+
# Remove duplicates
109+
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
110+
111+
for sketch in $sketches; do
112+
echo $sketch >> sketches_found.txt
113+
chunks_count=$((chunks_count+1))
114+
done
115+
else
116+
echo "Unhandled change triggered the build. This should not happen."
117+
exit 1
118+
fi
119+
120+
if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then
121+
chunks_count=${{ env.MAX_CHUNKS }}
122+
fi
123+
124+
chunks='["0"'
125+
for i in $(seq 1 $chunks_count); do
126+
chunks+=",\"$i\""
127+
done
128+
chunks+="]"
129+
130+
echo "build_all=$build_all" >> $GITHUB_OUTPUT
131+
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
132+
echo "chunks=$chunks" >> $GITHUB_OUTPUT
133+
134+
- name: Upload sketches found
135+
if: ${{ steps.set-chunks.outputs.build_all == 'false' }}
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: sketches_found
139+
path: sketches_found.txt
140+
overwrite: true
141+
37142
# Ubuntu
38143
build-arduino-linux:
39144
name: Arduino ${{ matrix.chunk }} on ubuntu-latest
145+
needs: gen-chunks
40146
runs-on: ubuntu-latest
41147
strategy:
42148
fail-fast: false
43149
matrix:
44-
chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
150+
chunk: ${{ fromJson(needs.gen-chunks.outputs.chunks) }}
45151

46152
steps:
47153
- uses: actions/checkout@v4
@@ -62,8 +168,20 @@ jobs:
62168
./tools/riscv32-*
63169
./tools/xtensa-*
64170
65-
- name: Build Sketches
66-
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15 1
171+
- name: Build all sketches
172+
if: ${{ needs.gen-chunks.outputs.build_all == 'true' }}
173+
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} ${{ env.MAX_CHUNKS }} 1
174+
175+
- name: Download sketches found
176+
if: ${{ needs.gen-chunks.outputs.build_all == 'false' }}
177+
uses: actions/download-artifact@v4
178+
with:
179+
name: sketches_found
180+
path: sketches_found.txt
181+
182+
- name: Build selected sketches
183+
if: ${{ needs.gen-chunks.outputs.build_all == 'false' }}
184+
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} ${{ needs.gen-chunks.outputs.chunk_count }} 1 sketches_found.txt
67185

68186
#Upload cli compile json as artifact
69187
- name: Upload cli compile json

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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'

.github/workflows/wokwi.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ jobs:
6767
cache: 'pip'
6868
python-version: '3.x'
6969

70-
- name: Wokwi CI Server
71-
uses: wokwi/wokwi-ci-server-action@v1
72-
7370
- name: Install dependencies
7471
if: steps.check-tests.outputs.enabled == 'true'
7572
run: |
@@ -81,6 +78,7 @@ jobs:
8178
run: curl -L https://wokwi.com/ci/install.sh | sh
8279

8380
- name: Wokwi CI Server
81+
if: steps.check-tests.outputs.enabled == 'true'
8482
uses: wokwi/wokwi-ci-server-action@v1
8583

8684
- name: Get binaries

0 commit comments

Comments
 (0)