Skip to content

Commit 54e060c

Browse files
committed
tests: shellcheck: add shellcheck
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 769b4f8 commit 54e060c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

tests/patch/shellcheck/info.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"run": ["shellcheck.sh"]
3+
}

tests/patch/shellcheck/shellcheck.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
HEAD=$(git rev-parse HEAD)
5+
tmpfile_o=$(mktemp)
6+
tmpfile_n=$(mktemp)
7+
rc=0
8+
9+
pr() {
10+
echo " ====== $@ ======" | tee -a /dev/stderr
11+
}
12+
13+
# If it doesn't touch .sh files, don't bother. Ignore created and deleted.
14+
if ! git show --diff-filter=M --pretty="" --name-only HEAD | grep -q -E "\.sh$"
15+
then
16+
echo "No shell scripts touched, skip" >&$DESC_FD
17+
exit 0
18+
fi
19+
20+
echo "Redirect to $tmpfile_o and $tmpfile_n"
21+
22+
echo "Tree base:"
23+
git log -1 --pretty='%h ("%s")' HEAD~
24+
echo "Now at:"
25+
git log -1 --pretty='%h ("%s")' HEAD
26+
27+
pr "Checking before the patch"
28+
git checkout -q HEAD~
29+
30+
for f in $(git show --diff-filter=M --pretty="" --name-only HEAD | grep -E "\.sh$"); do
31+
(
32+
echo "Checking $f"
33+
echo
34+
35+
cd $(dirname $f)
36+
shellcheck -x $(basename $f) | tee -a $tmpfile_o
37+
echo
38+
)
39+
done
40+
41+
incumbent=$(grep -i -c "(error)" $tmpfile_o)
42+
incumbent_w=$(grep -i -c "SC[0-9]* (" $tmpfile_o)
43+
44+
pr "Building the tree with the patch"
45+
git checkout -q $HEAD
46+
47+
for f in $(git show --diff-filter=AM --pretty="" --name-only HEAD | grep -E "\.sh$"); do
48+
(
49+
echo "Checking $f"
50+
echo
51+
52+
cd $(dirname $f)
53+
shellcheck -x $(basename $f) | tee -a $tmpfile_n
54+
echo
55+
)
56+
done
57+
58+
current=$(grep -i -c "(error)" $tmpfile_n)
59+
current_w=$(grep -i -c "SC[0-9]* (" $tmpfile_n)
60+
61+
echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
62+
63+
if [ $current -gt $incumbent ]; then
64+
echo "New errors added" 1>&2
65+
diff -U 0 $tmpfile_o $tmpfile_n 1>&2
66+
67+
rc=1
68+
fi
69+
70+
if [ $current_w -gt $incumbent_w ]; then
71+
echo "New warnings added" 1>&2
72+
73+
rc=250
74+
fi
75+
76+
rm "$tmpfile_o" "$tmpfile_n"
77+
78+
exit $rc

0 commit comments

Comments
 (0)