Skip to content

Commit

Permalink
Merge pull request #35 from reviewdog/more_strict_shebang_checking
Browse files Browse the repository at this point in the history
  • Loading branch information
grische committed Nov 16, 2021
2 parents 5faebc1 + 29277ea commit 392cd66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ jobs:
pattern: '*.sh'
path: '.'
exclude: './testdata/*'
- name: shellcheck-shebang-check
uses: ./
with:
github_token: ${{ secrets.github_token }}
filter_mode: nofilter
pattern: |
*.sh
path: |
.
./testdata
exclude: |
./testdata/test.sh
*/.git/*
check_all_files_with_shebangs: true
4 changes: 2 additions & 2 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ done <<< "${INPUT_EXCLUDE:-}"
# Match all files matching the pattern
files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}")

# Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!/my/path/bash") in the first two lines
# 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 grep -m2 -IrlZ "^#\\!/.*sh" | xargs -r -0 echo)
files_with_shebang=$(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }')
fi

# Exit early if no files have been found
Expand Down
4 changes: 4 additions & 0 deletions testdata/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}"

0 comments on commit 392cd66

Please sign in to comment.