From ddcc75658740d174c2f8a93f354a012fbf8cc546 Mon Sep 17 00:00:00 2001 From: bobby abbott Date: Tue, 31 Mar 2015 21:48:03 -0700 Subject: [PATCH 1/2] Adds validate-vet script resolves #11970 Signed-off-by: bobby abbott Upstream-commit: 3280ce651b13866f93440b60a9182f9a4f9f14b9 Component: engine --- components/engine/Dockerfile | 4 ++++ components/engine/Makefile | 2 +- components/engine/hack/make.sh | 1 + components/engine/hack/make/validate-vet | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 components/engine/hack/make/validate-vet diff --git a/components/engine/Dockerfile b/components/engine/Dockerfile index b54fda5614..3cf5eb5ce5 100644 --- a/components/engine/Dockerfile +++ b/components/engine/Dockerfile @@ -105,6 +105,10 @@ RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env # Grab Go's cover tool for dead-simple code coverage testing RUN go get golang.org/x/tools/cmd/cover +# Grab Go's vet tool for examining go code to find suspicious constructs +# and help prevent errors that the compiler might not catch +RUN go get golang.org/x/tools/cmd/vet + # TODO replace FPM with some very minimal debhelper stuff RUN gem install --no-rdoc --no-ri fpm --version 1.3.2 diff --git a/components/engine/Makefile b/components/engine/Makefile index 9bf1b16c94..7978b632ca 100644 --- a/components/engine/Makefile +++ b/components/engine/Makefile @@ -77,7 +77,7 @@ test-docker-py: build $(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py validate: build - $(DOCKER_RUN_DOCKER) hack/make.sh validate-gofmt validate-dco validate-toml + $(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-toml validate-vet shell: build $(DOCKER_RUN_DOCKER) bash diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index 1ab1d8137e..3bcb265b3c 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -45,6 +45,7 @@ DEFAULT_BUNDLES=( validate-dco validate-gofmt validate-toml + validate-vet binary diff --git a/components/engine/hack/make/validate-vet b/components/engine/hack/make/validate-vet new file mode 100644 index 0000000000..994a6ac03d --- /dev/null +++ b/components/engine/hack/make/validate-vet @@ -0,0 +1,22 @@ +#!/bin/bash + +source "$(dirname "$BASH_SOURCE")/.validate" + +IFS=$'\n' +files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) +unset IFS + +for f in "${files[@]}"; do + # we use "git show" here to validate that what's committed is vetted + failedVet=$(git show "$VALIDATE_HEAD:$f" | go vet) + if [ $failedVet ]; then + fails=yes + echo $failedVet + fi +done + +if [ $fails ]; then + echo 'Please review and resolve the above issues and commit the result.' +else + echo 'All Go source files have been vetted.' +fi From 73aea165889d45da38a6573d2124c08f2df8cec7 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Mon, 13 Apr 2015 11:31:17 -0700 Subject: [PATCH 2/2] change tabs to spaces Signed-off-by: Jessica Frazelle Upstream-commit: f3ba0a6a3505f5c5c690b84a4db2255fea9af18f Component: engine --- components/engine/hack/make/validate-vet | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/components/engine/hack/make/validate-vet b/components/engine/hack/make/validate-vet index 994a6ac03d..e88f7549c3 100644 --- a/components/engine/hack/make/validate-vet +++ b/components/engine/hack/make/validate-vet @@ -6,17 +6,27 @@ IFS=$'\n' files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) unset IFS +errors=() for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed is vetted - failedVet=$(git show "$VALIDATE_HEAD:$f" | go vet) - if [ $failedVet ]; then - fails=yes - echo $failedVet - fi + # we use "git show" here to validate that what's committed passes go vet + failedVet=$(go vet "$f") + if [ "$failedVet" ]; then + errors+=( "$failedVet" ) + fi done -if [ $fails ]; then - echo 'Please review and resolve the above issues and commit the result.' + +if [ ${#errors[@]} -eq 0 ]; then + echo 'Congratulations! All Go source files have been vetted.' else - echo 'All Go source files have been vetted.' + { + echo "Errors from go vet:" + for err in "${errors[@]}"; do + echo " - $err" + done + echo + echo 'Please fix the above errors. You can test via "go vet" and commit the result.' + echo + } >&2 + false fi