Skip to content

Commit 35d6c4c

Browse files
authored
Add the ability to check all scripts in one shellcheck command (#17)
This is the most straightforward way to allow sourcing scripts, as shellcheck [SC1090] only allows `source` files that are in the same invocation, I believe unless `-x` is also specified. [SC1090]: https://github.com/koalaman/shellcheck/wiki/SC1090
1 parent 142c6d5 commit 35d6c4c

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,19 @@ example:
7171
with:
7272
severity: error
7373
```
74+
75+
## Run shellcheck with all paths in a single invocation
76+
77+
If you run into SC1090/SC1091 errors you may need to tell shellcheck to check
78+
all files at once:
79+
80+
```yaml
81+
...
82+
- name: Run ShellCheck
83+
uses: ludeeus/action-shellcheck@master
84+
with:
85+
check_together: 'yes'
86+
```
87+
88+
This can turn into a problem if you have enough script files to overwhelm the
89+
maximum argv length on your system.

action.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
description: 'Minimum severity of errors to consider. Options: [error, warning, info, style]'
1111
required: false
1212
default: ''
13+
check_together:
14+
description: 'Run shellcheck on _all_ files at once, instead of one at a time'
15+
required: false
16+
default: ''
1317
runs:
1418
using: 'docker'
1519
image: 'Dockerfile'

runaction.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ fi
6868

6969
[[ -n "${INPUT_SEVERITY}" ]] && options+=(-S "${INPUT_SEVERITY}")
7070

71-
for file in "${filepaths[@]}"; do
72-
echo "::debug:: Checking $file"
73-
shellcheck "${options[@]}" "$file" || statuscode=$?
74-
done
71+
if [[ -n "$INPUT_CHECK_TOGETHER" ]]; then
72+
echo "::debug:: shellcheck ${options[*]} ${filepaths[*]}"
73+
shellcheck "${options[@]}" "${filepaths[@]}" || statuscode=$?
74+
else
75+
echo "::debug:: Shellcheck options: ${options[*]}"
76+
for file in "${filepaths[@]}"; do
77+
echo "::debug:: Checking $file"
78+
shellcheck "${options[@]}" "$file" || statuscode=$?
79+
done
80+
fi
7581

7682
exit "$statuscode"

0 commit comments

Comments
 (0)