From 57970684fa8726848872a6a338b0ae2209acde26 Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Sun, 14 Nov 2021 00:11:58 +0100 Subject: [PATCH 1/2] Improve exit code handling --- script.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/script.sh b/script.sh index 3be6f58..85c1336 100755 --- a/script.sh +++ b/script.sh @@ -47,7 +47,8 @@ if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE=$? + ${INPUT_REVIEWDOG_FLAGS} + EXIT_CODE=$? else # github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation. # shellcheck disable=SC2086 @@ -59,7 +60,8 @@ else -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE=$? + ${INPUT_REVIEWDOG_FLAGS} + EXIT_CODE=$? fi echo '::endgroup::' @@ -74,9 +76,10 @@ shellcheck -f diff ${FILES} \ -reporter="github-pr-review" \ -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ - ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE_SUGGESTION=$? + ${INPUT_REVIEWDOG_FLAGS} +EXIT_CODE_SUGGESTION=$? echo '::endgroup::' -if [ -n "${EXIT_CODE}" ] || [ -n "${EXIT_CODE_SUGGESTION}" ]; then - exit 1 +if [ "${EXIT_CODE}" -ne 0 ] || [ "${EXIT_CODE_SUGGESTION}" -ne 0 ]; then + exit $((EXIT_CODE + EXIT_CODE_SUGGESTION)) fi From cde79b03250072b659354a69ad285a6f6110fbda Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Sun, 14 Nov 2021 01:00:30 +0100 Subject: [PATCH 2/2] Treat unset variables as an error when substituting --- script.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script.sh b/script.sh index 85c1336..6e9f232 100755 --- a/script.sh +++ b/script.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -u + echo '::group:: Installing shellcheck ... https://github.com/koalaman/shellcheck' TEMP_PATH="$(mktemp -d)" cd "${TEMP_PATH}" || exit @@ -27,12 +29,12 @@ if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then fi # Exit early if no files have been found -if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang}" ]; then +if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then echo "No matching files found to check." exit 0 fi -FILES="${files_with_pattern} ${files_with_shebang}" +FILES="${files_with_pattern} ${files_with_shebang:-}" echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then