diff --git a/action.yml b/action.yml index 861b2f8..ff6c8bb 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,12 @@ inputs: description: "File patterns of target files. Same as `-name [pattern]` of `find` command." default: '*.sh' required: false + check_all_files_with_shebangs: + description: | + Checks all files with shebangs in the repository even if they do not match the pattern. + Default is `false`. + default: 'false' + required: false exclude: description: "Exclude patterns of target files. Same as `-not -path [exclude]` of `find` command." shellcheck_flags: @@ -68,6 +74,7 @@ runs: INPUT_PATH: ${{ inputs.path }} INPUT_PATTERN: ${{ inputs.pattern }} INPUT_EXCLUDE: ${{ inputs.exclude }} + INPUT_CHECK_ALL_FILES_WITH_SHEBANGS: ${{ inputs.check_all_files_with_shebangs }} INPUT_SHELLCHECK_FLAGS: ${{ inputs.shellcheck_flags }} branding: diff --git a/script.sh b/script.sh index f7733c7..fdf46fe 100755 --- a/script.sh +++ b/script.sh @@ -13,7 +13,20 @@ cd "${GITHUB_WORKSPACE}" || exit export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" -FILES=$(find "${INPUT_PATH:-'.'}" -not -path "${INPUT_EXCLUDE}" -type f -name "${INPUT_PATTERN:-'*.sh'}") +pattern="${INPUT_PATTERN:-'*.sh'}" +exclude="${INPUT_EXCLUDE:-}" +path="${INPUT_PATH:-'.'}" + +# Match all files matching the pattern +files_with_pattern=$(find "${path}" -not -path "${exclude}" -type f -name "${pattern}") + +# Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!/my/path/bash") in the first two lines +# Ignore files which match "$pattern" in order to avoid duplicates +if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then + files_with_shebang=$(find "${path}" -not -path "${path}/.git/*" -not -path "${exclude}" -not -name "${pattern}" -type f -print0 | xargs -0 grep -m2 -IrlZ "^#\\!/.*sh" | xargs -r -0 echo) +fi + +FILES="${files_with_pattern} ${files_with_shebang}" echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then