verify-imports.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 restricted packages are imported or not and outputs the
  16. # result. Target directory's path and allowed packages against checking are
  17. # listed in `staging/publishing/import-restrictions.yaml`.
  18. # Usage: `hack/verify-imports.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. kube::golang::setup_env
  25. make -C "${KUBE_ROOT}" WHAT=cmd/importverifier
  26. # Find binary
  27. importverifier=$(kube::util::find-binary "importverifier")
  28. if [[ ! -x "$importverifier" ]]; then
  29. {
  30. echo "It looks as if you don't have a compiled importverifier binary"
  31. echo
  32. echo "If you are running from a clone of the git repo, please run"
  33. echo "'make WHAT=cmd/importverifier'."
  34. } >&2
  35. exit 1
  36. fi
  37. "${importverifier}" "k8s.io/" "${KUBE_ROOT}/staging/publishing/import-restrictions.yaml"