Skip to content

Commit 6ffa8a9

Browse files
committed
De-magic number exit statuses
I find the use of 0 as the success exit status confusing.
1 parent a253288 commit 6ffa8a9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

arduino-ci-script.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ readonly ARDUINO_CI_SCRIPT_HIGHEST_ACCEPTABLE_ARDUINO_EXIT_CODE=4
2525
readonly ARDUINO_CI_SCRIPT_SKETCH_VERIFY_RETRIES=3
2626
readonly ARDUINO_CI_SCRIPT_REPORT_PUSH_RETRIES=10
2727

28+
readonly ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS=0
29+
readonly ARDUINO_CI_SCRIPT_FAILURE_EXIT_STATUS=1
30+
2831

2932
# Create the folder if it doesn't exist
3033
function create_folder()
@@ -621,7 +624,7 @@ function build_sketch()
621624
local -r endIDEversion="$5"
622625

623626
# Set default value for buildSketchExitCode
624-
local buildSketchExitCode=0
627+
local buildSketchExitCode="$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS"
625628

626629
generate_ide_version_list_array "$INSTALLED_IDE_VERSION_LIST_ARRAY" "$startIDEversion" "$endIDEversion"
627630

@@ -709,23 +712,23 @@ function build_this_sketch()
709712
local verifyCount=$((verifyCount + 1))
710713
done
711714

712-
if [[ "$arduinoExitCode" != "0" ]]; then
715+
if [[ "$arduinoExitCode" != "$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS" ]]; then
713716
# Sketch build failed
714717
if [[ "$allowFail" == "true" || "$allowFail" == "require" ]]; then
715718
# Failure is allowed for this test
716-
local -r buildThisSketchExitCode=0
719+
local -r buildThisSketchExitCode="$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS"
717720
else
718721
# Failure is not allowed for this test, fail the Travis build after completing all sketch builds
719-
local -r buildThisSketchExitCode=1
722+
local -r buildThisSketchExitCode="$ARDUINO_CI_SCRIPT_FAILURE_EXIT_STATUS"
720723
fi
721724
else
722725
# Sketch build succeeded
723726
if [[ "$allowFail" == "require" ]]; then
724727
# Failure is required for this test, fail the Travis build after completing all sketch builds
725-
local -r buildThisSketchExitCode=1
728+
local -r buildThisSketchExitCode="$ARDUINO_CI_SCRIPT_FAILURE_EXIT_STATUS"
726729
else
727730
# Success is allowed
728-
local -r buildThisSketchExitCode=0
731+
local -r buildThisSketchExitCode="$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS"
729732
fi
730733

731734
# Parse through the output from the sketch verification to count warnings and determine the compile size
@@ -832,15 +835,15 @@ function publish_report_to_repository()
832835
git commit $ARDUINO_CI_SCRIPT_QUIET_OPTION $ARDUINO_CI_SCRIPT_VERBOSITY_OPTION --message="Add Travis CI job ${TRAVIS_JOB_NUMBER} report (${jobSuccessMessage})" --message="Job log: https://travis-ci.org/${TRAVIS_REPO_SLUG}/jobs/${TRAVIS_JOB_ID}" --message="Commit: https://github.com/${TRAVIS_REPO_SLUG}/commit/${TRAVIS_COMMIT}" --message="$TRAVIS_COMMIT_MESSAGE" --message="[skip ci]"
833836
local gitPushExitCode="1"
834837
local pushCount=0
835-
while [[ "$gitPushExitCode" != "0" && $pushCount -le $ARDUINO_CI_SCRIPT_REPORT_PUSH_RETRIES ]]; do
838+
while [[ "$gitPushExitCode" != "$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS" && $pushCount -le $ARDUINO_CI_SCRIPT_REPORT_PUSH_RETRIES ]]; do
836839
pushCount=$((pushCount + 1))
837840
# Do a pull now in case another job has finished about the same time and pushed a report since the last pull. This would require a merge or rebase. Rebase should be safe since the commits will be separate files.
838841
git pull $ARDUINO_CI_SCRIPT_QUIET_OPTION --rebase
839842
git push $ARDUINO_CI_SCRIPT_QUIET_OPTION $ARDUINO_CI_SCRIPT_VERBOSITY_OPTION "https://${token}@${repositoryURL#*//}"
840843
gitPushExitCode="$?"
841844
done
842845
rm --recursive --force "${HOME}/report-repository"
843-
if [[ "$gitPushExitCode" == "0" ]]; then
846+
if [[ "$gitPushExitCode" == "$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS" ]]; then
844847
if [[ "$doLinkComment" == "true" ]]; then
845848
# Only comment if it's job 1
846849
local -r firstJobRegex="\.1$"

0 commit comments

Comments
 (0)