-
Notifications
You must be signed in to change notification settings - Fork 25
/
run-checks
executable file
·176 lines (152 loc) · 4.4 KB
/
run-checks
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
if [ "$TRAVIS_BUILD_NUMBER" ]; then
echo travis_fold:start:env
printenv | sort
echo travis_fold:end:env
fi
export LANG=C.UTF-8
export LANGUAGE=en
set -eu
if which goctest >/dev/null; then
goctest="goctest"
else
goctest="go test -mod=vendor"
fi
COVERMODE=${COVERMODE:-atomic}
STATIC=
UNIT=
case "${1:-all}" in
all)
STATIC=1
UNIT=1
;;
--static)
STATIC=1
;;
--unit)
UNIT=1
;;
*)
echo "Wrong flag ${1}. To run a single suite use --static or --unit"
exit 1
esac
CURRENTTRAP="true"
EXIT_CODE=99
store_exit_code() {
EXIT_CODE=$?
}
exit_with_exit_code() {
exit $EXIT_CODE
}
addtrap() {
CURRENTTRAP="$CURRENTTRAP ; $1"
trap "store_exit_code; $CURRENTTRAP ; exit_with_exit_code" EXIT
}
endmsg() {
if [ $EXIT_CODE -eq 0 ]; then
p="success.txt"
m="All good, what could possibly go wrong."
else
p="failure.txt"
m="Crushing failure and despair."
fi
echo "$m"
}
addtrap endmsg
# Append the coverage profile of a package to the project coverage.
append_coverage() {
local profile="$1"
if [ -f $profile ]; then
cat $profile | grep -v "mode: set" >> .coverage/coverage.out
rm $profile
fi
}
if [ "$STATIC" = 1 ]; then
# Run static tests.
echo Checking docs
./mdlint.py ./*.md docs/*.md docs/reference/*.md docs/reference/rest-api/*.md
echo Checking formatting
fmt=""
for dir in $(go list -f '{{.Dir}}' ./... | grep -v '/vendor/' ); do
s="$(gofmt -s -l "$dir")"
if [ -n "$s" ]; then
fmt="$s\n$fmt"
fi
done
if [ -n "$fmt" ]; then
echo "Formatting wrong in following files:"
echo "$fmt"
exit 1
fi
# go vet
echo Running vet
go vet -mod=vendor ./...
# TODO: disable lint until go version upgrade
#echo Running lint
#for dir in $(go list -f '{{.Dir}}' ./... | grep -v '/vendor/' ); do
# lint="$(./bin/golint "$dir")"
# if [ -n "$lint" ]; then
# echo "Lint complains:"
# echo "$lint"
# exit 1
# fi
#done
# TODO: Commented out until desired to fix all the remaining format stuff
#
# if which shellcheck >/dev/null; then
# echo Checking shell scripts...
# ( git ls-files -z 2>/dev/null ||
# find . \( -name .git -o -name vendor \) -prune -o -print0 ) |
# xargs -0 file -N |
# awk -F": " '$2~/shell.script/{print $1}' |
# xargs shellcheck
# regexp='GOPATH(?!%%:\*)(?!:)[^=]*/'
# if grep -qPr --exclude HACKING.md --exclude-dir .git --exclude-dir vendor "$regexp"; then
# echo "Using GOPATH as if it were a single entry and not a list:"
# grep -PHrn -C1 --color=auto --exclude HACKING.md --exclude-dir .git --exclude-dir vendor "$regexp"
# exit 1
# fi
# unset regexp
# fi
echo Checking spelling errors
for file in *; do
if [ "$file" = "vendor" ] || [ "$file" = "static" ] || [ "$file" = "webapp-admin" ] || [ "$file" = "webapp-user" ] || [ "$file" = "test" ] || [ "$file" = "tmp" ] || [ "$file" = "tmp_charm" ] || [ "$file" = "dist" ]; then
continue
fi
./bin/misspell -error -i auther,PROCES,PROCESSS,proces,processs,exportfs "$file"
done
# TODO: disable ineffassign until go version upgrade
#echo Checking for ineffective assignments
# ineffassign knows about ignoring vendor/ \o/
#./bin/ineffassign ./...
echo Checking for naked returns
got=$(./bin/nakedret ./... 2>&1)
if [ -n "$got" ]; then
echo "$got"
exit 1
fi
fi
if [ ! -z "$UNIT" ]; then
# Prepare the coverage output profile.
rm -rf .coverage
mkdir .coverage
echo "mode: $COVERMODE" > .coverage/coverage.out
# tests
echo Running tests from "$PWD"
for pkg in $(go list ./... | grep -v '/vendor/' ); do
$goctest -v -coverprofile=.coverage/profile.out -covermode="$COVERMODE" "$pkg"
append_coverage .coverage/profile.out
done
# upload to codecov.io if on travis
if [ "${TRAVIS_BUILD_NUMBER:-}" ]; then
curl -s https://codecov.io/bash | bash /dev/stdin -f .coverage/coverage.out
fi
fi
UNCLEAN="$(git status -s|grep ^??)" || true
if [ -n "$UNCLEAN" ]; then
cat <<EOF
There are files left in the git tree after the tests:
$UNCLEAN
EOF
exit 1
fi