1
0
Fork 0
mirror of https://github.com/ludeeus/action-shellcheck.git synced 2024-08-16 10:09:53 +02:00

Add scandir option (#28)

This commit is contained in:
Daniel 2020-10-03 14:49:12 +02:00 committed by GitHub
parent c489c81f79
commit fcee962fee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -87,3 +87,16 @@ all files at once:
This can turn into a problem if you have enough script files to overwhelm the This can turn into a problem if you have enough script files to overwhelm the
maximum argv length on your system. maximum argv length on your system.
## Run shellcheck only in a single directory
If you have multiple directories with scripts, but only want to scan
one of them, you can use the following configuration:
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
scandir: './scripts'
```

View file

@ -14,6 +14,10 @@ inputs:
description: 'Run shellcheck on _all_ files at once, instead of one at a time' description: 'Run shellcheck on _all_ files at once, instead of one at a time'
required: false required: false
default: '' default: ''
scandir:
description: 'Directory to be searched for files. Defaults to .'
required: false
default: '.'
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'

View file

@ -13,6 +13,7 @@ declare -a filepaths
declare -a excludes declare -a excludes
declare -a tmp declare -a tmp
INPUT_SCANDIR="${INPUT_SCANDIR:-.}"
statuscode=0 statuscode=0
shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh" shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh"
@ -26,7 +27,7 @@ for path in ${INPUT_IGNORE}; do
excludes+=(! -path "*/${path}/*" ) excludes+=(! -path "*/${path}/*" )
done done
readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \ readarray -d '' filepaths < <(find "${INPUT_SCANDIR}" -type f "${excludes[@]}" \
'(' \ '(' \
\ \
-name '*.bash' \ -name '*.bash' \
@ -59,19 +60,20 @@ readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \
\ \
-print0) -print0)
readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
readarray -d '' tmp < <(find "${INPUT_SCANDIR}" "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
for file in "${tmp[@]}"; do for file in "${tmp[@]}"; do
head -n1 "$file" | grep -Eqs "$shebangregex" || continue head -n1 "$file" | grep -Eqs "$shebangregex" || continue
filepaths+=("$file") filepaths+=("$file")
done done
if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print | if find "${INPUT_SCANDIR}" "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print |
grep . grep .
then then
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH" echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
fi fi
if find . "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print | if find "${INPUT_SCANDIR}" "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
grep . grep .
then then
echo >&2 "::warning:: programs in PATH should not have a filename suffix" echo >&2 "::warning:: programs in PATH should not have a filename suffix"