verify-generated-files.sh 1.4 KB

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