verify-generated-swagger-docs.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # Copyright 2015 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. kube::golang::setup_env
  21. make -C "${KUBE_ROOT}" WHAT=cmd/genswaggertypedocs
  22. # Find binary
  23. genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs")
  24. if [[ ! -x "$genswaggertypedocs" ]]; then
  25. {
  26. echo "It looks as if you don't have a compiled genswaggertypedocs binary"
  27. echo
  28. echo "If you are running from a clone of the git repo, please run"
  29. echo "'make WHAT=cmd/genswaggertypedocs'."
  30. } >&2
  31. exit 1
  32. fi
  33. DIFFROOT="${KUBE_ROOT}/pkg"
  34. TMP_DIFFROOT="${KUBE_ROOT}/_tmp/pkg"
  35. _tmp="${KUBE_ROOT}/_tmp"
  36. mkdir -p "${_tmp}"
  37. trap "rm -rf ${_tmp}" EXIT SIGINT
  38. cp -a "${DIFFROOT}" "${TMP_DIFFROOT}"
  39. "${KUBE_ROOT}/hack/update-generated-swagger-docs.sh"
  40. echo "diffing ${DIFFROOT} against freshly generated swagger type documentation"
  41. ret=0
  42. diff -Naupr -I 'Auto generated by' "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
  43. cp -a "${TMP_DIFFROOT}" "${KUBE_ROOT}/"
  44. if [[ $ret -eq 0 ]]
  45. then
  46. echo "${DIFFROOT} up to date."
  47. else
  48. echo "${DIFFROOT} is out of date. Please run hack/update-generated-swagger-docs.sh"
  49. exit 1
  50. fi