Skip to content

Commit 0219c21

Browse files
authored
[CI] Get sizes from push workflow, updated build scripts (espressif#9524)
* Remove event-file from External libs wf * Add compilation log to the build scripts * Add 2nd compilation run on base branch * Fix sketch_utils script * Update on-push.sh * Update Push workflow * Upload pr number in lib.yml * Fix PR number in publish sizes * Update external libs results with pr num file
1 parent e33543c commit 0219c21

File tree

6 files changed

+215
-31
lines changed

6 files changed

+215
-31
lines changed

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

+31-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function build(){
99
local fqbn=$2
1010
local chunk_index=$3
1111
local chunks_cnt=$4
12-
shift; shift; shift; shift;
12+
local build_log=$5
13+
shift; shift; shift; shift; shift;
1314
local sketches=$*
1415

1516
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
@@ -22,6 +23,9 @@ function build(){
2223
if [ "$OS_IS_LINUX" == "1" ]; then
2324
args+=" -p $ARDUINO_ESP32_PATH/libraries"
2425
args+=" -i $chunk_index -m $chunks_cnt"
26+
if [ $build_log -eq 1 ]; then
27+
args+=" -l $build_log"
28+
fi
2529
${BUILD_SKETCHES} ${args}
2630
else
2731
for sketch in ${sketches}; do
@@ -45,6 +49,7 @@ fi
4549

4650
CHUNK_INDEX=$1
4751
CHUNKS_CNT=$2
52+
BUILD_LOG=$3
4853
BUILD_PIO=0
4954
if [ "$#" -lt 2 ] || [ "$CHUNKS_CNT" -le 0 ]; then
5055
CHUNK_INDEX=0
@@ -55,6 +60,10 @@ elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
5560
BUILD_PIO=1
5661
fi
5762

63+
if [ "$BUILD_LOG" -le 0 ]; then
64+
BUILD_LOG=0
65+
fi
66+
5867
#echo "Updating submodules ..."
5968
#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
6069

@@ -77,13 +86,28 @@ if [ "$BUILD_PIO" -eq 0 ]; then
7786
$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino\
7887
$ARDUINO_ESP32_PATH/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino\
7988
"
89+
#create sizes_file
90+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$CHUNK_INDEX.json"
8091

81-
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
82-
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
83-
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
84-
build "esp32c6" $FQBN_ESP32C6 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
85-
build "esp32h2" $FQBN_ESP32H2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
86-
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
92+
if [ "$BUILD_LOG" -eq 1 ]; then
93+
#create sizes_file and echo start of JSON array with "boards" key
94+
echo "{\"boards\": [" > $sizes_file
95+
fi
96+
97+
#build sketches for different targets
98+
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
99+
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
100+
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
101+
build "esp32c6" $FQBN_ESP32C6 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
102+
build "esp32h2" $FQBN_ESP32H2 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
103+
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $BUILD_LOG $SKETCHES_ESP32
104+
105+
if [ "$BUILD_LOG" -eq 1 ]; then
106+
#remove last comma from the last JSON object
107+
sed -i '$ s/.$//' "$sizes_file"
108+
#echo end of JSON array
109+
echo "]}" >> $sizes_file
110+
fi
87111
else
88112
source ${SCRIPTS_DIR}/install-platformio-esp32.sh
89113
# PlatformIO ESP32 Test

Diff for: .github/scripts/sketch_utils.sh

+67-3
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
;;
@@ -140,6 +148,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140148
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
141149
fi
142150

151+
output_file="$HOME/.arduino/cli_compile_output.txt"
152+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
153+
143154
mkdir -p "$ARDUINO_CACHE_DIR"
144155
for i in `seq 0 $(($len - 1))`
145156
do
@@ -164,13 +175,39 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
164175
--build-property "compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
165176
--build-cache-path "$ARDUINO_CACHE_DIR" \
166177
--build-path "$build_dir" \
167-
$xtra_opts "${sketchdir}"
178+
$xtra_opts "${sketchdir}" \
179+
> $output_file
168180

169181
exit_status=$?
170182
if [ $exit_status -ne 0 ]; then
171183
echo ""ERROR: Compilation failed with error code $exit_status""
172184
exit $exit_status
173185
fi
186+
187+
if [ $log_compilation ]; then
188+
#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
189+
flash_bytes=$(grep -oE 'Sketch uses ([0-9]+) bytes' $output_file | awk '{print $3}')
190+
flash_percentage=$(grep -oE 'Sketch uses ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk '{print $5}' | tr -d '(%)')
191+
ram_bytes=$(grep -oE 'Global variables use ([0-9]+) bytes' $output_file | awk '{print $4}')
192+
ram_percentage=$(grep -oE 'Global variables use ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk '{print $6}' | tr -d '(%)')
193+
194+
# Extract the directory path excluding the filename
195+
directory_path=$(dirname "$sketch")
196+
# Define the constant part
197+
constant_part="/home/runner/Arduino/hardware/espressif/esp32/libraries/"
198+
# Extract the desired substring using sed
199+
lib_sketch_name=$(echo "$directory_path" | sed "s|$constant_part||")
200+
#append json file where key is fqbn, sketch name, sizes -> extracted values
201+
echo "{\"name\": \"$lib_sketch_name\",
202+
\"sizes\": [{
203+
\"flash_bytes\": $flash_bytes,
204+
\"flash_percentage\": $flash_percentage,
205+
\"ram_bytes\": $ram_bytes,
206+
\"ram_percentage\": $ram_percentage
207+
}]
208+
}," >> "$sizes_file"
209+
fi
210+
174211
elif [ -f "$ide_path/arduino-builder" ]; then
175212
echo "Building $sketchname with arduino-builder and FQBN=$currfqbn"
176213
echo "Build path = $build_dir"
@@ -204,6 +241,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
204241
# $xtra_opts "${sketchdir}/${sketchname}.ino"
205242
fi
206243
done
244+
207245
unset fqbn
208246
unset xtra_opts
209247
unset options
@@ -277,6 +315,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
277315
shift
278316
chunk_max=$1
279317
;;
318+
-l )
319+
shift
320+
log_compilation=$1
321+
;;
280322
* )
281323
break
282324
;;
@@ -340,8 +382,19 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
340382
echo "Start Sketch: $start_num"
341383
echo "End Sketch : $end_index"
342384

