verify-no-vendor-cycles.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  19. export GO111MODULE=auto
  20. staging_repos=($(ls "${KUBE_ROOT}/staging/src/k8s.io/"))
  21. staging_repos_pattern=$(IFS="|"; echo "${staging_repos[*]}")
  22. failed=false
  23. for i in $(find vendor/ -type d); do
  24. deps=$(go list -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' ./$i 2> /dev/null || echo "")
  25. deps_on_main=$(echo "${deps}" | grep -v "k8s.io/kubernetes/vendor/" | grep "k8s.io/kubernetes" || echo "")
  26. if [ -n "${deps_on_main}" ]; then
  27. echo "Package ${i} has a cyclic dependency on the main repository."
  28. failed=true
  29. fi
  30. deps_on_staging=$(echo "${deps}" | grep "k8s.io/kubernetes/vendor/k8s.io" | grep -E "k8s.io\/${staging_repos_pattern}\>" || echo "")
  31. if [ -n "${deps_on_staging}" ]; then
  32. echo "Package ${i} has a cyclic dependency on staging repository packages: ${deps_on_staging}"
  33. failed=true
  34. fi
  35. done
  36. if [[ "${failed}" == "true" ]]; then
  37. exit 1
  38. fi