hack/verify-govet.sh
6f45c69b
 #!/bin/bash
 
 set -o nounset
 set -o pipefail
 
 GO_VERSION=($(go version))
 
27df2696
 if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.[4-5]') ]]; then
6f45c69b
   echo "Unknown go version '${GO_VERSION}', skipping go vet."
   exit 0
 fi
 
 OS_ROOT=$(dirname "${BASH_SOURCE}")/..
 source "${OS_ROOT}/hack/common.sh"
 source "${OS_ROOT}/hack/util.sh"
 
 cd "${OS_ROOT}"
 mkdir -p _output/govet
 
772b5fa0
 os::build::setup_env
 
6f45c69b
 FAILURE=false
aff1d6b5
 test_dirs=$(find_files | cut -d '/' -f 1-2 | sort -u)
6f45c69b
 for test_dir in $test_dirs
 do
398ef03e
   go tool vet -shadow=false $test_dir
6f45c69b
   if [ "$?" -ne 0 ]
19ec3fd8
   then
6f45c69b
     FAILURE=true
   fi
 done
 
27df2696
 # For the sake of slowly white-listing `shadow` checks, we need to keep track of which
 # directories we're searching through. The following are all of the directories we care about:
 # all top-level directories except for 'pkg', and all second-level subdirectories of 'pkg'.
 ALL_DIRS=$(find_files | grep -Eo "\./([^/]+|pkg/[^/]+)" | sort -u)
 
e4e3a118
 DIR_BLACKLIST='./hack
27df2696
 ./pkg/api
 ./pkg/authorization
 ./pkg/build
 ./pkg/client
 ./pkg/cmd
 ./pkg/deploy
 ./pkg/diagnostics
 ./pkg/dockerregistry
 ./pkg/generate
 ./pkg/gitserver
 ./pkg/image
 ./pkg/oauth
 ./pkg/project
 ./pkg/router
 ./pkg/security
 ./pkg/serviceaccounts
 ./pkg/template
 ./pkg/user
 ./pkg/util
 ./test
 ./tools'
 
 for test_dir in $ALL_DIRS
 do
   # use `grep` failure to determine that a directory is not in the blacklist 
   if ! echo "${DIR_BLACKLIST}" | grep -q "${test_dir}"; then
     go tool vet -shadow -shadowstrict $test_dir
     if [ "$?" -ne "0" ]
     then
       FAILURE=true
     fi
   fi
 done
 
19ec3fd8
 # We don't want to exit on the first failure of go vet, so just keep track of
 # whether a failure occurred or not.
6f45c69b
 if $FAILURE
 then
   echo "FAILURE: go vet failed!"
   exit 1
 else
   echo "SUCCESS: go vet succeded!"
   exit 0
19ec3fd8
 fi