385+
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
386+
if [ $log_compilation ]; then
387+
#echo board,target and start of sketches to sizes_file json
388+
echo "{ \"board\": \"$fqbn\",
389+
\"target\": \"$target\",
390+
\"sketches\": [" >> "$sizes_file"
391+
fi
392+
343393
local sketchnum=0
344-
args+=" -ai $ide_path -au $user_path"
394+
args+=" -ai $ide_path -au $user_path -i $chunk_index"
395+
if [ $log_compilation ]; then
396+
args+=" -l $log_compilation"
397+
fi
345398
for sketch in $sketches; do
346399
local sketchdir=$(dirname $sketch)
347400
local sketchdirname=$(basename $sketchdir)
@@ -358,6 +411,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
358411
return $result
359412
fi
360413
done
414+
415+
if [ $log_compilation ]; then
416+
#remove last comma from json
417+
if [ $i -eq $(($len - 1)) ]; then
418+
sed -i '$ s/.$//' "$sizes_file"
419+
fi
420+
#echo end of sketches sizes_file json
421+
echo "]" >> "$sizes_file"
422+
#echo end of board sizes_file json
423+
echo "}," >> "$sizes_file"
424+
fi
425+
361426
return 0
362427
}
363428

@@ -389,4 +454,3 @@ case "$cmd" in
389454
echo "$USAGE"
390455
exit 2
391456
esac
392-

Diff for: .github/workflows/lib.yml

+16-11
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,21 @@ jobs:
121121
git add ${{ env.RESULT_LIBRARY_TEST_FILE }}
122122
git commit -m "Generated External Libraries Test Results"
123123
git push origin HEAD:gh-pages
124-
125-
event_file:
126-
name: "Event File"
127-
if: |
128-
contains(github.event.pull_request.labels.*.name, 'lib_test')
129-
needs: compile-sketch
124+
125+
#Upload PR number as artifact
126+
upload-pr-number:
127+
name: Upload PR number
128+
if: github.event_name == 'pull_request'
130129
runs-on: ubuntu-latest
131130
steps:
132-
- name: Upload
133-
uses: actions/upload-artifact@v4
134-
with:
135-
name: Event File
136-
path: ${{github.event_path}}
131+
- name: Save the PR number in an artifact
132+
shell: bash
133+
env:
134+
PR_NUM: ${{ github.event.number }}
135+
run: echo $PR_NUM > pr_num.txt
136+
- name: Upload PR number
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: pr_number
140+
path: ./pr_num.txt
141+
overwrite: true

