-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
executable file
·53 lines (43 loc) · 1.26 KB
/
check.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
#/bin/sh
# Script to simplify the style check process
errors=0
echo
echo '---------------------- Custom Checks ----------------------'
echo
for f in `git ls-files`; do
# Check text files
if file "$f" | grep -q 'text$'; then
# Ends with newline as POSIX requires
if [ -n "$(tail -c 1 "$f")" ]; then
echo "Not ends with newline: $f"
errors=$((${errors}+1))
fi
fi
done
echo
echo '---------------------- GoFmt verify ----------------------'
echo
reformat=$(gofmt -l .)
if [ "${reformat}" ]; then
echo "Please run 'gofmt -w .': \n${reformat}"
errors=$((${errors}+$(echo "${reformat}" | wc -l)))
fi
echo
echo '---------------------- GoModTidy verify ----------------------'
echo
cp -af go.mod go.sum /tmp/
tidy=$(go mod tidy -v)
if [ "${tidy}" -o "x$(date -r /tmp/go.mod ; date -r /tmp/go.sum)" != "x$(date -r go.mod ; date -r go.sum)" ]; then
echo "Please run 'go mod tidy -v' \n${tidy}"
errors=$((${errors}+$(echo "${tidy}" | wc -l)))
fi
mv /tmp/go.mod /tmp/go.sum ./
echo
echo '---------------------- GoVet verify ----------------------'
echo
vet=$(go vet ./... 2>&1)
if [ "${vet}" ]; then
echo "Please fix the issues: \n${vet}"
errors=$(((${errors}+$(echo "${vet}" | wc -l))/2))
fi
exit ${errors}