-
Notifications
You must be signed in to change notification settings - Fork 3
87 lines (76 loc) · 2.91 KB
/
Copy pathshellcheck.yml
File metadata and controls
87 lines (76 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: ShellCheck
# The engine had no static analysis at all, and it showed. An unquoted
# expansion in `pct create ... $PCT_OPTIONS` split a password on spaces and let
# `Test*` be replaced by a filename -- textbook SC2086, found by a user rather
# than by a tool.
#
# Two stages on purpose:
#
# "Errors" blocks. At severity=error ShellCheck reports things that are wrong
# regardless of intent, so it can gate a PR from day one.
#
# "Warnings" reports without blocking. Turning the full set on as a gate would
# fail every PR immediately: `$STD` and `$PCT_OPTIONS` are expanded unquoted
# deliberately -- that is how the options string becomes separate arguments --
# so SC2086 alone fires across the codebase. Those need per-site review and a
# disable comment where the split is intended, which is real work and not
# something to hide behind a red build.
#
# The intent is to work the warning list down and then promote it to blocking.
on:
pull_request:
paths:
- "**/*.func"
- "**/*.sh"
- ".github/workflows/shellcheck.yml"
push:
branches: [main]
paths:
- "**/*.func"
- "**/*.sh"
workflow_dispatch:
permissions:
contents: read
jobs:
errors:
name: Errors (blocking)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ShellCheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: shellcheck --severity=error
run: |
set -euo pipefail
# SC1091 is excluded: nearly every source is fetched at run time, so
# there is no path on disk for ShellCheck to follow.
mapfile -t files < <(find . \( -name '*.func' -o -name '*.sh' \) -not -path './.git/*' | sort)
echo "checking ${#files[@]} files"
shellcheck --shell=bash --severity=error --exclude=SC1091 \
--format=gcc "${files[@]}"
warnings:
name: Warnings (report only)
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Install ShellCheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: shellcheck --severity=warning
run: |
set -uo pipefail
mapfile -t files < <(find . \( -name '*.func' -o -name '*.sh' \) -not -path './.git/*' | sort)
shellcheck --shell=bash --severity=warning --exclude=SC1091 \
--format=gcc "${files[@]}" > findings.txt || true
total=$(wc -l < findings.txt)
{
echo "### ShellCheck warnings: ${total}"
echo ''
echo 'By check, most frequent first:'
echo '```'
grep -oE 'SC[0-9]+' findings.txt | sort | uniq -c | sort -rn | head -25
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
# The full list in the log, so a specific site can be looked up
# without installing ShellCheck locally.
cat findings.txt