vuln: run checks with go test

Remove the "go test" code from all.bash and rename the file to
checks.bash, for reasons explained below.

Add a Go test file to the repo root that shells out to checks.bash.

Now `go test ./...` does everything we want: runs the Go tests
and all the checks.

The  trybot builders don't have git. We use it just to find
the CL diffs in order to optimize the license header check.
Instead of trying to install it, check just .go and .sh files
for license headers.

This means that trybots should be sufficient for CI; we
don't need kokoro. So remove devtools/ci.sh.

Change-Id: I7e28a83228e78b944972309dcf73765cc5ffbebf
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/370114
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/all_test.go b/all_test.go
new file mode 100644
index 0000000..d008ad8
--- /dev/null
+++ b/all_test.go
@@ -0,0 +1,23 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build go1.17 && !windows
+// +build go1.17,!windows
+
+package main
+
+import (
+	"os"
+	"os/exec"
+	"testing"
+)
+
+func Test(t *testing.T) {
+	cmd := exec.Command("./checks.bash")
+	cmd.Stdout = os.Stdout
+	cmd.Stderr = os.Stderr
+	if err := cmd.Run(); err != nil {
+		t.Fatal(err)
+	}
+}
diff --git a/all.bash b/checks.bash
similarity index 74%
rename from all.bash
rename to checks.bash
index 0a46ce8..3195612 100755
--- a/all.bash
+++ b/checks.bash
@@ -3,6 +3,17 @@
 # Use of this source code is governed by a BSD-style
 # license that can be found in the LICENSE file.
 
+# This file will be run by `go test`.
+# See all_test.go in this directory.
+
+go version
+
+# Ensure that installed go binaries are on the path.
+# This bash expression follows the algorithm described at the top of
+# `go install help`: first try $GOBIN, then $GOPATH/bin, then $HOME/go/bin.
+go_install_dir=${GOBIN:-${GOPATH:-$HOME/go}/bin}
+PATH=$PATH:$go_install_dir
+
 source devtools/lib.sh
 
 # ensure_go_binary verifies that a binary exists in $PATH corresponding to the
@@ -12,7 +23,7 @@
   if ! [ -x "$(command -v $binary)" ]; then
     info "Installing: $1"
     # Install the binary in a way that doesn't affect our go.mod file.
-    go install $1@latest
+    go install $1@master
   fi
 }
 
@@ -22,7 +33,7 @@
   if [[ "$@" != "" ]]; then
     for FILE in $@
     do
-        line="$(head -1 $FILE)"
+        line="$(head -4 $FILE)"
         if [[ ! $line == *"The Go Authors. All rights reserved."* ]] &&
          [[ ! $line == "// DO NOT EDIT. This file was copied from" ]]; then
               err "missing license header: $FILE"
@@ -31,14 +42,9 @@
   fi
 }
 
-# Support ** in globs for findcode.
+# Support ** in globs for finding files throughout the tree.
 shopt -s globstar
 
-# findcode finds source files in the repo.
-findcode() {
-  find **/*.go
-}
-
 # check_headers checks that all source files that have been staged in this
 # commit, and all other non-third-party files in the repo, have a license
 # header.
@@ -47,11 +53,9 @@
     info "Checking listed files for license header"
     verify_header $*
   else
-    info "Checking staged files for license header"
     # Check code files that have been modified or added.
-    verify_header $(git diff --cached --name-status | grep -vE "^D" | cut -f 2- | grep -E ".go$|.sh$")
-    info "Checking go files for license header"
-    verify_header $(findcode)
+    info "Checking go and sh files for license header"
+    verify_header $(find **/*.go) $(find **/*.sh)
   fi
 }
 
@@ -82,36 +86,24 @@
   check_vet
   check_staticcheck
   check_misspell
-  check_unparam
+  # Commented out pending https://github.com/mvdan/unparam/issues/59.
+  # check_unparam
 }
 
 go_modtidy() {
   runcmd go mod tidy
 }
 
-go_test() {
-  runcmd go test ./...
-}
-
 runchecks() {
   check_headers
   go_linters
   go_modtidy
-  go_test
 }
 
 usage() {
   cat <<EOUSAGE
 Usage: $0 [subcommand]
 Available subcommands:
-  (empty)        - run all standard checks and tests:
-     * headers: check source files for the license disclaimer
-     * vet: run go vet on source files
-     * staticcheck: run staticcheck on source files
-     * misspell: run misspell on source files
-     * unparam: run unparam on source files
-     * tidy: run go mod tidy
-     * tests: run all Go tests
   help           - display this help message
 EOUSAGE
 }
diff --git a/devtools/ci.sh b/devtools/ci.sh
deleted file mode 100755
index edd244a..0000000
--- a/devtools/ci.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2021 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-# This script will be run by our Kokoro job, whose configuration
-# can be found under go/kokoro in Google3's internal repo.
-# It is run from the repo's root directory.
-
-docker run -v $PWD:/vuln -w /vuln golang:1.17.3 ./all.bash