From 812e52019cc03f9d2b75a9cd319173c57cbdecd9 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 31 Jan 2017 09:47:01 +0100 Subject: [PATCH] client-go: add staging/copy.sh testing --- hack/verify-staging-client-go.sh | 57 ++++++++++++++++++++++++++++++-- staging/copy.sh | 27 +++++++++------ 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/hack/verify-staging-client-go.sh b/hack/verify-staging-client-go.sh index 3e428ac811de7..f4915e730b303 100755 --- a/hack/verify-staging-client-go.sh +++ b/hack/verify-staging-client-go.sh @@ -18,8 +18,59 @@ set -o errexit set -o nounset set -o pipefail -go build ./staging/src/k8s.io/client-go/examples/... +V="" +while getopts ":v" opt; do + case $opt in + v) # increase verbosity + V="-v" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + ;; + esac +done +readonly V KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. -# TODO: reenable copy.sh when test can cope with circular dependencies -# "${KUBE_ROOT}"/staging/copy.sh -v +cd ${KUBE_ROOT} + +# Smoke test client-go examples +go install ./staging/src/k8s.io/client-go/examples/... + +# Create a temporary GOPATH for apimachinery and client-go, copy the current HEAD into each and turn them +# into a git repo. Then we can run copy.sh with this additional GOPATH. The Godeps.json will +# have invalid git SHA1s, but it's good enough as a smoke test of copy.sh. +if [ "${USE_TEMP_DIR:-1}" = 1 ]; then + TEMP_STAGING_GOPATH=$(mktemp -d -t verify-staging-client-go.XXXXX) + echo "Creating the temporary staging GOPATH directory: ${TEMP_STAGING_GOPATH}" + cleanup() { + if [ "${KEEP_TEMP_DIR:-0}" != 1 ]; then + rm -rf "${TEMP_STAGING_GOPATH}" + fi + } + trap cleanup EXIT SIGINT + mkdir -p "${TEMP_STAGING_GOPATH}/src/k8s.io" + ln -s "${PWD}" "${TEMP_STAGING_GOPATH}/src/k8s.io" +else + TEMP_STAGING_GOPATH="${GOPATH}" +fi +for PACKAGE in apimachinery client-go; do + PACKAGE_PATH="${TEMP_STAGING_GOPATH}/src/k8s.io/${PACKAGE}" + echo "Creating a temporary ${PACKAGE} repo with a snapshot of HEAD" + mkdir -p "${PACKAGE_PATH}" + rsync -ax --delete staging/src/k8s.io/${PACKAGE}/ "${PACKAGE_PATH}/" + pushd "${PACKAGE_PATH}" >/dev/null + git init >/dev/null + git add * + git -c user.email="nobody@k8s.io" -c user.name="verify-staging-client-go.sh" commit -q -m "Snapshot" + popd >/dev/null +done + +echo "Running godep restore" +pushd "${TEMP_STAGING_GOPATH}/src/k8s.io/kubernetes" >/dev/null +export GOPATH="${TEMP_STAGING_GOPATH}" +godep restore ${V} 2>&1 | sed 's/^/ /' + +echo "Testing staging/copy.sh" +staging/copy.sh -d 2>&1 | sed 's/^/ /' +popd diff --git a/staging/copy.sh b/staging/copy.sh index 7a6e4e0a4bd27..76337b90052cb 100755 --- a/staging/copy.sh +++ b/staging/copy.sh @@ -18,18 +18,22 @@ set -o errexit set -o nounset set -o pipefail -VERIFYONLY=false -while getopts ":v" opt; do +FAIL_ON_CHANGES=false +DRY_RUN=false +while getopts ":fd" opt; do case $opt in - v) - VERIFYONLY=true + f) + FAIL_ON_CHANGES=true + ;; + d) + DRY_RUN=true ;; \?) echo "Invalid option: -$OPTARG" >&2 ;; esac done -readonly VERIFYONLY +readonly FAIL_ON_CHANGES DRY_RUN echo "**PLEASE** run \"godep restore\" before running this script" # PREREQUISITES: run `godep restore` in the main repo before calling this script. @@ -183,8 +187,8 @@ find "${CLIENT_REPO_TEMP}" -type f \( \ echo "remove cyclical godep" rm -rf "${CLIENT_REPO_TEMP}/_vendor/k8s.io/client-go" -if [ "${VERIFYONLY}" = true ]; then - echo "running verify-only" +if [ "${FAIL_ON_CHANGES}" = true ]; then + echo "running FAIL_ON_CHANGES" ret=0 if diff -NauprB -I "GoVersion.*\|GodepVersion.*" "${CLIENT_REPO}" "${CLIENT_REPO_TEMP}"; then echo "${CLIENT_REPO} up to date." @@ -197,8 +201,11 @@ if [ "${VERIFYONLY}" = true ]; then fi fi -echo "move to the client repo" # clean the ${CLIENT_REPO} -ls "${CLIENT_REPO}" | { grep -v '_tmp' || true; } | xargs rm -rf -mv "${CLIENT_REPO_TEMP}"/* "${CLIENT_REPO}" +echo "move to the client repo" +if [ "${DRY_RUN}" = false ]; then + ls "${CLIENT_REPO}" | { grep -v '_tmp' || true; } | xargs rm -rf + mv "${CLIENT_REPO_TEMP}"/* "${CLIENT_REPO}" +fi + cleanup