verify-readonly-packages.sh 2.1 KB

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