verify-generated-files.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. # Copyright 2018 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 generated code is needed or not. We
  16. # should run `make generated_files` if generated code is out of date.
  17. # Usage: `hack/verify-generated-files.sh`.
  18. set -o errexit
  19. set -o nounset
  20. set -o pipefail
  21. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  22. export KUBE_ROOT
  23. source "${KUBE_ROOT}/hack/lib/init.sh"
  24. kube::util::ensure_clean_working_dir
  25. _tmpdir="$(kube::realpath "$(mktemp -d -t verify-generated-files.XXXXXX)")"
  26. kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
  27. _tmp_gopath="${_tmpdir}/go"
  28. _tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
  29. mkdir -p "${_tmp_kuberoot}/.."
  30. cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."
  31. cd "${_tmp_kuberoot}"
  32. # clean out anything from the temp dir that's not checked in
  33. git clean -ffxd
  34. # regenerate any generated code
  35. make generated_files
  36. changed_files=$(git status --porcelain)
  37. if [[ -n "${changed_files}" ]]; then
  38. echo "!!! Generated code is out of date:" >&2
  39. echo "${changed_files}" >&2
  40. echo >&2
  41. echo "Please run make generated_files." >&2
  42. exit 1
  43. fi