From 07da999357fc5efe4fe3cfd4d53284895426d104 Mon Sep 17 00:00:00 2001 From: Vandit Singh Date: Sun, 17 Mar 2024 21:42:18 +0530 Subject: [PATCH 1/2] update verify shellcheck to reduce the time to less than 15min --- hack/verify-shellcheck.sh | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index c566f772e9..b4850dbf91 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -17,11 +17,44 @@ # allow overriding docker cli, which should work fine for this script DOCKER="${DOCKER:-docker}" + SHELLCHECK_VERSION="0.9.0" SHELLCHECK_IMAGE="docker.io/koalaman/shellcheck-alpine:v0.9.0@sha256:e19ed93c22423970d56568e171b4512c9244fc75dd9114045016b4a0073ac4b7" +# common arguments we'll pass to shellcheck +SHELLCHECK_OPTIONS=( + # allow following sourced files that are not specified in the command, + # we need this because we specify one file at a time in order to trivially + # detect which files are failing + "--external-sources" + # include our disabled lints + "--exclude=${SHELLCHECK_DISABLED}" + # set colorized output + "--color=${SHELLCHECK_COLORIZED_OUTPUT}" +) + # Currently disabled these errors will take care of them later -DISABLED_ERRORS="SC2002,SC3028,SC3054,SC3014,SC3040,SC3046,SC3030,SC3010,SC3037,SC3045,SC3006,SC3018,SC3016,SC3011,SC3044,SC3043,SC3060,SC3024,SC1091,SC2066,SC2086,SC2034,SC1083,SC1009,SC1073,SC1072,SC2155,SC2046" +SHELLCHECK_DISABLED="SC2002,SC3028,SC3054,SC3014,SC3040,SC3046,SC3030,SC3010,SC3037,SC3045,SC3006,SC3018,SC3016,SC3011,SC3044,SC3043,SC3060,SC3024,SC1091,SC2066,SC2086,SC2034,SC1083,SC1009,SC1073,SC1072,SC2155,SC2046" + +scripts_to_check=("$@") +if [[ "$#" == 0 ]]; then + # Find all shell scripts excluding: + # - Anything git-ignored - No need to lint untracked files. + # - ./_* - No need to lint output directories. + # - ./.git/* - Ignore anything in the git object store. + # - ./vendor* - Vendored code should be fixed upstream instead. + # - ./third_party/*, but re-include ./third_party/forked/* - only code we + # forked should be linted and fixed. + while IFS=$'\n' read -r script; + do git check-ignore -q "$script" || scripts_to_check+=("$script"); + done < <(find . -name "*.sh" \ + -not \( \ + -path ./_\* -o \ + -path ./.git\* -o \ + -path ./vendor\* -o \ + \( -path ./third_party\* -a -not -path ./third_party/forked\* \) \ + \)) +fi # Download shellcheck-alpine from Docker Hub echo "Downloading ShellCheck Docker image..." @@ -29,6 +62,9 @@ echo "Downloading ShellCheck Docker image..." # Run ShellCheck on all shell script files, excluding those in the 'vendor' directory echo "Running ShellCheck..." -"${DOCKER}" run --rm -v "$(pwd):$(pwd)" -w "$(pwd)" "${SHELLCHECK_IMAGE}" \ - find .. -type f -name '*.sh' -exec shellcheck --exclude="$DISABLED_ERRORS" {} + +"${DOCKER}" run \ + --rm -v "$(pwd)" -w "$(pwd)" \ + "${SHELLCHECK_IMAGE}" \ + shellcheck "${SHELLCHECK_OPTIONS[@]}" "${scripts_to_check[@]}" >&2 || res=$? + echo "Shellcheck ran successfully" From 621a636fdd85fd093ea2bd1196c27e7bd3854e70 Mon Sep 17 00:00:00 2001 From: Vandit Singh Date: Tue, 19 Mar 2024 02:55:14 +0530 Subject: [PATCH 2/2] put disabled_errors on the correct line --- hack/verify-shellcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index b4850dbf91..1bd17cebc8 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -21,6 +21,7 @@ DOCKER="${DOCKER:-docker}" SHELLCHECK_VERSION="0.9.0" SHELLCHECK_IMAGE="docker.io/koalaman/shellcheck-alpine:v0.9.0@sha256:e19ed93c22423970d56568e171b4512c9244fc75dd9114045016b4a0073ac4b7" +SHELLCHECK_DISABLED="SC2002,SC3028,SC3054,SC3014,SC3040,SC3046,SC3030,SC3010,SC3037,SC3045,SC3006,SC3018,SC3016,SC3011,SC3044,SC3043,SC3060,SC3024,SC1091,SC2066,SC2086,SC2034,SC1083,SC1009,SC1073,SC1072,SC2155,SC2046" # common arguments we'll pass to shellcheck SHELLCHECK_OPTIONS=( # allow following sourced files that are not specified in the command, @@ -34,7 +35,6 @@ SHELLCHECK_OPTIONS=( ) # Currently disabled these errors will take care of them later -SHELLCHECK_DISABLED="SC2002,SC3028,SC3054,SC3014,SC3040,SC3046,SC3030,SC3010,SC3037,SC3045,SC3006,SC3018,SC3016,SC3011,SC3044,SC3043,SC3060,SC3024,SC1091,SC2066,SC2086,SC2034,SC1083,SC1009,SC1073,SC1072,SC2155,SC2046" scripts_to_check=("$@") if [[ "$#" == 0 ]]; then