-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: adapt goclean.sh to work with module packages
- Loading branch information
Showing
1 changed file
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
#!/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://godoc.org/golang.org/x/tools/cmd/goimports) | ||
# 3. go vet (http://golang.org/cmd/vet) | ||
# 4. gosimple (https://github.com/dominikh/go-simple) | ||
# 5. unconvert (https://github.com/mdempsky/unconvert) | ||
# 6. race detector (http://blog.golang.org/race-detector) | ||
# 7. test coverage (http://blog.golang.org/cover) | ||
|
||
set -ex | ||
# Automatic checks | ||
for i in $(find . -name go.mod -type f -print); do | ||
module=$(dirname ${i}) | ||
echo "==> ${module}" | ||
|
||
env GORACE="halt_on_error=1" go test -race -tags="rpctest" -covermode atomic -coverprofile=profile.cov ./... | ||
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \ | ||
-e 's,^/,,' -e 's,/v[0-9]+$,,') | ||
if [ -z "$MODNAME" ]; then | ||
MODNAME=. | ||
fi | ||
|
||
# Automatic checks | ||
golangci-lint run --deadline=10m --disable-all \ | ||
--enable=gofmt \ | ||
--enable=vet \ | ||
--enable=gosimple \ | ||
--enable=unconvert | ||
# run tests | ||
(cd $MODNAME && env GORACE=halt_on_error=1 go test -tags="rpctest" -race ./...) || exit 1 | ||
|
||
# check linters | ||
(cd $MODNAME && \ | ||
go mod download && \ | ||
golangci-lint run --deadline=10m --disable-all \ | ||
--enable=gofmt \ | ||
--enable=goimports \ | ||
--enable=govet \ | ||
--enable=gosimple \ | ||
--enable=unconvert | ||
) | ||
done | ||
|
||
# Run test coverage on each subdirectories and merge the coverage profile. | ||
|
||
echo "mode: count" > profile.cov | ||
|
||
# Standard go tooling behavior is to ignore dirs with leading underscores. | ||
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); | ||
do | ||
if ls $dir/*.go &> /dev/null; then | ||
go test -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 | ||
fi | ||
done | ||
|
||
go tool cover -func profile.cov |