verify.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # Copyright 2014 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}/cluster/lib/util.sh"
  20. # Excluded checks are always skipped.
  21. EXCLUDED_CHECKS=(
  22. "verify-linkcheck.sh" # runs in separate Jenkins job once per day due to high network usage
  23. "verify-govet.sh" # it has a separate make vet target
  24. )
  25. function is-excluded {
  26. if [[ $1 -ef "$KUBE_ROOT/hack/verify-all.sh" ]]; then
  27. return
  28. fi
  29. for e in ${EXCLUDED_CHECKS[@]}; do
  30. if [[ $1 -ef "$KUBE_ROOT/hack/$e" ]]; then
  31. return
  32. fi
  33. done
  34. return 1
  35. }
  36. function run-cmd {
  37. if ${SILENT}; then
  38. "$@" &> /dev/null
  39. else
  40. "$@"
  41. fi
  42. }
  43. function run-checks {
  44. local -r pattern=$1
  45. local -r runner=$2
  46. for t in $(ls ${pattern})
  47. do
  48. if is-excluded "${t}" ; then
  49. echo "Skipping ${t}"
  50. continue
  51. fi
  52. echo -e "Verifying ${t}"
  53. local start=$(date +%s)
  54. run-cmd "${runner}" "${t}" && tr=$? || tr=$?
  55. local elapsed=$(($(date +%s) - ${start}))
  56. if [[ ${tr} -eq 0 ]]; then
  57. echo -e "${color_green}SUCCESS${color_norm} ${t}\t${elapsed}s"
  58. else
  59. echo -e "${color_red}FAILED${color_norm} ${t}\t${elapsed}s"
  60. ret=1
  61. fi
  62. done
  63. }
  64. while getopts ":v" opt; do
  65. case ${opt} in
  66. v)
  67. SILENT=false
  68. ;;
  69. \?)
  70. echo "Invalid flag: -${OPTARG}" >&2
  71. exit 1
  72. ;;
  73. esac
  74. done
  75. if ${SILENT} ; then
  76. echo "Running in silent mode, run with -v if you want to see script logs."
  77. fi
  78. ret=0
  79. run-checks "${KUBE_ROOT}/hack/verify-*.sh" bash
  80. run-checks "${KUBE_ROOT}/hack/verify-*.py" python
  81. exit ${ret}
  82. # ex: ts=2 sw=2 et filetype=sh