Don't exit 1 on NON_EXECUTABLE_FILES and check all scripts

This commit is contained in:
Eric Nemchik 2023-02-11 08:37:44 -06:00
parent a3e59f090e
commit db213ee316

View File

@ -1,9 +1,10 @@
#!/bin/bash
# clear preexisting variables not set by job
unset EXECUTABLE_FILES MOUNT_OPTIONS NON_EXECUTABLE_FILES SHELLCHECK_OPTIONS SHELLCKECK_IMAGE TEST_AREA
unset ALL_SHELL_FILES EXECUTABLE_FILES MOUNT_OPTIONS NON_EXECUTABLE_FILES SHELLCHECK_OPTIONS SHELLCKECK_IMAGE TEST_AREA
# initialize variables
ALL_SHELL_FILES=()
EXECUTABLE_FILES=()
MOUNT_OPTIONS=()
NON_EXECUTABLE_FILES=()
@ -46,6 +47,7 @@ fi
# check test area for executable files
while IFS= read -r -d '' file; do
if head -n1 "${file}" | grep -q -E -w "sh|bash|dash|ksh"; then
ALL_SHELL_FILES+=("${file}")
if [[ -x "${file}" ]]; then
EXECUTABLE_FILES+=("${file}")
else
@ -58,11 +60,11 @@ done < <(find "${TEST_AREA[@]}" -type f -print0)
if [[ ${#NON_EXECUTABLE_FILES[@]} -ne 0 ]]; then
echo "the following shell scripts are not executable:"
printf "'%s'\n" "${NON_EXECUTABLE_FILES[@]}"
exit 1
#exit 1 # errors for non executable files are reported by https://github.com/linuxserver/github-workflows/blob/v1/.github/workflows/init-svc-executable-permissions.yml
fi
# exit gracefully if no EXECUTABLE_FILES are found
if [[ ${#EXECUTABLE_FILES[@]} -eq 0 ]]; then
# exit gracefully if no ALL_SHELL_FILES are found
if [[ ${#ALL_SHELL_FILES[@]} -eq 0 ]]; then
echo "no common files found, linting not required"
exit 0
fi
@ -72,7 +74,7 @@ docker pull "${SHELLCKECK_IMAGE}"
docker run --rm -t \
"${SHELLCKECK_IMAGE}" \
shellcheck --version
find "${EXECUTABLE_FILES[@]}" -exec \
find "${ALL_SHELL_FILES[@]}" -exec \
docker run --rm -t \
"${MOUNT_OPTIONS[@]}" \
"${SHELLCKECK_IMAGE}" \