vet.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env 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[0]}")/../..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. cd "${KUBE_ROOT}"
  21. # If called directly, exit.
  22. if [[ "${CALLED_FROM_MAIN_MAKEFILE:-""}" == "" ]]; then
  23. echo "ERROR: $0 should not be run directly." >&2
  24. echo >&2
  25. echo "Please run this command using \"make vet\""
  26. exit 1
  27. fi
  28. # This is required before we run govet for the results to be correct.
  29. # See https://github.com/golang/go/issues/16086 for details.
  30. go install ./cmd/...
  31. # Filter out arguments that start with "-" and move them to goflags.
  32. targets=()
  33. for arg; do
  34. if [[ "${arg}" == -* ]]; then
  35. goflags+=("${arg}")
  36. else
  37. targets+=("${arg}")
  38. fi
  39. done
  40. if [[ ${#targets[@]} -eq 0 ]]; then
  41. # Do not run on third_party directories or generated client code or build tools.
  42. while IFS='' read -r line; do
  43. targets+=("${line}")
  44. done < <(go list -e ./... | grep -E -v "/(build|third_party|vendor|staging|clientset_generated)/")
  45. fi
  46. go vet "${goflags[@]:+${goflags[@]}}" "${targets[@]}"