From 8bfd043ef2ea6d455355e72306058f8faab6606d Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 25 Sep 2021 08:09:52 +0000 Subject: [PATCH 1/3] Support suggestion --- script.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/script.sh b/script.sh index 2251fc2..01ec109 100755 --- a/script.sh +++ b/script.sh @@ -13,9 +13,12 @@ cd "${GITHUB_WORKSPACE}" || exit export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +FILES=$(find "${INPUT_PATH:-'.'}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN:-'*.sh'}") + +echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then # erroformat: https://git.io/JeGMU - shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} $(find "${INPUT_PATH:-'.'}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN:-'*.sh'}") \ + shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \ | jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message) [SC\(.code)](https://github.com/koalaman/shellcheck/wiki/SC\(.code))"' \ | reviewdog \ -efm="%f:%l:%c:%t%*[^:]:%m" \ @@ -24,10 +27,10 @@ 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} + ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE=$? else # github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation. - shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} $(find "${INPUT_PATH:-'.'}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN:-'*.sh'}") \ + shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \ | reviewdog \ -f="checkstyle" \ -name="shellcheck" \ @@ -35,5 +38,23 @@ else -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} + ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE=$? +fi +echo '::endgroup::' + +echo '::group:: Running shellcheck (suggestion) ...' +# -reporter must be github-pr-review for the suggestion feature. +shellcheck -f diff ${FILES} \ + | reviewdog \ + -name="shellcheck (suggestion)" \ + -f=diff \ + -f.diff.strip=1 \ + -reporter="github-pr-review" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE_SUGGESTION=$? +echo '::endgroup::' + +if [ "${EXIT_CODE}" != 0 ] || [ "${EXIT_CODE_SUGGESTION}" != 0 ]; then + exit 1 fi From 6ea64ea89588504b2c5b80497e3354b73fff7cab Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 25 Sep 2021 08:17:37 +0000 Subject: [PATCH 2/3] fix exit code handling --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 01ec109..e00039d 100755 --- a/script.sh +++ b/script.sh @@ -55,6 +55,6 @@ shellcheck -f diff ${FILES} \ ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE_SUGGESTION=$? echo '::endgroup::' -if [ "${EXIT_CODE}" != 0 ] || [ "${EXIT_CODE_SUGGESTION}" != 0 ]; then +if [ -n "${EXIT_CODE}" ] || [ -n "${EXIT_CODE_SUGGESTION}" ]; then exit 1 fi From ea324dc6ebc2e1408b5c1a8ba0838920e58addf1 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 25 Sep 2021 08:51:40 +0000 Subject: [PATCH 3/3] disable SC2086 --- script.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script.sh b/script.sh index e00039d..f7733c7 100755 --- a/script.sh +++ b/script.sh @@ -18,6 +18,7 @@ FILES=$(find "${INPUT_PATH:-'.'}" -not -path "${INPUT_EXCLUDE}" -type f -name "$ echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then # erroformat: https://git.io/JeGMU + # shellcheck disable=SC2086 shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \ | jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message) [SC\(.code)](https://github.com/koalaman/shellcheck/wiki/SC\(.code))"' \ | reviewdog \ @@ -30,6 +31,7 @@ if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then ${INPUT_REVIEWDOG_FLAGS} || EXIT_CODE=$? else # github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation. + # shellcheck disable=SC2086 shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \ | reviewdog \ -f="checkstyle" \ @@ -44,6 +46,7 @@ echo '::endgroup::' echo '::group:: Running shellcheck (suggestion) ...' # -reporter must be github-pr-review for the suggestion feature. +# shellcheck disable=SC2086 shellcheck -f diff ${FILES} \ | reviewdog \ -name="shellcheck (suggestion)" \