Skip to content

Commit 255ee02

Browse files
committed
tests: yamllint: add YAML linting
Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 41a20fd commit 255ee02

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/patch/yamllint/info.json

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

tests/patch/yamllint/yamllint.sh

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

0 commit comments

Comments
 (0)