-
-
Save mewmew/379014c9a2e6885e238d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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://godoc.org/golang.org/x/tools/cmd/goimports) | |
# 3. golint (https://github.com/golang/lint) | |
# 4. go vet (http://golang.org/cmd/vet) | |
# 5. race detector (http://blog.golang.org/race-detector) | |
# 6. test coverage (http://blog.golang.org/cover) | |
# Automatic checks | |
echo "### gofmt" | |
test -z "$(find . -type f -name '*.go' -print0 | xargs -0 gofmt -l -s | tee /dev/stderr)" | |
GOFMT_FAIL=$? | |
echo | |
echo "### goimports" | |
test -z "$(find . -type f -name '*.go' -print0 | xargs -0 goimports -l | tee /dev/stderr)" | |
GOIMPORTS_FAIL=$? | |
echo | |
echo "### golint" | |
if [ "${GOLINT_IGNORE}" ]; then | |
test -z "$(echo ${GOLINT_IGNORE} | xargs find . -type f -name '*.go' | xargs -I '{}' golint "{}" | tee /dev/stderr)" | |
GOLINT_FAIL=$? | |
else | |
test -z "$(golint ./... | tee /dev/stderr)" | |
GOLINT_FAIL=$? | |
fi | |
echo | |
echo "### go vet" | |
go vet ./... | |
GOVET_FAIL=$? | |
echo | |
echo "### go test -race" | |
go test -race ./... | |
GOTEST_FAIL=$? | |
echo | |
if [ "${COVERALLS_TOKEN}" ]; then | |
echo "### go tool cover" | |
# Run test coverage on each subdirectories and merge the coverage profile. | |
echo "mode: count" > coverage.out | |
# Standard go tooling behaviour is to ignore directories 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}/coverage.tmp ${dir} | |
if [ -f ${dir}/coverage.tmp ]; then | |
cat ${dir}/coverage.tmp | tail -n +2 >> coverage.out | |
rm ${dir}/coverage.tmp | |
fi | |
fi | |
done | |
go tool cover -func coverage.out | |
# To submit the test coverage result to coveralls.io use goveralls | |
# (https://github.com/mattn/goveralls) | |
goveralls -coverprofile coverage.out -service travis-ci -repotoken ${COVERALLS_TOKEN} | |
fi | |
RET=0 | |
if [ ${GOFMT_FAIL} -eq 1 ] ; then | |
echo "gofmt: FAIL" | |
RET=1 | |
else | |
echo "gofmt: PASS" | |
fi | |
if [ ${GOIMPORTS_FAIL} -eq 1 ] ; then | |
echo "goimports: FAIL" | |
RET=1 | |
else | |
echo "goimports: PASS" | |
fi | |
if [ ${GOLINT_FAIL} -eq 1 ] ; then | |
echo "golint: FAIL" | |
RET=1 | |
else | |
echo "golint: PASS" | |
fi | |
if [ ${GOVET_FAIL} -eq 1 ] ; then | |
echo "go vet: FAIL" | |
RET=1 | |
else | |
echo "go vet: PASS" | |
fi | |
if [ ${GOTEST_FAIL} -eq 1 ] ; then | |
echo "go test: FAIL" | |
RET=1 | |
else | |
echo "go test: PASS" | |
fi | |
exit ${RET} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of Go 1.6, vendor directories have been enabled by default, Godep paths have thus been superseded by vendor.