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
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
|
2020-05-30 11:44:01 +02:00
|
|
|
excludes+=( ! -path *./.git/* )
|
2020-06-07 16:53:52 +02:00
|
|
|
excludes+=( ! -path *.go )
|
2020-06-10 11:56:06 +02:00
|
|
|
excludes+=( ! -path */mvnw )
|
2020-06-07 16:53:52 +02:00
|
|
|
|
2020-05-30 11:44:01 +02:00
|
|
|
for path in ${INPUT_IGNORE}; do
|
2020-05-30 12:01:39 +02:00
|
|
|
echo "::debug:: Adding '${path}' to excludes"
|
2020-05-30 12:00:24 +02:00
|
|
|
excludes+=(! -path "*./${path}/*" )
|
2020-05-30 12:01:39 +02:00
|
|
|
excludes+=(! -path "*/${path}/*" )
|
2020-05-30 11:44:01 +02:00
|
|
|
done
|
|
|
|
|
2020-06-27 11:43:04 +02:00
|
|
|
readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \
|
2020-05-30 11:44:01 +02:00
|
|
|
'(' \
|
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 '*/.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
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
|
2020-05-30 11:44:01 +02:00
|
|
|
if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print |
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
grep .
|
|
|
|
then
|
2020-05-30 00:06:39 +02:00
|
|
|
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
fi
|
|
|
|
|
2020-05-30 11:44:01 +02:00
|
|
|
if find . "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
grep .
|
|
|
|
then
|
2020-05-30 00:06:39 +02:00
|
|
|
echo >&2 "::warning:: programs in PATH should not have a filename suffix"
|
apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.
Apply shellcheck to:
* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)
* typical home directory shell startup files:
for posix sh & all shells: .profile
for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
for ksh: .profile
for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc
* typical system-wide shell startup files:
for posix sh & all shells: /etc/profile
for bash: /etc/bashrc, /etc/bash_profile
for ksh:
for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc
* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 06:45:19 +01:00
|
|
|
fi
|
2020-05-03 22:11:15 +02:00
|
|
|
|
2020-06-26 08:05:34 +02:00
|
|
|
[[ -n "${INPUT_SEVERITY}" ]] && options+=(-S "${INPUT_SEVERITY}")
|
|
|
|
|
2020-06-26 21:41:45 +02:00
|
|
|
if [[ -n "$INPUT_CHECK_TOGETHER" ]]; then
|
|
|
|
echo "::debug:: shellcheck ${options[*]} ${filepaths[*]}"
|
|
|
|
shellcheck "${options[@]}" "${filepaths[@]}" || statuscode=$?
|
|
|
|
else
|
|
|
|
echo "::debug:: Shellcheck options: ${options[*]}"
|
|
|
|
for file in "${filepaths[@]}"; do
|
|
|
|
echo "::debug:: Checking $file"
|
|
|
|
shellcheck "${options[@]}" "$file" || statuscode=$?
|
|
|
|
done
|
|
|
|
fi
|
2020-05-30 00:06:39 +02:00
|
|
|
|
2020-06-10 11:56:06 +02:00
|
|
|
exit "$statuscode"
|