vet.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # Copyright 2016 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. cd "${KUBE_ROOT}"
  21. # This is required before we run govet for the results to be correct.
  22. # See https://github.com/golang/go/issues/16086 for details.
  23. make generated_files
  24. go install ./cmd/...
  25. # Use eval to preserve embedded quoted strings.
  26. eval "goflags=(${KUBE_GOFLAGS:-})"
  27. # Filter out arguments that start with "-" and move them to goflags.
  28. targets=()
  29. for arg; do
  30. if [[ "${arg}" == -* ]]; then
  31. goflags+=("${arg}")
  32. else
  33. targets+=("${arg}")
  34. fi
  35. done
  36. if [[ ${#targets[@]} -eq 0 ]]; then
  37. # Do not run on third_party directories or generated client code.
  38. targets=$(go list -e ./... | egrep -v "/(third_party|vendor|staging|clientset_generated)/")
  39. fi
  40. go vet "${goflags[@]:+${goflags[@]}}" ${targets[@]}