From dacf0e033add57129c55e4e2abe5b1e9facf7207 Mon Sep 17 00:00:00 2001 From: Ken Robertson Date: Tue, 12 Aug 2014 23:01:21 -0700 Subject: [PATCH] Fix Travis to properly fail the build on go fmt and go vet. When running go fmt/vet, they do not exit non-zero if they detect any issues, they only print out information. This wraps go fmt/vet in a script that captures the output to a temp file and checks if anything was written to it. If any was, it prints it out then exits 1. --- .travis.yml | 4 ++-- travis/gofmt.sh | 13 +++++++++++++ travis/govet.sh | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 travis/gofmt.sh create mode 100755 travis/govet.sh diff --git a/.travis.yml b/.travis.yml index fbf149ca..1bc95ca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,8 @@ install: - go get github.com/mattn/goveralls script: - go build -- go fmt ./... -- go vet ./... +- ./travis/gofmt.sh +- ./travis/govet.sh - go test -i -race ./... - go test -v -race ./... - ./travis/coveralls-script.sh diff --git a/travis/gofmt.sh b/travis/gofmt.sh new file mode 100755 index 00000000..03931943 --- /dev/null +++ b/travis/gofmt.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# run go fmt and exit non-zero if it detected anything +T=$(mktemp -t gofmt.XXXXX) +go fmt ./... > $T +if egrep -q '.*' "$T" ; then + echo "go fmt failed on the following files:" + cat "$T" + rm $T + exit 1 +fi +rm $T +exit 0 diff --git a/travis/govet.sh b/travis/govet.sh new file mode 100755 index 00000000..0c38d347 --- /dev/null +++ b/travis/govet.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# run go vet and exit non-zero if it detected anything +T=$(mktemp -t govet.XXXXX) +go vet ./... > $T +if egrep -q '.*' "$T" ; then + echo "go vet failed on the following files:" + cat "$T" + rm $T + exit 1 +fi +rm $T +exit 0