Closed lsgunth closed 2 years ago
Something like this might work in place of the find command:
grep -rIzl '^#![[:blank:]]*/bin/.*sh' . --exclude-dir=.git
Maybe only if the pattern is '*'?
I am using the following for quite a while already (I think it was suggested in the shellcheck readme):
grep -rIl '^#![[:blank:]]*/bin/\(bash\|sh\|zsh\)' \
--exclude-dir=.git --exclude=*.sw? \
| xargs shellcheck -x
I would be looking into integrating this into the current entrypoint script. the question is if @haya14busa would be willing to part with the find command.
Sounds good. We can add a flag for this.
fwiw, here's the scriptlet I've been using to get a list of shell scripts.
(
# find sh files
find . \
-name .git -prune -o \
-name vendor -prune -o \
-name '*.sh' -print
# find executable files beginning with a "!#"
find . \
-name .git -prune -o \
-name vendor -prune -o \
"(" \
-type f -and \
-perm -100 \
")" -print0 \
| xargs -0r grep -lE '^#!/bin/(ba)?sh'
) | sort -u | xargs shellcheck --shellcheck-options...
As you see, it finds:
*.sh
regardless of file permissions or shebang(Note: I realise the grep
doesn't spot #!/usr/bin/env bash
.)
@lsgunth you can use the new feature by setting check_all_files_with_shebangs
to true
.
name: reviewdog
on: [pull_request]
jobs:
shellcheck:
name: runner / shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: shellcheck
uses: reviewdog/action-shellcheck@v1
with:
check_all_files_with_shebangs: "true"
Many shell scripts have no '.sh' suffix and but if we omit the pattern, this action checks all files in the repo except those excluded. This isn't terribly useful.
It would be nice if the files could be filtered by their shebang somehow.