Skip to content

Commit 3a489d4

Browse files
matttbekuba-moo
authored andcommitted
tests: shellcheck: keep files compliant
If a file was shellcheck compliant before or is new, it is interesting to tell the reviewers when this status changes or if the new file is not shellcheck compliant from the beginning. A new dedicated file is used for each modified shell script, using a hash of the file path to cope with files with the same base name. If the status is different than before, warnings + info + style are added to the errors count. Note: it is not clear if the log message about a file no longer being shellcheck compliant any more should be more visible or not, i.e. sent to $DESC_FD. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 4c8449d commit 3a489d4

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

tests/patch/shellcheck/shellcheck.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ git checkout -q HEAD~
3131
# Also ignore created, as not present in the parent commit
3232
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
3333
(
34-
echo "Checking $f"
34+
sha=$(echo $f | sha256sum | awk '{print $1}')
35+
echo "Checking $f - $sha"
3536
echo
3637

3738
cd $(dirname $f)
38-
shellcheck -x $(basename $f) | tee -a $tmpfile_o
39+
sha="${tmpfile_o}_${sha}"
40+
rm -f "${sha}"
41+
shellcheck -x $(basename $f) | tee -a "${tmpfile_o}" "${sha}"
3942
echo
4043
)
4144
done
@@ -50,11 +53,14 @@ git checkout -q $HEAD
5053

5154
for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
5255
(
53-
echo "Checking $f"
56+
sha=$(echo $f | sha256sum | awk '{print $1}')
57+
echo "Checking $f - $sha"
5458
echo
5559

5660
cd $(dirname $f)
57-
shellcheck -x $(basename $f) | tee -a $tmpfile_n
61+
sha="${tmpfile_n}_${sha}"
62+
rm -f "${sha}"
63+
shellcheck -x $(basename $f) | tee -a "${tmpfile_n}" "${sha}"
5864
echo
5965
)
6066
done
@@ -63,6 +69,25 @@ done
6369
current=$(grep -c " (error):" $tmpfile_n)
6470
current_w=$(grep -c " (warning):" $tmpfile_n)
6571

72+
# if a file was compliant before or is new, mark everything as error to keep it good.
73+
for f in "${tmpfile_n}_"*; do
74+
[ ! -s "${f}" ] && continue # still compliant
75+
76+
sha="${f:${#tmpfile_n}+1}"
77+
old="${tmpfile_o}_${sha}"
78+
[ -s "${old}" ] && continue # wasn't compliant
79+
80+
fname=$(head -n2 "${f}" | tail -n1 | sed "s/^In \(\S\+\.sh\) line [0-9]\+:/\1/g")
81+
if [ -f "${old}" ]; then
82+
echo "${fname} was shellcheck compliant, not anymore" 1>&2
83+
else
84+
echo "${fname} is a new file, but not shellcheck compliant" 1>&2
85+
fi
86+
87+
extra=$(grep -c -E " \((warning|info|style)\):" "${f}")
88+
current=$((current + extra))
89+
done
90+
6691
echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
6792

6893
if [ $current -gt $incumbent ]; then
@@ -78,6 +103,6 @@ if [ $current_w -gt $incumbent_w ]; then
78103
rc=250
79104
fi
80105

81-
rm "$tmpfile_o" "$tmpfile_n"
106+
rm "$tmpfile_o"* "$tmpfile_n"*
82107

83108
exit $rc

0 commit comments

Comments
 (0)