Make verify-shellcheck take optional args

This commit is contained in:
Tim Hockin 2024-01-07 11:16:28 -08:00
parent 19b37f046f
commit 2c0da11c0a
No known key found for this signature in database

View File

@ -57,23 +57,25 @@ readonly SHELLCHECK_DISABLED
# ensure we're linting the k8s source tree # ensure we're linting the k8s source tree
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
# Find all shell scripts excluding: scripts_to_check=("$@")
# - Anything git-ignored - No need to lint untracked files. if [[ "$#" == 0 ]]; then
# - ./_* - No need to lint output directories. # Find all shell scripts excluding:
# - ./.git/* - Ignore anything in the git object store. # - Anything git-ignored - No need to lint untracked files.
# - ./vendor* - Vendored code should be fixed upstream instead. # - ./_* - No need to lint output directories.
# - ./third_party/*, but re-include ./third_party/forked/* - only code we # - ./.git/* - Ignore anything in the git object store.
# forked should be linted and fixed. # - ./vendor* - Vendored code should be fixed upstream instead.
all_shell_scripts=() # - ./third_party/*, but re-include ./third_party/forked/* - only code we
while IFS=$'\n' read -r script; # forked should be linted and fixed.
do git check-ignore -q "$script" || all_shell_scripts+=("$script"); while IFS=$'\n' read -r script;
done < <(find . -name "*.sh" \ do git check-ignore -q "$script" || scripts_to_check+=("$script");
-not \( \ done < <(find . -name "*.sh" \
-path ./_\* -o \ -not \( \
-path ./.git\* -o \ -path ./_\* -o \
-path ./vendor\* -o \ -path ./.git\* -o \
\( -path ./third_party\* -a -not -path ./third_party/forked\* \) \ -path ./vendor\* -o \
\)) \( -path ./third_party\* -a -not -path ./third_party/forked\* \) \
\))
fi
# detect if the host machine has the required shellcheck version installed # detect if the host machine has the required shellcheck version installed
# if so, we will use that instead. # if so, we will use that instead.
@ -110,13 +112,13 @@ SHELLCHECK_OPTIONS=(
res=0 res=0
if ${HAVE_SHELLCHECK}; then if ${HAVE_SHELLCHECK}; then
echo "Using host shellcheck ${SHELLCHECK_VERSION} binary." echo "Using host shellcheck ${SHELLCHECK_VERSION} binary."
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$? shellcheck "${SHELLCHECK_OPTIONS[@]}" "${scripts_to_check[@]}" >&2 || res=$?
else else
echo "Using shellcheck ${SHELLCHECK_VERSION} docker image." echo "Using shellcheck ${SHELLCHECK_VERSION} docker image."
"${DOCKER}" run \ "${DOCKER}" run \
--rm -v "${KUBE_ROOT}:${KUBE_ROOT}" -w "${KUBE_ROOT}" \ --rm -v "${KUBE_ROOT}:${KUBE_ROOT}" -w "${KUBE_ROOT}" \
"${SHELLCHECK_IMAGE}" \ "${SHELLCHECK_IMAGE}" \
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$? shellcheck "${SHELLCHECK_OPTIONS[@]}" "${scripts_to_check[@]}" >&2 || res=$?
fi fi
# print a message based on the result # print a message based on the result