-
Notifications
You must be signed in to change notification settings - Fork 1
/
go-ci.sh
44 lines (36 loc) · 1.09 KB
/
go-ci.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
#!/bin/sh
export TERM=xterm-color
. ./ci-prepare.sh
set -e
set -x
g.. build
g.. install
set +e
if fmtresults=$(find . -type d \( -path "*/vendor" -o -path "*/.*" \) -prune -o -iname "*.go" -print0 | xargs -I{} -0 gofmt -l '{}'); then
# $() removes trailing newlines. Reinsert it if the string is not empty
# so that wc -l can count the last line.
if [ -n "$fmtresults" ]; then
newline=$(printf "\\nX") # protect the newline from $() using a trailing X
newline=${newline%X} # remove the X
fmtresults="$fmtresults$newline"
fi
efmt=$(printf "%s" "$fmtresults" | wc -l)
else
efmt=1
fi
g.. vet
evet=$?
# g.. test
rm -f coverage.tmp
# shellcheck disable=SC2016
echo 'mode: set' > coverage.txt && g.. | xargs -n1 -I{} sh -c 'go test -v -coverprofile=coverage.tmp {}; ec=$?; if test -f coverage.tmp; then tail -n +2 coverage.tmp >> coverage.txt; fi; exit $ec'
etest=$?
rm coverage.tmp
go tool cover -func coverage.txt | tail -1
set +x
if [ "$efmt" != "0" ]; then
echo "Code is not formatted correctly. Please run go fmt."
fi
if [ "$efmt" != "0" ] || [ $evet -ne 0 ] || [ $etest -ne 0 ]; then
exit 1
fi