Skip to content

Commit

Permalink
fmt check in script; fail build on gofmt problems
Browse files Browse the repository at this point in the history
  • Loading branch information
trevrosen committed Nov 9, 2017
1 parent 9d5449d commit 591c290
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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))
Expand Down
18 changes: 18 additions & 0 deletions ci/format.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 591c290

Please sign in to comment.