From 7732c8d8925aeb58b1bdaf829be7439c335e5101 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 31 Aug 2017 21:39:18 -0700 Subject: [PATCH] Centralize godep version number --- hack/godep-restore.sh | 2 +- hack/godep-save.sh | 2 +- hack/lib/util.sh | 22 +++++++++++++++------- hack/update-all.sh | 2 +- hack/update-staging-godeps-dockerized.sh | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/hack/godep-restore.sh b/hack/godep-restore.sh index ae9caf07442..ae90ce2b6f3 100755 --- a/hack/godep-restore.sh +++ b/hack/godep-restore.sh @@ -22,7 +22,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/util.sh" -kube::util::ensure_godep_version v79 +kube::util::ensure_godep_version kube::log::status "Starting to download all kubernetes godeps. This takes a while" GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep restore "$@" diff --git a/hack/godep-save.sh b/hack/godep-save.sh index 0d4d2253402..98c48ec57f0 100755 --- a/hack/godep-save.sh +++ b/hack/godep-save.sh @@ -23,7 +23,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/util.sh" kube::util::ensure_single_dir_gopath -kube::util::ensure_godep_version v79 +kube::util::ensure_godep_version kube::util::ensure_no_staging_repos_in_gopath if [ -e "${KUBE_ROOT}/vendor" -o -e "${KUBE_ROOT}/Godeps" ]; then diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 8e96ad462b1..cc4c4f5d5cc 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -512,25 +512,33 @@ kube::util::ensure_clean_working_dir() { done 1>&2 } -# Ensure that the given godep version is installed and in the path +# Ensure that the given godep version is installed and in the path. Almost +# nobody should use any version but the default. kube::util::ensure_godep_version() { - GODEP_VERSION=${1:-"v79"} + GODEP_VERSION=${1:-"v79"} # this version is known to work + if [[ "$(godep version 2>/dev/null)" == *"godep ${GODEP_VERSION}"* ]]; then return fi + kube::log::status "Getting godep version ${GODEP_VERSION}" kube::util::ensure-temp-dir mkdir -p "${KUBE_TEMP}/go/src" - GOPATH="${KUBE_TEMP}/go" go get -d -u github.com/tools/godep - pushd "${KUBE_TEMP}/go/src/github.com/tools/godep" >/dev/null + GP="$(echo $GOPATH | cut -f1 -d:)" + rm -rf "${GP}/src/github.com/tools/godep" + go get -d -u github.com/tools/godep + pushd "${GP}/src/github.com/tools/godep" >/dev/null git checkout -q "${GODEP_VERSION}" - GOPATH="${KUBE_TEMP}/go" go install . + go install . popd >/dev/null - PATH="${KUBE_TEMP}/go/bin:${PATH}" hash -r # force bash to clear PATH cache - godep version + PATH="${PATH}:${GP}/bin" + if [[ "$(godep version 2>/dev/null)" != *"godep ${GODEP_VERSION}"* ]]; then + kube::log::error "Expected godep ${GODEP_VERSION}, got $(godep version)" + return 1 + fi } # Ensure that none of the staging repos is checked out in the GOPATH because this diff --git a/hack/update-all.sh b/hack/update-all.sh index e08d059d150..1b674497676 100755 --- a/hack/update-all.sh +++ b/hack/update-all.sh @@ -53,7 +53,7 @@ if ! $ALL ; then echo "Running in short-circuit mode; run with -a to force all scripts to run." fi -kube::util::ensure_godep_version v79 +kube::util::ensure_godep_version if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then echo "Running godep restore" diff --git a/hack/update-staging-godeps-dockerized.sh b/hack/update-staging-godeps-dockerized.sh index 6733914e14e..e33f9dfbbba 100755 --- a/hack/update-staging-godeps-dockerized.sh +++ b/hack/update-staging-godeps-dockerized.sh @@ -57,7 +57,7 @@ kube::golang::setup_env kube::util::ensure_single_dir_gopath kube::util::ensure_no_staging_repos_in_gopath # Confirm we have the right godep version installed -kube::util::ensure_godep_version v79 +kube::util::ensure_godep_version # Create a fake git repo the root of the repo to prevent godeps from complaining kube::util::create-fake-git-tree "${KUBE_ROOT}"