Browse code

Adds validate-vet script

resolves #11970

Signed-off-by: bobby abbott <ttobbaybbob@gmail.com>

bobby abbott authored on 2015/04/01 13:48:03
Showing 4 changed files
... ...
@@ -105,6 +105,10 @@ RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env
105 105
 # Grab Go's cover tool for dead-simple code coverage testing
106 106
 RUN go get golang.org/x/tools/cmd/cover
107 107
 
108
+# Grab Go's vet tool for examining go code to find suspicious constructs
109
+# and help prevent errors that the compiler might not catch
110
+RUN go get golang.org/x/tools/cmd/vet
111
+
108 112
 # TODO replace FPM with some very minimal debhelper stuff
109 113
 RUN gem install --no-rdoc --no-ri fpm --version 1.3.2
110 114
 
... ...
@@ -77,7 +77,7 @@ test-docker-py: build
77 77
 	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py
78 78
 
79 79
 validate: build
80
-	$(DOCKER_RUN_DOCKER) hack/make.sh validate-gofmt validate-dco validate-toml
80
+	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-toml validate-vet
81 81
 
82 82
 shell: build
83 83
 	$(DOCKER_RUN_DOCKER) bash
... ...
@@ -45,6 +45,7 @@ DEFAULT_BUNDLES=(
45 45
 	validate-dco
46 46
 	validate-gofmt
47 47
 	validate-toml
48
+	validate-vet
48 49
 
49 50
 	binary
50 51
 
51 52
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+#!/bin/bash
1
+
2
+source "$(dirname "$BASH_SOURCE")/.validate"
3
+
4
+IFS=$'\n'
5
+files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
6
+unset IFS
7
+
8
+for f in "${files[@]}"; do
9
+    # we use "git show" here to validate that what's committed is vetted
10
+    failedVet=$(git show "$VALIDATE_HEAD:$f" | go vet)
11
+    if [ $failedVet ]; then
12
+        fails=yes
13
+        echo $failedVet
14
+    fi
15
+done
16
+
17
+if [ $fails ]; then
18
+    echo 'Please review and resolve the above issues and commit the result.'
19
+else
20
+    echo 'All Go source files have been vetted.'
21
+fi