2015-07-28 10:37:56 +02:00
|
|
|
#!/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 (https://github.com/bradfitz/goimports)
|
|
|
|
# 3. golint (https://github.com/golang/lint)
|
|
|
|
# 4. go vet (http://golang.org/cmd/vet)
|
2016-12-02 14:20:07 +01:00
|
|
|
# 5. gosimple (https://github.com/dominikh/go-simple)
|
|
|
|
# 6. unconvert (https://github.com/mdempsky/unconvert)
|
|
|
|
# 7. race detector (http://blog.golang.org/race-detector)
|
|
|
|
# 8. test coverage (http://blog.golang.org/cover)
|
2016-12-01 18:23:38 +01:00
|
|
|
#
|
2015-07-28 10:37:56 +02:00
|
|
|
|
2016-12-02 00:01:55 +01:00
|
|
|
set -ex
|
2015-07-28 10:37:56 +02:00
|
|
|
|
|
|
|
# Automatic checks
|
2020-05-13 15:25:32 +02:00
|
|
|
for i in $(find . -name go.mod -type f -print); do
|
|
|
|
module=$(dirname ${i})
|
|
|
|
echo "==> ${module}"
|
2015-07-28 10:37:56 +02:00
|
|
|
|
2020-05-13 15:25:32 +02:00
|
|
|
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \
|
|
|
|
-e 's,^/,,' -e 's,/v[0-9]+$,,')
|
|
|
|
if [ -z "$MODNAME" ]; then
|
|
|
|
MODNAME=.
|
2015-07-28 10:37:56 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-13 15:25:32 +02:00
|
|
|
# run tests
|
|
|
|
(cd $MODNAME &&
|
|
|
|
echo "mode: atomic" > profile.cov && \
|
|
|
|
env GORACE=halt_on_error=1 go test -race -covermode=atomic -coverprofile=profile.tmp ./... && \
|
|
|
|
cat profile.tmp | tail -n +2 >> profile.cov && \
|
|
|
|
rm profile.tmp && \
|
|
|
|
go tool cover -func profile.cov
|
|
|
|
)
|
2015-07-28 10:37:56 +02:00
|
|
|
|
2020-05-13 15:25:32 +02:00
|
|
|
done
|