3
3
readonly CLI_VERSION=" ${1} "
4
4
readonly FQBN_ARG=" ${2} "
5
5
readonly LIBRARIES=" ${3} "
6
- readonly GH_TOKEN=" ${4} "
7
- readonly SIZE_REPORT_SKETCH=" ${5} "
8
- ENABLE_SIZE_DELTAS_REPORT=" ${6} "
9
- readonly SIZE_DELTAS_REPORT_FOLDER_NAME=" ${7} "
10
- ENABLE_SIZE_TRENDS_REPORT=" ${8} "
11
- readonly SIZE_TRENDS_REPORT_SPREADSHEET_ID=" ${9} "
12
- readonly SIZE_TRENDS_REPORT_SHEET_NAME=" ${10} "
6
+ readonly SKETCH_PATHS=" ${4} "
7
+ readonly GH_TOKEN=" ${5} "
8
+ readonly SIZE_REPORT_SKETCH=" ${6} "
9
+ ENABLE_SIZE_DELTAS_REPORT=" ${7} "
10
+ readonly SIZE_DELTAS_REPORT_FOLDER_NAME=" ${8} "
11
+ ENABLE_SIZE_TRENDS_REPORT=" ${9} "
12
+ readonly SIZE_TRENDS_REPORT_SPREADSHEET_ID=" ${10} "
13
+ readonly SIZE_TRENDS_REPORT_SHEET_NAME=" ${11} "
13
14
14
15
readonly SIZE_NOT_APPLICABLE_INDICATOR=' "N/A"'
15
16
@@ -25,6 +26,8 @@ readonly CORE="$(echo "$FQBN" | cut --delimiter=':' --fields=1,2)"
25
26
# Additional Boards Manager URL
26
27
readonly ADDITIONAL_URL=" ${FQBN_ARRAY[1]} "
27
28
29
+ declare -a -r SKETCH_PATHS_ARRAY=" (${SKETCH_PATHS} )"
30
+
28
31
function compile_example() {
29
32
local -r examplePath=" $1 "
30
33
arduino-cli compile --verbose --warnings all --fqbn " $FQBN " " $examplePath " || {
@@ -179,101 +182,109 @@ fi
179
182
mkdir --parents " $HOME /Arduino/libraries"
180
183
ln --symbolic " $PWD " " $HOME /Arduino/libraries/."
181
184
182
- # Find all the examples and loop build each
183
- readonly EXAMPLES=" $( find " examples/" -name ' *.ino' -print0 | xargs --null dirname | uniq) "
184
- if [[ " $EXAMPLES " == " " ]]; then
185
- exit 1
186
- fi
187
185
# Set default exit status
188
186
SCRIPT_EXIT_STATUS=0
189
- for EXAMPLE in $EXAMPLES ; do
190
- echo " Building example $EXAMPLE "
191
-
192
- if [[ (" $ENABLE_SIZE_DELTAS_REPORT " ! = " true" && " $ENABLE_SIZE_TRENDS_REPORT " ! = " true" ) || " ${EXAMPLE##*/ } " != " $SIZE_REPORT_SKETCH " ]]; then
193
- # Don't determine size
194
- compile_example " $EXAMPLE " || {
195
- SCRIPT_EXIT_STATUS=" $? "
196
- }
197
- continue
198
- elif [[ (" $ENABLE_SIZE_DELTAS_REPORT " == " true" || " $ENABLE_SIZE_TRENDS_REPORT " == " true" ) && " ${EXAMPLE##*/ } " == " $SIZE_REPORT_SKETCH " ]]; then
199
- # Do determine size
200
-
201
- # Determine memory usage of the sketch at the tip of the pull request branch
202
- compile_example_get_size_from_output " $EXAMPLE " || {
203
- SCRIPT_EXIT_STATUS=" $? "
204
- continue
205
- }
206
- check_sizes
207
-
208
- readonly CURRENT_FLASH_SIZE=" $FLASH_SIZE "
209
- readonly CURRENT_RAM_SIZE=" $RAM_SIZE "
210
187
211
- if [[ " $ENABLE_SIZE_TRENDS_REPORT " == " true" ]]; then
212
- readonly SHORT_COMMIT_HASH=" $( git rev-parse --short HEAD) "
213
- python3 /reportsizetrends/reportsizetrends.py --spreadsheet-id " $SIZE_TRENDS_REPORT_SPREADSHEET_ID " --sheet-name " $SIZE_TRENDS_REPORT_SHEET_NAME " --google-key-file " $INPUT_KEYFILE " --sketch-name=" $EXAMPLE " --commit-hash=" $SHORT_COMMIT_HASH " --commit-url=" https://github.com/${GITHUB_REPOSITORY} /commit/${SHORT_COMMIT_HASH} " --fqbn=" $FQBN " --flash=" $CURRENT_FLASH_SIZE " --ram=" $CURRENT_RAM_SIZE " || {
214
- echo " ::error::Could not update size trends report spreadsheet"
215
- exit 1
216
- }
217
- fi
218
-
219
- if [[ " $ENABLE_SIZE_DELTAS_REPORT " == " true" ]]; then
220
- # Determine memory usage of the sketch at the tip of the target repository's default branch
221
-
222
- # Save the commit hash for the tip of the pull request branch
223
- readonly CURRENT_COMMIT=" $( git rev-parse HEAD) "
188
+ for SKETCH_PATH in " ${SKETCH_PATHS_ARRAY[@]} " ; do
189
+ if [[ ! -e " $SKETCH_PATH " ]]; then
190
+ echo " ::error::$SKETCH_PATH doesn't exist"
191
+ exit 1
192
+ fi
224
193
225
- # checkout the tip of the pull request's base branch
194
+ # Find all the examples and loop build each
195
+ EXAMPLES=" $( find " $SKETCH_PATH " -name ' *.ino' -print0 | xargs --null dirname | uniq) "
196
+ if [[ " $EXAMPLES " == " " ]]; then
197
+ exit 1
198
+ fi
199
+ for EXAMPLE in $EXAMPLES ; do
200
+ echo " Building example $EXAMPLE "
226
201
227
- # Determine the pull request number, to use for the GitHub API request
228
- readonly PULL_REQUEST_NUMBER=" $( jq --raw-output ' .pull_request.number' " $GITHUB_EVENT_PATH " ) "
229
- if [[ " $GH_TOKEN " == " " ]]; then
230
- # Access token is not needed for public repositories
231
- readonly BASE_BRANCH_NAME=" $( curl " https://api.github.com/repos/${GITHUB_REPOSITORY} /pulls/${PULL_REQUEST_NUMBER} " | jq --raw-output .base.ref) "
232
- else
233
- readonly BASE_BRANCH_NAME=" $( curl --header " Authorization: token ${GH_TOKEN} " " https://api.github.com/repos/${GITHUB_REPOSITORY} /pulls/${PULL_REQUEST_NUMBER} " | jq --raw-output .base.ref) "
234
- fi
235
- if [[ " $BASE_BRANCH_NAME " == " null" ]]; then
236
- echo " ::error::Unable to determine base branch name. Please specify the size-report-github-token argument in your workflow configuration."
237
- exit 1
238
- fi
239
- git checkout " $BASE_BRANCH_NAME " || {
240
- echo " ::error::Failed to checkout base branch"
241
- exit 1
202
+ if [[ (" $ENABLE_SIZE_DELTAS_REPORT " ! = " true" && " $ENABLE_SIZE_TRENDS_REPORT " ! = " true" ) || " ${EXAMPLE##*/ } " != " $SIZE_REPORT_SKETCH " ]]; then
203
+ # Don't determine size
204
+ compile_example " $EXAMPLE " || {
205
+ SCRIPT_EXIT_STATUS=" $? "
242
206
}
207
+ continue
208
+ elif [[ (" $ENABLE_SIZE_DELTAS_REPORT " == " true" || " $ENABLE_SIZE_TRENDS_REPORT " == " true" ) && " ${EXAMPLE##*/ } " == " $SIZE_REPORT_SKETCH " ]]; then
209
+ # Do determine size
243
210
244
- # Compile the example sketch and get the sizes
245
- compile_example_get_size_from_output " $EXAMPLE "
211
+ # Determine memory usage of the sketch at the tip of the pull request branch
212
+ compile_example_get_size_from_output " $EXAMPLE " || {
213
+ SCRIPT_EXIT_STATUS=" $? "
214
+ continue
215
+ }
246
216
check_sizes
247
217
248
- if [[ " $CURRENT_FLASH_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " || " $FLASH_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " ]]; then
249
- FLASH_DELTA=" $SIZE_NOT_APPLICABLE_INDICATOR "
250
- else
251
- FLASH_DELTA=" $(( CURRENT_FLASH_SIZE - FLASH_SIZE)) "
252
- fi
253
- echo " Change in flash memory usage: $FLASH_DELTA "
254
- if [[ " $CURRENT_RAM_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " || " $RAM_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " ]]; then
255
- RAM_DELTA=" $SIZE_NOT_APPLICABLE_INDICATOR "
256
- else
257
- RAM_DELTA=" $(( CURRENT_RAM_SIZE - RAM_SIZE)) "
218
+ readonly CURRENT_FLASH_SIZE=" $FLASH_SIZE "
219
+ readonly CURRENT_RAM_SIZE=" $RAM_SIZE "
220
+
221
+ if [[ " $ENABLE_SIZE_TRENDS_REPORT " == " true" ]]; then
222
+ readonly SHORT_COMMIT_HASH=" $( git rev-parse --short HEAD) "
223
+ python3 /reportsizetrends/reportsizetrends.py --spreadsheet-id " $SIZE_TRENDS_REPORT_SPREADSHEET_ID " --sheet-name " $SIZE_TRENDS_REPORT_SHEET_NAME " --google-key-file " $INPUT_KEYFILE " --sketch-name=" $EXAMPLE " --commit-hash=" $SHORT_COMMIT_HASH " --commit-url=" https://github.com/${GITHUB_REPOSITORY} /commit/${SHORT_COMMIT_HASH} " --fqbn=" $FQBN " --flash=" $CURRENT_FLASH_SIZE " --ram=" $CURRENT_RAM_SIZE " || {
224
+ echo " ::error::Could not update size trends report spreadsheet"
225
+ exit 1
226
+ }
258
227
fi
259
- echo " Change in RAM used by globals: $RAM_DELTA "
260
228
261
- # Create the report folder
262
- readonly SIZE_REPORT_FOLDER_PATH=" ${GITHUB_WORKSPACE} /${SIZE_DELTAS_REPORT_FOLDER_NAME} "
263
- if ! [[ -d " $SIZE_REPORT_FOLDER_PATH " ]]; then
264
- mkdir --parents " $SIZE_REPORT_FOLDER_PATH "
229
+ if [[ " $ENABLE_SIZE_DELTAS_REPORT " == " true" ]]; then
230
+ # Determine memory usage of the sketch at the tip of the target repository's default branch
231
+
232
+ # Save the commit hash for the tip of the pull request branch
233
+ readonly CURRENT_COMMIT=" $( git rev-parse HEAD) "
234
+
235
+ # checkout the tip of the pull request's base branch
236
+
237
+ # Determine the pull request number, to use for the GitHub API request
238
+ readonly PULL_REQUEST_NUMBER=" $( jq --raw-output ' .pull_request.number' " $GITHUB_EVENT_PATH " ) "
239
+ if [[ " $GH_TOKEN " == " " ]]; then
240
+ # Access token is not needed for public repositories
241
+ readonly BASE_BRANCH_NAME=" $( curl " https://api.github.com/repos/${GITHUB_REPOSITORY} /pulls/${PULL_REQUEST_NUMBER} " | jq --raw-output .base.ref) "
242
+ else
243
+ readonly BASE_BRANCH_NAME=" $( curl --header " Authorization: token ${GH_TOKEN} " " https://api.github.com/repos/${GITHUB_REPOSITORY} /pulls/${PULL_REQUEST_NUMBER} " | jq --raw-output .base.ref) "
244
+ fi
245
+ if [[ " $BASE_BRANCH_NAME " == " null" ]]; then
246
+ echo " ::error::Unable to determine base branch name. Please specify the size-report-github-token argument in your workflow configuration."
247
+ exit 1
248
+ fi
249
+ git checkout " $BASE_BRANCH_NAME " || {
250
+ echo " ::error::Failed to checkout base branch"
251
+ exit 1
252
+ }
253
+
254
+ # Compile the example sketch and get the sizes
255
+ compile_example_get_size_from_output " $EXAMPLE "
256
+ check_sizes
257
+
258
+ if [[ " $CURRENT_FLASH_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " || " $FLASH_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " ]]; then
259
+ FLASH_DELTA=" $SIZE_NOT_APPLICABLE_INDICATOR "
260
+ else
261
+ FLASH_DELTA=" $(( CURRENT_FLASH_SIZE - FLASH_SIZE)) "
262
+ fi
263
+ echo " Change in flash memory usage: $FLASH_DELTA "
264
+ if [[ " $CURRENT_RAM_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " || " $RAM_SIZE " == " $SIZE_NOT_APPLICABLE_INDICATOR " ]]; then
265
+ RAM_DELTA=" $SIZE_NOT_APPLICABLE_INDICATOR "
266
+ else
267
+ RAM_DELTA=" $(( CURRENT_RAM_SIZE - RAM_SIZE)) "
268
+ fi
269
+ echo " Change in RAM used by globals: $RAM_DELTA "
270
+
271
+ # Create the report folder
272
+ readonly SIZE_REPORT_FOLDER_PATH=" ${GITHUB_WORKSPACE} /${SIZE_DELTAS_REPORT_FOLDER_NAME} "
273
+ if ! [[ -d " $SIZE_REPORT_FOLDER_PATH " ]]; then
274
+ mkdir --parents " $SIZE_REPORT_FOLDER_PATH "
275
+ fi
276
+ # Create the report file
277
+ readonly SIZE_REPORT_FILE_PATH=" ${SIZE_REPORT_FOLDER_PATH} /${FQBN//:/ -} .json"
278
+ echo " {\" fqbn\" : \" ${FQBN} \" , \" sketch\" : \" ${EXAMPLE} \" , \" previous_flash\" : ${FLASH_SIZE} , \" flash\" : ${CURRENT_FLASH_SIZE} , \" flash_delta\" : ${FLASH_DELTA} , \" previous_ram\" : ${RAM_SIZE} , \" ram\" : ${CURRENT_RAM_SIZE} , \" ram_delta\" : ${RAM_DELTA} }" | jq . > " $SIZE_REPORT_FILE_PATH "
279
+
280
+ # Switch back to the previous commit in the repository
281
+ git checkout " $CURRENT_COMMIT " || {
282
+ echo " ::error::Could not checkout the PR's head branch"
283
+ exit 1
284
+ }
265
285
fi
266
- # Create the report file
267
- readonly SIZE_REPORT_FILE_PATH=" ${SIZE_REPORT_FOLDER_PATH} /${FQBN//:/ -} .json"
268
- echo " {\" fqbn\" : \" ${FQBN} \" , \" sketch\" : \" ${EXAMPLE} \" , \" previous_flash\" : ${FLASH_SIZE} , \" flash\" : ${CURRENT_FLASH_SIZE} , \" flash_delta\" : ${FLASH_DELTA} , \" previous_ram\" : ${RAM_SIZE} , \" ram\" : ${CURRENT_RAM_SIZE} , \" ram_delta\" : ${RAM_DELTA} }" | jq . > " $SIZE_REPORT_FILE_PATH "
269
-
270
- # Switch back to the previous commit in the repository
271
- git checkout " $CURRENT_COMMIT " || {
272
- echo " ::error::Could not checkout the PR's head branch"
273
- exit 1
274
- }
275
286
fi
276
- fi
287
+ done
277
288
done
278
289
279
290
exit $SCRIPT_EXIT_STATUS
0 commit comments