Skip to content

Commit 12d4226

Browse files
committed
ci(2.x): Save sizes to gh-pages
1 parent dc596f1 commit 12d4226

File tree

3 files changed

+147
-8
lines changed

3 files changed

+147
-8
lines changed

Diff for: .github/scripts/on-push.sh

+28-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function build(){
1212
local fqbn=$2
1313
local chunk_index=$3
1414
local chunks_cnt=$4
15-
shift; shift; shift; shift;
15+
local build_log=$5
16+
shift; shift; shift; shift; shift;
1617
local sketches=$*
1718

1819
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
@@ -25,6 +26,9 @@ function build(){
2526
if [ "$OS_IS_LINUX" == "1" ]; then
2627
args+=" -p $ARDUINO_ESP32_PATH/libraries"
2728
args+=" -i $chunk_index -m $chunks_cnt"
29+
if [ $build_log -eq 1 ]; then
30+
args+=" -l $build_log"
31+
fi
2832
${BUILD_SKETCHES} ${args}
2933
else
3034
for sketch in ${sketches}; do
@@ -48,6 +52,7 @@ fi
4852

4953
CHUNK_INDEX=$1
5054
CHUNKS_CNT=$2
55+
BUILD_LOG=$3
5156
BUILD_PIO=0
5257
if [ "$#" -lt 2 ] || [ "$CHUNKS_CNT" -le 0 ]; then
5358
CHUNK_INDEX=0
@@ -58,6 +63,10 @@ elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
5863
BUILD_PIO=1
5964
fi
6065

66+
if [ -z "$BUILD_LOG" ] || [ "$BUILD_LOG" -le 0 ]; then
67+
BUILD_LOG=0
68+
fi
69+
6170
#echo "Updating submodules ..."
6271
#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
6372

@@ -84,11 +93,25 @@ if [ "$BUILD_PIO" -eq 0 ]; then
8493
$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino\
8594
$ARDUINO_ESP32_PATH/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino\
8695
"
96+
#create sizes_file
97+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$CHUNK_INDEX.json"
98+
99+
if [ "$BUILD_LOG" -eq 1 ]; then
100+
#create sizes_file and echo start of JSON array with "boards" key
101+
echo "{\"boards\": [" > $sizes_file
102+
fi
103+
104+
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
105+
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32XX
106+
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32XX
107+
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
87108

88-
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
89-
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
90-
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
91-
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
109+
if [ "$BUILD_LOG" -eq 1 ]; then
110+
#remove last comma from the last JSON object
111+
sed -i '$ s/.$//' "$sizes_file"
112+
#echo end of JSON array
113+
echo "]}" >> $sizes_file
114+
fi
92115
else
93116
source ${SCRIPTS_DIR}/install-platformio-esp32.sh
94117
# PlatformIO ESP32 Test

Diff for: .github/scripts/sketch_utils.sh

+73-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
2727
shift
2828
sketchdir=$1
2929
;;
30+
-i )
31+
shift
32+
chunk_index=$1
33+
;;
34+
-l )
35+
shift
36+
log_compilation=$1
37+
;;
3038
* )
3139
break
3240
;;
@@ -127,6 +135,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
127135
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
128136
fi
129137

138+
output_file="$HOME/.arduino/cli_compile_output.txt"
139+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
140+
130141
mkdir -p "$ARDUINO_CACHE_DIR"
131142
for i in `seq 0 $(($len - 1))`
132143
do
@@ -151,7 +162,40 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
151162
--build-property "compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
152163
--build-cache-path "$ARDUINO_CACHE_DIR" \
153164
--build-path "$build_dir" \
154-
$xtra_opts "${sketchdir}"
165+
$xtra_opts "${sketchdir}" \
166+
> $output_file
167+
168+
exit_status=$?
169+
if [ $exit_status -ne 0 ]; then
170+
echo ""ERROR: Compilation failed with error code $exit_status""
171+
exit $exit_status
172+
fi
173+
174+
if [ $log_compilation ]; then
175+
#Extract the program storage space and dynamic memory usage in bytes and percentage in separate variables from the output, just the value without the string
176+
flash_bytes=$(grep -oE 'Sketch uses ([0-9]+) bytes' $output_file | awk '{print $3}')
177+
flash_percentage=$(grep -oE 'Sketch uses ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk '{print $5}' | tr -d '(%)')
178+
ram_bytes=$(grep -oE 'Global variables use ([0-9]+) bytes' $output_file | awk '{print $4}')
179+
ram_percentage=$(grep -oE 'Global variables use ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk '{print $6}' | tr -d '(%)')
180+
181+
# Extract the directory path excluding the filename
182+
directory_path=$(dirname "$sketch")
183+
# Define the constant part
184+
constant_part="/home/runner/Arduino/hardware/espressif/esp32/libraries/"
185+
# Extract the desired substring using sed
186+
lib_sketch_name=$(echo "$directory_path" | sed "s|$constant_part||")
187+
#append json file where key is fqbn, sketch name, sizes -> extracted values
188+
echo "{\"name\": \"$lib_sketch_name\",
189+
\"sizes\": [{
190+
\"flash_bytes\": $flash_bytes,
191+
\"flash_percentage\": $flash_percentage,
192+
\"ram_bytes\": $ram_bytes,
193+
\"ram_percentage\": $ram_percentage
194+
}]
195+
}," >> "$sizes_file"
196+
fi
197+
198+
155199
elif [ -f "$ide_path/arduino-builder" ]; then
156200
echo "Building $sketchname with arduino-builder and FQBN=$currfqbn"
157201
echo "Build path = $build_dir"
@@ -253,6 +297,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
253297
shift
254298
chunk_max=$1
255299
;;
300+
-l )
301+
shift
302+
log_compilation=$1
303+
;;
256304
* )
257305
break
258306
;;
@@ -316,8 +364,19 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
316364
echo "Start Sketch: $start_num"
317365
echo "End Sketch : $end_index"
318366

