forked from googollee/go-socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gosweep.sh
executable file
·65 lines (51 loc) · 1.92 KB
/
gosweep.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
59
60
61
62
63
64
65
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. goimports (http://golang.org/x/tools/cmd/goimports)
# 3. golint (https://github.com/golang/lint)
# 4. go vet (http://golang.org/cmd/vet)
# 5. ineffassign (https://github.com/gordonklaus/ineffassign)
# 6. race detector (http://blog.golang.org/race-detector)
# 7. test coverage (http://blog.golang.org/cover)
go get golang.org/x/tools/cmd/goimports
go get github.com/golang/lint/golint
go get github.com/gordonklaus/ineffassign
set -e
# Automatic checks
echo gofmt check...
test -z "$(gofmt -l -w . | tee /dev/stderr)"
echo goimports check...
test -z "$(goimports -l -w . | tee /dev/stderr)"
echo golint check...
test -z "$(golint . | tee /dev/stderr)"
echo ineffassign check...
test -z "$(ineffassign . | tee /dev/stderr)"
DIR_SOURCE="$(find . -maxdepth 10 -type f -not -path '*/vendor*' -name '*.go' | xargs -I {} dirname {} | sort | uniq)"
go vet ${DIR_SOURCE}
env GORACE="halt_on_error=1" go test -short -race ${DIR_SOURCE}
for dir in ${DIR_SOURCE};
do
ineffassign $dir
done
# Run test coverage on each subdirectories and merge the coverage profile.
echo "mode: count" > profile.cov
for dir in ${DIR_SOURCE};
do
go test -short -covermode=count -coverprofile=$dir/profile.tmp $dir
if [ -f $dir/profile.tmp ]
then
cat $dir/profile.tmp | tail -n +2 >> profile.cov
rm $dir/profile.tmp
fi
done
go tool cover -func profile.cov
# To submit the test coverage result to coveralls.io,
# use goveralls (https://github.com/mattn/goveralls)
if [ -n "${CI_SERVICE+1}" ]; then
echo "goveralls with" $CI_SERVICE
if [ -n "${COVERALLS_TOKEN+1}" ]; then
goveralls -coverprofile=profile.cov -service=$CI_SERVICE -repotoken $COVERALLS_TOKEN
else
goveralls -coverprofile=profile.cov -service=$CI_SERVICE
fi
fi