fmt check in script; fail build on gofmt problems

This commit is contained in:
Trevor Rosen 2017-11-09 13:35:02 -06:00
parent 9d5449d173
commit 591c2909c6
No known key found for this signature in database
GPG Key ID: 56054B6FF40DE0F9
2 changed files with 20 additions and 3 deletions

View File

@ -1,7 +1,6 @@
.PHONY: test race cover robeaux examples deps test_with_coverage fmt_check
excluding_vendor := $(shell go list ./... | grep -v /vendor/)
gofiles_excluding_vendor = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
# Run tests on all non-vendor directories
test:
@ -13,11 +12,11 @@ race:
# Check for code well-formedness
fmt_check:
gofmt -d $(gofiles_excluding_vendor)
./ci/format.sh
# Test and generate coverage
test_with_coverage:
./ci/test.sh || exit 1
./ci/test.sh
deps:
ifeq (,$(shell which dep))

18
ci/format.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
## Only uncomment the below for debugging
#set -euxo pipefail
pushd $PWD/..
GO_FILES_EXCLUDING_VENDOR=$(find . -type f -name '*.go' -not -path "./vendor/*")
FMT_RESULTS=$(gofmt -l $GO_FILES_EXCLUDING_VENDOR)
if [ ${#FMT_RESULTS[@]} -ne 0 ]; then
# some files have formatting errors
echo "--- gofmt found errors found in the following files:"
echo $FMT_RESULTS
exit 1
else
# no files have formatting errors
exit 0
fi
popd