From 3fa48e54fffaeccf5c88f041a07fc07e45cb36d9 Mon Sep 17 00:00:00 2001 From: Crazykev Date: Wed, 14 Dec 2016 19:31:24 +0800 Subject: [PATCH] add gofmt verify in CI Signed-off-by: Crazykev --- .travis.yml | 1 + Makefile | 5 +++++ hack/verify-gofmt.sh | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100755 hack/verify-gofmt.sh diff --git a/.travis.yml b/.travis.yml index 14416ccd..811546a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ before_script: script: - make .gitvalidation + - make gofmt - make lint - make integration - make docs diff --git a/Makefile b/Makefile index 0efb696c..1f580edb 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ help: @echo " * 'integration' - Execute integration tests" @echo " * 'clean' - Clean artifacts" @echo " * 'lint' - Execute the source code linter" + @echo " * 'gofmt' - Verify the source code gofmt" lint: ${OCID_LINK} @which gometalinter > /dev/null 2>/dev/null || (echo "ERROR: gometalinter not found. Consider 'make install.tools' target" && false) @@ -40,6 +41,9 @@ ${OCID_LINK}: mkdir -p ${OCID_LINK_DIR} ln -sfn ${CURDIR} ${OCID_LINK} +gofmt: + @./hack/verify-gofmt.sh + conmon: make -C $@ @@ -164,6 +168,7 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man conmon \ default \ docs \ + gofmt \ help \ install \ lint \ diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh new file mode 100755 index 00000000..5577d1b9 --- /dev/null +++ b/hack/verify-gofmt.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +find_files() { + find . -not \( \ + \( \ + -wholename '*/vendor/*' \ + \) -prune \ + \) -name '*.go' +} + +GOFMT="gofmt -s" +bad_files=$(find_files | xargs $GOFMT -l) +if [[ -n "${bad_files}" ]]; then + echo "!!! '$GOFMT' needs to be run on the following files: " + echo "${bad_files}" + exit 1 +fi