-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathverify-jsonformat.sh
executable file
·58 lines (51 loc) · 1.48 KB
/
verify-jsonformat.sh
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
#!/usr/bin/env bash
# Usage:
#
# To only verify that there are no errors in JSON files, run:
# $ ./hack/verify-jsonformat.sh
#
# Additionally, to verify also the formatting of JSON file, run:
# $ ./hack/verify-jsonformat.sh --format
#
# In case there is a formatting error, you can use this command to fix it
# automatically:
# $ ./hack/verify-jsonformat.sh --format --fix
#
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
json_files=$(find {examples,docs,images,test} -name "*.json")
tmp_dir=$(mktemp -d)
found=0
excluded_files=(
"test/extended/testdata/cmd/test/cmd/testdata/new-app/bc-from-imagestreamimage.json"
"test/extended/testdata/cmd/test/cmd/testdata/new-app/invalid.json"
)
set +e
format="${1:-""}"
fix="${2:-""}"
for f in $json_files; do
if [[ " ${excluded_files[@]} " =~ " ${f} " ]]; then
continue
fi
tmp_file="${tmp_dir}$(basename $f)"
go run ./hack/jsonformat/main.go ${f} > ${tmp_file}
result=$?
if [ "${format}" == "--format" ]; then
if ! diff --brief ${f} ${tmp_file} > /dev/null; then
if [ "$result" == "0" -a "${fix}" == "--fix" ]; then
echo "Fixing JSON formatting for '${f}'"
cp ${tmp_file} ${f}
else
echo "JSON formatting problem: '${f}'"
found=1
fi
continue
fi
fi
[ "$result" != "0" ] && found=1
done
rm -rf ${tmp_dir}
if [ "$found" == "1" ]; then
echo -e "\nThere are problems with some JSON files, to verify them you can run:"
echo -e "$ go run ./hack/jsonformat.go <filename>\n"
exit
fi