verify-generated-protobuf.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env 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[0]}")/..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. kube::golang::setup_env
  21. APIROOTS=$({
  22. # gather the packages explicitly requesting generation
  23. git grep --files-with-matches -e '// +k8s:protobuf-gen=package' cmd pkg staging | xargs -n 1 dirname
  24. # add the root apimachinery pkg containing implicitly generated files (--apimachinery-packages)
  25. echo staging/src/k8s.io/apimachinery/pkg
  26. } | sort | uniq)
  27. _tmp="${KUBE_ROOT}/_tmp"
  28. cleanup() {
  29. rm -rf "${_tmp}"
  30. }
  31. trap "cleanup" EXIT SIGINT
  32. cleanup
  33. for APIROOT in ${APIROOTS}; do
  34. mkdir -p "${_tmp}/${APIROOT}"
  35. cp -a "${KUBE_ROOT}/${APIROOT}"/* "${_tmp}/${APIROOT}/"
  36. done
  37. KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-protobuf.sh"
  38. for APIROOT in ${APIROOTS}; do
  39. TMP_APIROOT="${_tmp}/${APIROOT}"
  40. echo "diffing ${APIROOT} against freshly generated protobuf"
  41. ret=0
  42. diff -Naupr -I 'Auto generated by' -x 'zz_generated.*' -x '.github' "${KUBE_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$?
  43. cp -a "${TMP_APIROOT}"/* "${KUBE_ROOT}/${APIROOT}/"
  44. if [[ $ret -eq 0 ]]; then
  45. echo "${APIROOT} up to date."
  46. else
  47. echo "${APIROOT} is out of date. Please run hack/update-generated-protobuf.sh"
  48. exit 1
  49. fi
  50. done