367+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
368+
if [ $log_compilation ]; then
369+
#echo board,target and start of sketches to sizes_file json
370+
echo "{ \"board\": \"$fqbn\",
371+
\"target\": \"$target\",
372+
\"sketches\": [" >> "$sizes_file"
373+
fi
374+
319375
local sketchnum=0
320-
args+=" -ai $ide_path -au $user_path"
376+
args+=" -ai $ide_path -au $user_path -i $chunk_index"
377+
if [ $log_compilation ]; then
378+
args+=" -l $log_compilation"
379+
fi
321380
for sketch in $sketches; do
322381
local sketchdir=$(dirname $sketch)
323382
local sketchdirname=$(basename $sketchdir)
@@ -334,6 +393,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
334393
return $result
335394
fi
336395
done
396+
397+
if [ $log_compilation ]; then
398+
#remove last comma from json
399+
if [ $i -eq $(($len - 1)) ]; then
400+
sed -i '$ s/.$//' "$sizes_file"
401+
fi
402+
#echo end of sketches sizes_file json
403+
echo "]" >> "$sizes_file"
404+
#echo end of board sizes_file json
405+
echo "}," >> "$sizes_file"
406+
fi
407+
337408
return 0
338409
}
339410

Diff for: .github/workflows/push.yml

+46-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ jobs:
4545
'tools/get.py',
4646
'.github/scripts/install-arduino-ide.sh') }}
4747
- name: Build Sketches
48-
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15
48+
run: bash ./.github/scripts/on-push.sh ${{ matrix.chunk }} 15 1
49+
50+
#Upload cli compile json as artifact
51+
- name: Upload cli compile json
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: pr_cli_compile_${{ matrix.chunk }}
55+
path: cli_compile_${{ matrix.chunk }}.json
56+
overwrite: true
4957

5058
# Windows and MacOS
5159
build-arduino-win-mac:
@@ -106,3 +114,40 @@ jobs:
106114
idf.py create-project test
107115
echo CONFIG_FREERTOS_HZ=1000 > test/sdkconfig.defaults
108116
idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build
117+
118+
# Save 2.x artifacts to gh-pages
119+
save-artifacts:
120+
name: Save build artifacts
121+
needs: build-arduino-linux
122+
if: github.event_name == 'push' && github.ref == 'refs/heads/release/v2.x'
123+
runs-on: ubuntu-latest
124+
steps:
125+
# Check out repository
126+
- name: Checkout repository
127+
uses: actions/checkout@v4
128+
with:
129+
token: ${{secrets.GITHUB_TOKEN}}
130+
fetch-depth: '0'
131+
132+
- name: Switch branch
133+
run:
134+
git checkout remotes/origin/gh-pages
135+
136+
- name: Download sketches reports artifact
137+
uses: actions/download-artifact@v4
138+
with:
139+
pattern: pr_cli_compile_*
140+
merge-multiple: true
141+
path: v2.x_cli_compile
142+
143+
- name: List files in the directory
144+
run: ls -R
145+
146+
- name: Commit json files to gh-pages if on release branch
147+
if: github.event_name == 'push' && github.ref == 'refs/heads/release/v2.x'
148+
run: |
149+
git config user.name github-actions
150+
git config user.email [email protected]
151+
git add --all
152+
git commit -m "Updated 2.x cli compile json files"
153+
git push origin HEAD:gh-pages

0 commit comments

Comments
 (0)