verify-generated-protobuf.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. APIROOTS=${APIROOTS:-pkg/api pkg/apis pkg/runtime pkg/util/intstr pkg/watch}
  22. _tmp="${KUBE_ROOT}/_tmp"
  23. cleanup() {
  24. rm -rf "${_tmp}"
  25. }
  26. trap "cleanup" EXIT SIGINT
  27. cleanup
  28. for APIROOT in ${APIROOTS}; do
  29. mkdir -p "${_tmp}/${APIROOT%/*}"
  30. cp -a "${KUBE_ROOT}/${APIROOT}" "${_tmp}/${APIROOT}"
  31. done
  32. "${KUBE_ROOT}/hack/update-generated-protobuf.sh"
  33. for APIROOT in ${APIROOTS}; do
  34. TMP_APIROOT="${_tmp}/${APIROOT}"
  35. echo "diffing ${APIROOT} against freshly generated protobuf"
  36. ret=0
  37. diff -Naupr -I 'Auto generated by' -x 'zz_generated.*' "${KUBE_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$?
  38. cp -a "${TMP_APIROOT}" "${KUBE_ROOT}/${APIROOT%/*}"
  39. if [[ $ret -eq 0 ]]; then
  40. echo "${APIROOT} up to date."
  41. else
  42. echo "${APIROOT} is out of date. Please run hack/update-generated-protobuf.sh"
  43. exit 1
  44. fi
  45. done