diff --git a/README.md b/README.md index 531e705..d57df72 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,23 @@ all files at once: ```yaml ... - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master - with: - check_together: 'yes' + uses: ludeeus/action-shellcheck@master + with: + check_together: 'yes' ``` This can turn into a problem if you have enough script files to overwhelm the 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' +``` diff --git a/action.yaml b/action.yaml index e4fd398..4fc804d 100644 --- a/action.yaml +++ b/action.yaml @@ -14,6 +14,10 @@ inputs: description: 'Run shellcheck on _all_ files at once, instead of one at a time' required: false default: '' + scandir: + description: 'Directory to be searched for files. Defaults to .' + required: false + default: '.' runs: using: 'docker' image: 'Dockerfile' diff --git a/runaction b/runaction index df5dc53..920a9ed 100755 --- a/runaction +++ b/runaction @@ -13,6 +13,7 @@ declare -a filepaths declare -a excludes declare -a tmp +INPUT_SCANDIR="${INPUT_SCANDIR:-.}" statuscode=0 shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh" @@ -26,7 +27,7 @@ for path in ${INPUT_IGNORE}; do excludes+=(! -path "*/${path}/*" ) done -readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \ +readarray -d '' filepaths < <(find "${INPUT_SCANDIR}" -type f "${excludes[@]}" \ '(' \ \ -name '*.bash' \ @@ -59,19 +60,20 @@ readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \ \ -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 head -n1 "$file" | grep -Eqs "$shebangregex" || continue filepaths+=("$file") done -if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print | +if find "${INPUT_SCANDIR}" "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print | grep . then echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH" 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 . then echo >&2 "::warning:: programs in PATH should not have a filename suffix"