action-shellcheck/runaction.sh

73 lines
1.7 KiB
Bash
Raw Normal View History

2020-05-30 00:06:39 +02:00
#!/bin/bash
2019-03-09 11:25:14 +01:00
2020-05-03 22:11:15 +02:00
cd "$GITHUB_WORKSPACE" || exit 1
2020-05-30 11:44:01 +02:00
declare statuscode
2020-05-30 00:06:39 +02:00
declare -a filepaths
2020-05-30 11:44:01 +02:00
declare -a excludes
2020-05-30 00:06:39 +02:00
declare -a tmp
2020-05-30 11:44:01 +02:00
statuscode=0
2020-05-30 11:44:01 +02:00
excludes+=( ! -path *./.git/* )
for path in ${INPUT_IGNORE}; do
[[ ${path#./*} != "$path" ]] || path=./${path}
echo "::debug:: Adding '${path}' to excludes"
excludes+=(! -path *"${path}"* )
done
readarray -d '' filepaths < <(find . "${excludes[@]}" \
'(' \
2020-05-30 00:06:39 +02:00
\
-name '*.bash' \
-o -path '*/.bash*' \
-o -path '*/bash*' \
-o -name '*.ksh' \
-o -name 'ksh*' \
-o -path '*/.ksh*' \
-o -path '*/ksh*' \
-o -name 'suid_profile' \
-o -name '*.zsh' \
-o -name '.zlogin*' \
-o -name 'zlogin*' \
-o -name '.zlogout*' \
-o -name 'zlogout*' \
-o -name '.zprofile*' \
-o -name 'zprofile*' \
-o -path '*/.zsh*' \
-o -path '*/zsh*' \
-o -name '*.sh' \
-o -path '*/.profile*' \
-o -path '*/profile*' \
-o -path '*/.shlib*' \
-o -path '*/shlib*' \
')'\
\
-print0)
2020-05-30 11:44:01 +02:00
readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
2020-05-30 00:06:39 +02:00
for file in "${tmp[@]}"; do
head -n1 "$file" | grep -Eqs "^#! */[^ ]*/[abkz]*sh" || continue
filepaths+=("$file")
done
2020-05-30 11:44:01 +02:00
if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print |
grep .
then
2020-05-30 00:06:39 +02:00
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
fi
2020-05-30 11:44:01 +02:00
if find . "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
grep .
then
2020-05-30 00:06:39 +02:00
echo >&2 "::warning:: programs in PATH should not have a filename suffix"
fi
2020-05-03 22:11:15 +02:00
2020-05-30 00:06:39 +02:00
for file in "${filepaths[@]}"; do
echo "::debug:: Checking $file"
2020-05-30 11:44:01 +02:00
shellcheck "$file" || statuscode=$?
2020-05-30 00:06:39 +02:00
done
2020-05-30 11:44:01 +02:00
exit "$statuscode"