From 4f5005b6bdb082c00ff123f30a886697b0d41829 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 23 Sep 2015 21:15:21 +0200 Subject: [PATCH] Add govet target and script Signed-off-by: Vincent Demeester --- Makefile | 5 ++++- script/validate-govet | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 script/validate-govet diff --git a/Makefile b/Makefile index c715199be..128f7d63e 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,14 @@ test-integration: build $(DOCKER_RUN_TRAEFIK) ./script/make.sh generate binary test-integration validate: build - $(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt + $(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt validate-govet validate-gofmt: build $(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt +validate-govet: build + $(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-govet + build: dist docker build -t "$(TRAEFIK_DEV_IMAGE)" -f build.Dockerfile . diff --git a/script/validate-govet b/script/validate-govet new file mode 100755 index 000000000..df21d3f09 --- /dev/null +++ b/script/validate-govet @@ -0,0 +1,31 @@ +#!/bin/bash + +source "$(dirname "$BASH_SOURCE")/.validate" + +IFS=$'\n' +files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^Godeps/' || true) ) +unset IFS + +errors=() +for f in "${files[@]}"; do + # we use "git show" here to validate that what's committed passes go vet + failedVet=$(go tool vet -printf=false "$f") + if [ "$failedVet" ]; then + errors+=( "$failedVet" ) + fi +done + +if [ ${#errors[@]} -eq 0 ]; then + echo 'Congratulations! All Go source files have been vetted.' +else + { + echo "Errors from govet:" + 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