Diff for: .github/workflows/publishlib.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
# It's convenient to set variables for values used multiple times in the workflow
1212
SKETCHES_REPORTS_PATH: artifacts/libraries-report
1313
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
14-
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
1514

1615
jobs:
1716
lib-test-results:
@@ -26,21 +25,32 @@ jobs:
2625
run: |
2726
mkdir -p artifacts && cd artifacts
2827
mkdir -p libraries-report
28+
mkdir -p workflows
2929
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
3030
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
3131
do
3232
IFS=$'\t' read name url <<< "$artifact"
3333
gh api $url > "$name.zip"
3434
unzip -j "$name.zip" -d "temp_$name"
35-
mv "temp_$name"/* libraries-report
35+
if [[ "$name" == "pr_num" ]]; then
36+
mv "temp_$name"/* workflows
37+
else
38+
mv "temp_$name"/* libraries-report
39+
fi
3640
rm -r "temp_$name"
3741
done
3842
echo "Contents of parent directory:"
3943
ls -R ..
44+
45+
- name: Read the pr_num file
46+
id: pr_num_reader
47+
uses: juliangruber/read-file-action@v1
48+
with:
49+
path: ./artifacts/workflows/pr_num.txt
4050

4151
- name: Report results
4252
uses: P-R-O-C-H-Y/report-size-deltas@libs
4353
with:
4454
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
4555
github-token: ${{ env.GITHUB_TOKEN }}
46-
pr-number: ${{ env.PR_NUMBER }}
56+
pr-number: "${{ steps.pr_num_reader.outputs.content }}"

Diff for: .github/workflows/publishsizes.yml

+24-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
# It's convenient to set variables for values used multiple times in the workflow
1212
SKETCHES_REPORTS_PATH: artifacts/sizes-report
1313
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
14-
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
1514

1615
jobs:
1716
sizes-test-results:
@@ -22,21 +21,34 @@ jobs:
2221
github.event.workflow_run.conclusion == 'success'
2322
2423
steps:
25-
- name: Download and Extract Artifacts
24+
- name: Checkout code
25+
uses: actions/checkout@v4 # This step checks out the repository's code at gh-pages branch
26+
with:
27+
ref: gh-pages
28+
29+
- name: Create folder structure
2630
run: |
2731
mkdir -p artifacts && cd artifacts
2832
mkdir -p sizes-report
2933
mkdir -p sizes-report/master
3034
mkdir -p sizes-report/pr
35+
36+
- name: Download JSON file
37+
run: |
38+
mv master_cli_compile/*.json artifacts/sizes-report/master/
39+
40+
- name: Download and Extract Artifacts
41+
run: |
42+
cd artifacts
3143
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
3244
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
3345
do
3446
IFS=$'\t' read name url <<< "$artifact"
3547
gh api $url > "$name.zip"
3648
unzip -j "$name.zip" -d "temp_$name"
37-
if [[ "$name" == *"master"* ]]; then
38-
mv "temp_$name"/* sizes-report/master
39-
elif [[ "$name" == *"pr"* ]]; then
49+
if [[ "$name" == "pr_num" ]]; then
50+
mv "temp_$name"/* sizes-report
51+
elif [[ "$name" == "pr_cli"* ]]; then
4052
mv "temp_$name"/* sizes-report/pr
4153
else
4254
mv "temp_$name"/* sizes-report
@@ -45,10 +57,16 @@ jobs:
4557
done
4658
echo "Contents of parent directory:"
4759
ls -R ..
60+
61+
- name: Read the pr_num file
62+
id: pr_num_reader
63+
uses: juliangruber/read-file-action@v1
64+
with:
65+
path: ./artifacts/sizes-report/pr_num.txt
4866

4967
- name: Report results
5068
uses: P-R-O-C-H-Y/report-size-deltas@sizes_v2
5169
with:
5270
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
5371
github-token: ${{ env.GITHUB_TOKEN }}
54-
pr-number: ${{ env.PR_NUMBER }}
72+
pr-number: "${{ steps.pr_num_reader.outputs.content }}"

0 commit comments

Comments
 (0)