Skip to content

Commit 6401cc2

Browse files
committed
Sync shell script static analysis task from template
- Use standardized task name - Add support for arbitrary file extensions and path configurations (which is not possible with the previous globstar approach)
1 parent 406fde0 commit 6401cc2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

.github/workflows/lint-shell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
version: 3.x
2626

2727
- name: Lint shell scripts
28-
run: task shell:lint
28+
run: task shell:check

Taskfile.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,33 @@ tasks:
266266
cmds:
267267
- npx {{ .PRETTIER }} --write "**/*.md"
268268

269-
shell:lint:
270-
desc: Lint shell scripts
269+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml
270+
shell:check:
271+
desc: Check for problems with shell scripts
271272
cmds:
272273
- |
273274
if ! which shellcheck &>/dev/null; then
274275
echo "shellcheck not installed or not in PATH. Please install: https://github.com/koalaman/shellcheck#installing"
275276
exit 1
276277
fi
277278
- |
278-
shopt -s globstar # Needed to check all scripts recursively.
279-
shellcheck ./**/*.sh
279+
# There is something odd about shellcheck that causes the task to always exit on the first fail, despite any
280+
# measures that would prevent this with any other command. So it's necessary to call shellcheck only once with
281+
# the list of script paths as an argument. This could lead to exceeding the maximum command length on Windows if
282+
# the repository contained a large number of scripts, but it's unlikely to happen in reality.
283+
shellcheck \
284+
--format={{default "tty" .SHELLCHECK_FORMAT}} \
285+
$(
286+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
287+
# \ characters special treatment on Windows in an attempt to support them as path separators.
288+
find . \
289+
-path ".git" -prune -or \
290+
\( \
291+
-regextype posix-extended \
292+
-regex '.*[.](bash|sh)' -and \
293+
-type f \
294+
\)
295+
)
280296
281297
shell:check-formatting:
282298
desc: Format shell scripts

0 commit comments

Comments
 (0)