verify-readonly-packages.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Copyright 2017 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. # verify-readonly-packages.sh checks whether between $KUBE_VERIFY_GIT_BRANCH and HEAD files
  16. # in readonly directories were modified. A directory is readonly iff it contains a .readonly
  17. # file. Being readonly DOES NOT apply recursively to subdirectories.
  18. set -o errexit
  19. set -o nounset
  20. set -o pipefail
  21. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  22. source "${KUBE_ROOT}/hack/lib/init.sh"
  23. readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
  24. find_files() {
  25. find . -not \( \
  26. \( \
  27. -wholename './output' \
  28. -o -wholename './_output' \
  29. -o -wholename './_gopath' \
  30. -o -wholename './release' \
  31. -o -wholename './target' \
  32. -o -wholename '*/third_party/*' \
  33. -o -wholename '*/vendor/*' \
  34. -o -wholename './staging/src/k8s.io/client-go/*vendor/*' \
  35. -o -wholename './staging/src/k8s.io/client-go/pkg/*' \
  36. \) -prune \
  37. \) -name '.readonly'
  38. }
  39. conflicts=()
  40. while IFS=$'\n' read -r dir; do
  41. dir=${dir#./}
  42. if kube::util::has_changes "${branch}" "^${dir}/[^/]*\$" '/\.readonly$|/BUILD$|/zz_generated|/\.generated\.|\.proto$|\.pb\.go$' >/dev/null; then
  43. conflicts+=("${dir}")
  44. fi
  45. done < <(find_files | sed 's|/.readonly||')
  46. if [ ${#conflicts[@]} -gt 0 ]; then
  47. exec 1>&2
  48. for dir in "${conflicts[@]}"; do
  49. echo "Found ${dir}/.readonly, but files changed compared to \"${branch}\" branch."
  50. done
  51. exit 1
  52. else
  53. echo "Readonly packages verified."
  54. fi
  55. # ex: ts=2 sw=2 et filetype=sh