verify-vendor.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bash
  2. # Copyright 2015 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. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. # create a nice clean place to put our new licenses
  21. # must be in the user dir (e.g. KUBE_ROOT) in order for the docker volume mount
  22. # to work with docker-machine on macs
  23. mkdir -p "${KUBE_ROOT}/_tmp"
  24. _tmpdir="$(mktemp -d "${KUBE_ROOT}/_tmp/kube-vendor.XXXXXX")"
  25. if [[ -z ${KEEP_TMP:-} ]]; then
  26. KEEP_TMP=false
  27. fi
  28. function cleanup {
  29. # make go module dirs writeable
  30. chmod -R +w "${_tmpdir}"
  31. if [ "${KEEP_TMP}" == "true" ]; then
  32. echo "Leaving ${_tmpdir} for you to examine or copy. Please delete it manually when finished. (rm -rf ${_tmpdir})"
  33. else
  34. echo "Removing ${_tmpdir}"
  35. rm -rf "${_tmpdir}"
  36. fi
  37. }
  38. kube::util::trap_add cleanup EXIT
  39. # Copy the contents of the kube directory into the nice clean place (which is NOT shaped like a GOPATH)
  40. _kubetmp="${_tmpdir}"
  41. mkdir -p "${_kubetmp}"
  42. # should create ${_kubectmp}/kubernetes
  43. git archive --format=tar --prefix=kubernetes/ "$(git write-tree)" | (cd "${_kubetmp}" && tar xf -)
  44. _kubetmp="${_kubetmp}/kubernetes"
  45. # Do all our work in module mode
  46. export GO111MODULE=on
  47. pushd "${_kubetmp}" > /dev/null 2>&1
  48. # Destroy deps in the copy of the kube tree
  49. rm -rf ./Godeps/LICENSES ./vendor
  50. # Recreate the vendor tree using the nice clean set we just downloaded
  51. hack/update-vendor.sh
  52. popd > /dev/null 2>&1
  53. ret=0
  54. pushd "${KUBE_ROOT}" > /dev/null 2>&1
  55. # Test for diffs
  56. if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' go.mod "${_kubetmp}/go.mod")"; then
  57. echo "Your go.mod file is different:" >&2
  58. echo "${_out}" >&2
  59. echo "Vendor Verify failed." >&2
  60. echo "If you're seeing this locally, run the below command to fix your go.mod:" >&2
  61. echo "hack/update-vendor.sh" >&2
  62. ret=1
  63. fi
  64. if ! _out="$(diff -Naupr -x "BUILD" -x "AUTHORS*" -x "CONTRIBUTORS*" vendor "${_kubetmp}/vendor")"; then
  65. echo "Your vendored results are different:" >&2
  66. echo "${_out}" >&2
  67. echo "Vendor Verify failed." >&2
  68. echo "${_out}" > vendordiff.patch
  69. echo "If you're seeing this locally, run the below command to fix your directories:" >&2
  70. echo "hack/update-vendor.sh" >&2
  71. ret=1
  72. fi
  73. popd > /dev/null 2>&1
  74. if [[ ${ret} -gt 0 ]]; then
  75. exit ${ret}
  76. fi
  77. echo "Vendor Verified."
  78. # ex: ts=2 sw=2 et filetype=sh