From 591c2909c63c89981f689e39d3a1b8c56da899ba Mon Sep 17 00:00:00 2001 From: Trevor Rosen Date: Thu, 9 Nov 2017 13:35:02 -0600 Subject: [PATCH] fmt check in script; fail build on gofmt problems --- Makefile | 5 ++--- ci/format.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100755 ci/format.sh diff --git a/Makefile b/Makefile index 1bfe45fb..581a6450 100644 --- a/Makefile +++ b/Makefile @@ -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)) diff --git a/ci/format.sh b/ci/format.sh new file mode 100755 index 00000000..db59b443 --- /dev/null +++ b/ci/format.sh @@ -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