internal: install tools from go.mod

Currently, we "go get <tools>" in vet.sh. This may download tools, which we don't want: we want all package download to be done through our go.mod. This CL solves the problem by switching from `go get <tools>` to `go install <tools>`.

Unfortunately, in the pre-1.11 environments we can't `go get ./...` to download our tools, even though they're deps in tools.go. tools.go has `+build tools`, which means we'd have to do `go get -tags tools ./...`. That also doesn't work, though, as the comment in continuous|presubmit.sh mentions: we get a "[...] is a program, not a package" error. So, in the pre-1.11 world, we simply `go get <tools>` as before.

Change-Id: I0833908796eeace8177dcf4f1685e6fdab952e3e
Reviewed-on: https://code-review.googlesource.com/c/38250
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Poydence <poy@google.com>
diff --git a/internal/kokoro/continuous.sh b/internal/kokoro/continuous.sh
index 31a3cca..26d9194 100755
--- a/internal/kokoro/continuous.sh
+++ b/internal/kokoro/continuous.sh
@@ -36,16 +36,28 @@
 try3() { eval "$*" || eval "$*" || eval "$*"; }
 if [[ `go version` == *"go1.11"* ]]; then
     export GO111MODULE=on
-    try3 go get .
+    # All packages, including +build tools, are fetched.
+    try3 go mod download
+
+    go install github.com/jstemmer/go-junit-report
 else
+    # Because we don't provide -tags tools, the +build tools dependencies
+    # aren't fetched.
     try3 go get -v -t ./...
+
+    # go get -tags tools ./... would fail with "[...]" is a program, not an
+    # importable package. So, we manually go get them in pre-module
+    # environments.
+    try3 go get -u \
+      github.com/golang/protobuf/protoc-gen-go \
+      github.com/jstemmer/go-junit-report \
+      golang.org/x/lint/golint \
+      golang.org/x/tools/cmd/goimports \
+      honnef.co/go/tools/cmd/staticcheck
 fi
 
 ./internal/kokoro/vet.sh
 
-# TODO(deklerk): Remove once tools are installed via tools.go.
-go get github.com/jstemmer/go-junit-report
-
 # Run tests and tee output to log file, to be pushed to GCS as artifact.
 # Also generate test summary in xUnit format to summarize the test execution.
 mkdir $KOKORO_ARTIFACTS_DIR/tests
diff --git a/internal/kokoro/presubmit.sh b/internal/kokoro/presubmit.sh
index fc5c375..dcdb973 100755
--- a/internal/kokoro/presubmit.sh
+++ b/internal/kokoro/presubmit.sh
@@ -24,19 +24,30 @@
 cd $GOCLOUD_HOME
 
 try3() { eval "$*" || eval "$*" || eval "$*"; }
-
 if [[ `go version` == *"go1.11"* ]]; then
     export GO111MODULE=on
-    try3 go get .
+    # All packages, including +build tools, are fetched.
+    try3 go mod download
+
+    go install github.com/jstemmer/go-junit-report
 else
+    # Because we don't provide -tags tools, the +build tools dependencies
+    # aren't fetched.
     try3 go get -v -t ./...
+
+    # go get -tags tools ./... would fail with "[...]" is a program, not an
+    # importable package. So, we manually go get them in pre-module
+    # environments.
+    try3 go get -u \
+      github.com/golang/protobuf/protoc-gen-go \
+      github.com/jstemmer/go-junit-report \
+      golang.org/x/lint/golint \
+      golang.org/x/tools/cmd/goimports \
+      honnef.co/go/tools/cmd/staticcheck
 fi
 
 ./internal/kokoro/vet.sh
 
-# TODO(deklerk): Remove once tools are installed via tools.go.
-go get github.com/jstemmer/go-junit-report
-
 # Run tests and tee output to log file, to be pushed to GCS as artifact.
 # Also generate test summary in xUnit format to summarize the test execution.
 mkdir $KOKORO_ARTIFACTS_DIR/tests
diff --git a/internal/kokoro/vet.sh b/internal/kokoro/vet.sh
index 4e01cac..86a3eea 100755
--- a/internal/kokoro/vet.sh
+++ b/internal/kokoro/vet.sh
@@ -23,9 +23,8 @@
 # Easier to debug CI.
 pwd
 
-try3() { eval "$*" || eval "$*" || eval "$*"; }
-
-try3 go get -u \
+# Should be downloaded in continuous.sh/presubmit.sh already.
+go install \
   golang.org/x/tools/cmd/goimports \
   golang.org/x/lint/golint \
   honnef.co/go/tools/cmd/staticcheck