Skip to content

Commit

Permalink
client-go: add staging/copy.sh testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Feb 2, 2017
1 parent 880cbd5 commit 812e520
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 13 deletions.
57 changes: 54 additions & 3 deletions hack/verify-staging-client-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" -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
27 changes: 17 additions & 10 deletions staging/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."
Expand All @@ -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

0 comments on commit 812e520

Please sign in to comment.