verify-godeps.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/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. # As of go 1.6, the vendor experiment is enabled by default.
  19. export GO15VENDOREXPERIMENT=1
  20. #### HACK ####
  21. # Sometimes godep just can't handle things. This lets use manually put
  22. # some deps in place first, so godep won't fall over.
  23. preload-dep() {
  24. org="$1"
  25. project="$2"
  26. sha="$3"
  27. org_dir="${GOPATH}/src/${org}"
  28. mkdir -p "${org_dir}"
  29. pushd "${org_dir}" > /dev/null
  30. git clone "https://${org}/${project}.git" > /dev/null 2>&1
  31. pushd "${org_dir}/${project}" > /dev/null
  32. git checkout "${sha}" > /dev/null 2>&1
  33. popd > /dev/null
  34. popd > /dev/null
  35. }
  36. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  37. source "${KUBE_ROOT}/hack/lib/init.sh"
  38. kube::golang::verify_godep_version
  39. readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
  40. if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
  41. ! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/' && \
  42. ! kube::util::has_changes_against_upstream_branch "${branch}" 'vendor/'; then
  43. exit 0
  44. fi
  45. # Create a nice clean place to put our new godeps
  46. _tmpdir="$(mktemp -d -t gopath.XXXXXX)"
  47. function cleanup {
  48. echo "Removing ${_tmpdir}"
  49. rm -rf "${_tmpdir}"
  50. }
  51. trap cleanup EXIT
  52. # Copy the contents of the kube directory into the nice clean place
  53. _kubetmp="${_tmpdir}/src/k8s.io"
  54. mkdir -p "${_kubetmp}"
  55. # should create ${_kubectmp}/kubernetes
  56. git archive --format=tar --prefix=kubernetes/ $(git write-tree) | (cd "${_kubetmp}" && tar xf -)
  57. _kubetmp="${_kubetmp}/kubernetes"
  58. # Do all our work in the new GOPATH
  59. export GOPATH="${_tmpdir}"
  60. cd "${_kubetmp}"
  61. # Build the godep tool
  62. go get -u github.com/tools/godep 2>/dev/null
  63. GODEP="${GOPATH}/bin/godep"
  64. pin-godep() {
  65. pushd "${GOPATH}/src/github.com/tools/godep" > /dev/null
  66. git checkout "$1"
  67. "${GODEP}" go install
  68. popd > /dev/null
  69. }
  70. # Use to following if we ever need to pin godep to a specific version again
  71. #pin-godep 'v63'
  72. # Fill out that nice clean place with the kube godeps
  73. echo "Starting to download all kubernetes godeps. This takes a while"
  74. "${GODEP}" restore
  75. echo "Download finished"
  76. # Destroy deps in the copy of the kube tree
  77. rm -rf ./Godeps ./vendor
  78. # For some reason the kube tree needs to be a git repo for the godep tool to
  79. # run. Doesn't make sense.
  80. git init > /dev/null 2>&1
  81. # Recreate the Godeps using the nice clean set we just downloaded
  82. hack/godep-save.sh
  83. # Test for diffs
  84. if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\":' ${KUBE_ROOT}/Godeps/Godeps.json ${_kubetmp}/Godeps/Godeps.json)"; then
  85. echo "Your Godeps.json is different:"
  86. echo "${_out}"
  87. echo "Godeps Verify failed."
  88. exit 1
  89. fi
  90. if ! _out="$(diff -Naupr ${KUBE_ROOT}/vendor ${_kubetmp}/vendor)"; then
  91. echo "Your vendored results are different:"
  92. echo "${_out}"
  93. echo "Godeps Verify failed."
  94. exit 1
  95. fi
  96. echo "Godeps Verified."
  97. # ex: ts=2 sw=2 et filetype=sh