verify-openapi-spec.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # This script checks whether updating of OpenAPI specification is needed or not.
  16. # We should run `hack/update-openapi-spec.sh` if OpenAPI specification is out of
  17. # date.
  18. # Usage: `hack/verify-openapi-spec.sh`.
  19. set -o errexit
  20. set -o nounset
  21. set -o pipefail
  22. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  23. source "${KUBE_ROOT}/hack/lib/init.sh"
  24. kube::golang::setup_env
  25. kube::etcd::install
  26. make -C "${KUBE_ROOT}" WHAT=cmd/kube-apiserver
  27. SPECROOT="${KUBE_ROOT}/api/openapi-spec"
  28. TMP_SPECROOT="${KUBE_ROOT}/_tmp/openapi-spec"
  29. _tmp="${KUBE_ROOT}/_tmp"
  30. mkdir -p "${_tmp}"
  31. cp -a "${SPECROOT}" "${TMP_SPECROOT}"
  32. trap 'cp -a ${TMP_SPECROOT} ${SPECROOT}/..; rm -rf ${_tmp}' EXIT SIGINT
  33. rm "${SPECROOT}"/*
  34. cp "${TMP_SPECROOT}/BUILD" "${SPECROOT}/BUILD"
  35. cp "${TMP_SPECROOT}/README.md" "${SPECROOT}/README.md"
  36. "${KUBE_ROOT}/hack/update-openapi-spec.sh"
  37. echo "diffing ${SPECROOT} against freshly generated openapi spec"
  38. ret=0
  39. diff -Naupr -I 'Auto generated by' "${SPECROOT}" "${TMP_SPECROOT}" || ret=$?
  40. if [[ $ret -eq 0 ]]
  41. then
  42. echo "${SPECROOT} up to date."
  43. else
  44. echo "${SPECROOT} is out of date. Please run hack/update-openapi-spec.sh" >&2
  45. exit 1
  46. fi
  47. # ex: ts=2 sw=2 et filetype=sh