Skip to content

Commit

Permalink
Merge pull request #31 from grische/feature/check_files_with_shebang
Browse files Browse the repository at this point in the history
Add flag to parse any file with a shebang
  • Loading branch information
shogo82148 authored Nov 13, 2021
2 parents 2c31bf1 + 8a76a62 commit 798a1c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 798a1c7

Please sign in to comment.