Skip to content

Commit 1daf8f9

Browse files
per1234aentinger
authored andcommitted
Allow sketch paths to be specified
The previous behavior was to recursively search the examples folder for sketches and compile all of them. The sketch-paths input added here allows the user to specify specific paths to search for sketches. The default value of the input is "examples" so it is completely backwards compatible. An example of the application for this feature is when sketches are specific to different boards.
1 parent f522696 commit 1daf8f9

File tree

3 files changed

+108
-89
lines changed

3 files changed

+108
-89
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ For 3rd party boards, also specify the Boards Manager URL:
2020

2121
List of library dependencies to install (space separated). Default `""`.
2222

23+
### `sketch-paths`
24+
25+
List of paths containing sketches to compile. These paths will be searched recursively. Default `"examples"`.
26+
2327
### `github-token`
2428

2529
GitHub access token used to get information from the GitHub API. Only needed if you're using the size report features with private repositories. It will be convenient to use [`${{ secrets.GITHUB_TOKEN }}`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token). Default `""`.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
libraries:
1111
description: 'List of library dependencies to install (space separated)'
1212
default: ''
13+
sketch-paths:
14+
description: 'List of paths containing sketches to compile.'
15+
default: 'examples'
1316
github-token:
1417
description: 'GitHub access token used to get information from the GitHub API. Only needed if you are using the size report features with private repositories.'
1518
default: ''
@@ -41,6 +44,7 @@ runs:
4144
- ${{ inputs.cli-version }}
4245
- ${{ inputs.fqbn }}
4346
- ${{ inputs.libraries }}
47+
- ${{ inputs.sketch-paths }}
4448
- ${{ inputs.github-token }}
4549
- ${{ inputs.size-report-sketch }}
4650
- ${{ inputs.enable-size-deltas-report }}

entrypoint.sh

Lines changed: 100 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
readonly CLI_VERSION="${1}"
44
readonly FQBN_ARG="${2}"
55
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}"
1314

1415
readonly SIZE_NOT_APPLICABLE_INDICATOR='"N/A"'
1516

@@ -25,6 +26,8 @@ readonly CORE="$(echo "$FQBN" | cut --delimiter=':' --fields=1,2)"
2526
# Additional Boards Manager URL
2627
readonly ADDITIONAL_URL="${FQBN_ARRAY[1]}"
2728

29+
declare -a -r SKETCH_PATHS_ARRAY="(${SKETCH_PATHS})"
30+
2831
function compile_example() {
2932
local -r examplePath="$1"
3033
arduino-cli compile --verbose --warnings all --fqbn "$FQBN" "$examplePath" || {
@@ -179,101 +182,109 @@ fi
179182
mkdir --parents "$HOME/Arduino/libraries"
180183
ln --symbolic "$PWD" "$HOME/Arduino/libraries/."
181184

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
187185
# Set default exit status
188186
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"
210187

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
224193

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"
226201

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="$?"
242206
}
207+
continue
208+
elif [[ ("$ENABLE_SIZE_DELTAS_REPORT" == "true" || "$ENABLE_SIZE_TRENDS_REPORT" == "true") && "${EXAMPLE##*/}" == "$SIZE_REPORT_SKETCH" ]]; then
209+
# Do determine size
243210

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+
}
246216
check_sizes
247217

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+
}
258227
fi
259-
echo "Change in RAM used by globals: $RAM_DELTA"
260228

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+
}
265285
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-
}
275286
fi
276-
fi
287+
done
277288
done
278289

279290
exit $SCRIPT_EXIT_STATUS

0 commit comments

Comments
 (0)