forked from danos/vplane-config-npf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codechecks
executable file
·112 lines (86 loc) · 2.68 KB
/
codechecks
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
#
# Copyright (c) 2020, AT&T Intellectual Property.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-only
#
# TODO
#
# * SPDX license check only provided there's a copyright message?
# * Remove dirs from $all_files
#
# $1: TARGET - most likely "origin/master"
# $2: SOURCE - most likely "bugfix/foo" or "feature/bar"
usage () {
echo "Usage: $(basename $0) target source" >&2
echo "target: something like 'origin/master'" >&2
echo "source: something like 'bugfix/foo' or 'feature/bar'" >&2
}
[ "$#" -ne 2 ] && { usage; exit 1; }
# Exit status: presume success.
status=0
# List of files to ignore.
IGN_FILES="configure.ac\nMakefile.am\ndebian\/.*\nplatform\/.*\.platform\nfeatures\/.*"
# All files in the diff, except deleted files.
all_files=`git diff --diff-filter=d --name-only --format=format:'' $1..$2`
# Strip out the ignored files.
check_files=`sed -e "$(sed 's:.*:s/&//ig:' <<< $(echo -e $IGN_FILES))" <<< $all_files`
# Bail out if there's nothing to check.
if [ -z "$check_files" ]; then
exit $status
fi
# Ensure all files contain a copyright message with the current year.
#
YEAR=`date +%Y`
copyright_fails=`egrep -d skip -L "Copyright \(c) .*$YEAR,{,1} AT&T Intellectual Property" $check_files`
if [ -n "$copyright_fails" ]; then
echo "$copyright_fails" | sed "s/^/Check copyright message: /"
echo
status=1
fi
# Ensure all files contain an SPDX license.
#
lic=`grep -L "SPDX-License-Identifier: " $check_files`
if [ -n "$lic" ]; then
echo "$lic" | sed "s/^/Missing SPDX-License-Identifier: /"
echo
status=1
fi
# No trailing whitespace in any files.
#
if [ "$check_files" ]; then trail_fails=`grep -n "\s$" $check_files`; fi
if [ -n "$trail_fails" ]; then
echo "$trail_fails" | sed "s/^/Trailing whitespace: /"
echo
status=1
fi
# Idempotent headers - .h files must end "#endif /* SOME TAG */"
#
h_files=`echo $check_files | grep -Po "[^[:blank:]]*\.h( |$)"`
idem_fails=`for h in $h_files; do tail -n 1 $h | grep -L "^#endif.*[A-Z]" > /tmp/x && echo $h; done`
if [ -n "$idem_fails" ]; then
echo "$idem_fails" | sed "s/^/Check idempotency: /"
echo
status=1
fi
# Ensure correct postal and web address in yang files.
#
yang_files=`echo $check_files | grep -Po "[^[:blank:]]*\.yang( |$)"`
for yang in $yang_files; do
IFS="" addr=`grep -A3 "Postal" $yang`
a1=`echo $addr | grep "Postal: 208 S. Akard Street"`
a2=`echo $addr | grep "Dallas, TX 75202, USA"`
a3=`echo $addr | grep "Web: www.att.com"`
if [ -z "$a1" -o -z "$a2" -o -z "$a3" ]; then
echo "Incorrect address:"
echo "$addr"
echo
status=1
fi
done
# Exit status:
# 0 on success
# 1 on failure
#
exit $status