godep-save.sh: add sanity checks

pull/6/head
Dr. Stefan Schimanski 2017-07-07 18:39:11 +02:00
parent a9bf44101b
commit 918721078f
2 changed files with 31 additions and 24 deletions

View File

@ -22,8 +22,14 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
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
if [ -e "${KUBE_ROOT}/vendor" -o -e "${KUBE_ROOT}/Godeps" ]; then
echo "The directory vendor/ or Godeps/ exists. Remove them before running godep-save.sh" 1>&2
exit 1
fi
# Some things we want in godeps aren't code dependencies, so ./...
# won't pick them up.
REQUIRED_BINS=(
@ -34,34 +40,27 @@ REQUIRED_BINS=(
)
pushd "${KUBE_ROOT}" > /dev/null
# sanity check that staging directories do not exist in GOPATH
error=0
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
if [ -e "${GOPATH}/src/k8s.io/${repo}" ]; then
echo "k8s.io/${repo} exists in GOPATH. Remove before running godep-save.sh." 1>&2
error=1
fi
done
if [ "${error}" = "1" ]; then
exit 1
fi
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep save "${REQUIRED_BINS[@]}"
# create a symlink in vendor directory pointing to the staging client. This
# let other packages use the staging client as if it were vendored.
if [ ! -e "vendor/k8s.io/api" ]; then
ln -s ../../staging/src/k8s.io/api vendor/k8s.io/api
fi
if [ ! -e "vendor/k8s.io/client-go" ]; then
ln -s ../../staging/src/k8s.io/client-go vendor/k8s.io/client-go
fi
if [ ! -e "vendor/k8s.io/apiserver" ]; then
ln -s ../../staging/src/k8s.io/apiserver vendor/k8s.io/apiserver
fi
if [ ! -e "vendor/k8s.io/apimachinery" ]; then
ln -s ../../staging/src/k8s.io/apimachinery vendor/k8s.io/apimachinery
fi
if [ ! -e "vendor/k8s.io/kube-aggregator" ]; then
ln -s ../../staging/src/k8s.io/kube-aggregator vendor/k8s.io/kube-aggregator
fi
if [ ! -e "vendor/k8s.io/apiextensions-apiserver" ]; then
ln -s ../../staging/src/k8s.io/apiextensions-apiserver vendor/k8s.io/apiextensions-apiserver
fi
if [ ! -e "vendor/k8s.io/sample-apiserver" ]; then
ln -s ../../staging/src/k8s.io/sample-apiserver vendor/k8s.io/sample-apiserver
fi
if [ ! -e "vendor/k8s.io/metrics" ]; then
ln -s ../../staging/src/k8s.io/metrics vendor/k8s.io/metrics
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
if [ ! -e "vendor/k8s.io/${repo}" ]; then
ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}"
fi
done
popd > /dev/null
echo "Don't forget to run hack/update-godep-licenses.sh if you added or removed a dependency!"

View File

@ -513,6 +513,14 @@ kube::util::ensure_godep_version() {
godep version
}
# Checks that the GOPATH is simple, i.e. consists only of one directory, not multiple.
kube::util::ensure_single_dir_gopath() {
if [[ "${GOPATH}" == *:* ]]; then
echo "GOPATH must consist of a single directory." 1>&2
exit 1
fi
}
# Checks whether there are any files matching pattern $2 changed between the
# current branch and upstream branch named by $1.
# Returns 1 (false) if there are no changes, 0 (true) if there are changes