Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,34 @@ while read -r pattern; do
[[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}")
done <<< "${INPUT_EXCLUDE:-}"

# Collect matches NUL-separated so that paths containing whitespace survive
files=()

# Match all files matching the pattern
files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}")
while IFS= read -r -d '' file; do
files+=("${file}")
done < <(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}" -print0)

# Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file
# Ignore files which match "$pattern" in order to avoid duplicates
if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then
files_with_shebang=$(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }')
while IFS= read -r -d '' file; do
files+=("${file}")
done < <(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 \
| xargs -0 awk 'FNR==1 && /^#!.*sh/ { printf "%s%c", FILENAME, 0 }')
fi

# Exit early if no files have been found
if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then
if [ ${#files[@]} -eq 0 ]; then
echo "No matching files found to check."
exit 0
fi

FILES="${files_with_pattern} ${files_with_shebang:-}"

echo '::group:: Running shellcheck ...'
if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then
# erroformat: https://git.io/JeGMU
# shellcheck disable=SC2086
shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \
shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} "${files[@]}" \
| jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message) [SC\(.code)](https://github.com/koalaman/shellcheck/wiki/SC\(.code))"' \
| reviewdog \
-efm="%f:%l:%c:%t%*[^:]:%m" \
Expand All @@ -93,7 +99,7 @@ if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then
else
# github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation.
# shellcheck disable=SC2086
shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} \
shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} "${files[@]}" \
| reviewdog \
-f="checkstyle" \
-name="shellcheck" \
Expand All @@ -110,7 +116,7 @@ echo '::endgroup::'
echo '::group:: Running shellcheck (suggestion) ...'
# -reporter must be github-pr-review for the suggestion feature.
# shellcheck disable=SC2086
shellcheck -f diff ${FILES} \
shellcheck -f diff "${files[@]}" \
| reviewdog \
-name="shellcheck (suggestion)" \
-f=diff \
Expand Down
4 changes: 4 additions & 0 deletions testdata/space dir/non-sh-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ksh
# shellcheck enable=all

echo "${1}"
2 changes: 2 additions & 0 deletions testdata/space dir/spaced test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo $1 # Unquoted variables

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)

Check warning on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./testdata/space dir/spaced test.sh:1:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check failure on line 1 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. Raw Output: ./testdata/space dir/spaced test.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (ShellCheck.SC2148)
find . -name *.ogg # Unquoted find/grep patterns

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (ubuntu-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (macos-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Use ./*glob* or -- *glob* so names with dashes won't become options. Raw Output: ./testdata/space dir/spaced test.sh:2:14: info: Use ./*glob* or -- *glob* so names with dashes won't become options. (ShellCheck.SC2035)

Check warning on line 2 in testdata/space dir/spaced test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck (windows-latest)

[shellcheck] reported by reviewdog 🐶 Quote the parameter to -name so the shell won't interpret it. Raw Output: ./testdata/space dir/spaced test.sh:2:14: warning: Quote the parameter to -name so the shell won't interpret it. (ShellCheck.SC2061)
Loading