From 3458246c103f105b878d387213ebf4a6f312a2d0 Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Tue, 17 Mar 2015 12:31:43 -0700 Subject: [PATCH] Publish a gs://kubernetes-release/release/latest.txt when we publish a build Adds a kube::release::gcs::publish_latest_official that checks the current contents of this file in GCS, verifies that we're pushing a newer build, and updates it if so. (i.e. it handles the case of pushing a 0.13.1 and then later pushing a 0.12.3.) This follows the pattern of the ci/ build, which Jenkins just updates unconditionally. I already updated the file for 0.13.1. After this we can update the get-k8s script, so we don't have to keep updating it. --- build/common.sh | 50 ++++++++++++++++++++++++++++++++++ build/push-official-release.sh | 6 ++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/build/common.sh b/build/common.sh index 9b2d5678d7..91b1a49c4c 100644 --- a/build/common.sh +++ b/build/common.sh @@ -833,3 +833,53 @@ function kube::release::gcs::publish_latest() { echo "+++ gsutil cat ${latest_file_dst}:" gsutil cat ${latest_file_dst} } + +# Publish a new latest.txt, but only if the release we're dealing with +# is newer than the contents in GCS. +function kube::release::gcs::publish_latest_official() { + local -r new_version=${KUBE_GCS_LATEST_CONTENTS} + local -r latest_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${KUBE_GCS_LATEST_FILE}" + + local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$" + [[ ${new_version} =~ ${version_regex} ]] || { + echo "!!! publish_latest_official passed bogus value: '${new_version}'" >&2 + return 1 + } + + local -r version_major="${BASH_REMATCH[1]}" + local -r version_minor="${BASH_REMATCH[2]}" + local -r version_patch="${BASH_REMATCH[3]}" + + local gcs_version + gcs_version=$(gsutil cat "${latest_file_dst}") + + [[ ${gcs_version} =~ ${version_regex} ]] || { + echo "!!! ${latest_file_dst} contains invalid release version, can't compare: '${gcs_version}'" >&2 + return 1 + } + + local -r gcs_version_major="${BASH_REMATCH[1]}" + local -r gcs_version_minor="${BASH_REMATCH[2]}" + local -r gcs_version_patch="${BASH_REMATCH[3]}" + + local greater=true + if [[ "${gcs_version_major}" -gt "${version_major}" ]]; then + greater=false + elif [[ "${gcs_version_major}" -lt "${version_major}" ]]; then + : # fall out + elif [[ "${gcs_version_minor}" -gt "${version_minor}" ]]; then + greater=false + elif [[ "${gcs_version_minor}" -lt "${version_minor}" ]]; then + : # fall out + elif [[ "${gcs_version_patch}" -ge "${version_patch}" ]]; then + greater=false + fi + + if [[ "${greater}" != "true" ]]; then + echo "+++ ${gcs_version} (latest on GCS) >= ${new_version} (just uploaded), not updating ${latest_file_dst}" + return 0 + fi + + echo "+++ ${new_version} (just uploaded) > ${gcs_version} (latest on GCS), updating ${latest_file_dst}" + kube::release::gcs::publish_latest +} diff --git a/build/push-official-release.sh b/build/push-official-release.sh index 1f7474fef0..5eb5a7222f 100755 --- a/build/push-official-release.sh +++ b/build/push-official-release.sh @@ -22,7 +22,7 @@ set -o pipefail KUBE_RELEASE_VERSION=${1-} -VERSION_REGEX="v[0-9]+.[0-9]+(.[0-9]+)?" +VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$" [[ ${KUBE_RELEASE_VERSION} =~ $VERSION_REGEX ]] || { echo "!!! You must specify the version you are releasing in the form of '$VERSION_REGEX'" >&2 exit 1 @@ -34,9 +34,11 @@ KUBE_GCS_UPLOAD_RELEASE=y KUBE_GCS_RELEASE_BUCKET=kubernetes-release KUBE_GCS_PROJECT=google-containers KUBE_GCS_RELEASE_PREFIX=release/${KUBE_RELEASE_VERSION} +KUBE_GCS_LATEST_FILE="release/latest.txt" +KUBE_GCS_LATEST_CONTENTS=${KUBE_RELEASE_VERSION} KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "$KUBE_ROOT/build/common.sh" - kube::release::gcs::release +kube::release::gcs::publish_latest_official