Skip to content

Commit

Permalink
Merge pull request kubernetes#16919 from ihmccreery/enable-prerelease…
Browse files Browse the repository at this point in the history
…-push-official-release

Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Nov 20, 2015
2 parents 0e229d5 + 2fad9a1 commit c8d2ec6
Showing 1 changed file with 86 additions and 45 deletions.
131 changes: 86 additions & 45 deletions build/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,26 @@ function kube::build::destroy_container() {
# version
# Returns:
# If version is a valid release version
# Sets:
# BASH_REMATCH, so you can do something like:
# local -r version_major="${BASH_REMATCH[1]}"
# local -r version_minor="${BASH_REMATCH[2]}"
# local -r version_patch="${BASH_REMATCH[3]}"
# Sets: (e.g. for '1.2.3-alpha.4')
# VERSION_MAJOR (e.g. '1')
# VERSION_MINOR (e.g. '2')
# VERSION_PATCH (e.g. '3')
# VERSION_EXTRA (e.g. '-alpha.4')
# VERSION_PRERELEASE (e.g. 'alpha')
# VERSION_PRERELEASE_REV (e.g. '4')
function kube::release::parse_and_validate_release_version() {
local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-(beta|alpha)\\.(0|[1-9][0-9]*))?$"
local -r version="${1-}"
[[ "${version}" =~ ${version_regex} ]] || {
kube::log::error "Invalid release version: '${version}'"
kube::log::error "Invalid release version: '${version}', must match regex ${version_regex}"
return 1
}
VERSION_MAJOR="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}"
VERSION_PATCH="${BASH_REMATCH[3]}"
VERSION_EXTRA="${BASH_REMATCH[4]}"
VERSION_PRERELEASE="${BASH_REMATCH[5]}"
VERSION_PRERELEASE_REV="${BASH_REMATCH[6]}"
}

# Validate a ci version
Expand All @@ -370,23 +378,29 @@ function kube::release::parse_and_validate_release_version() {
# version
# Returns:
# If version is a valid ci version
# Sets:
# BASH_REMATCH, so you can do something like:
# local -r version_major="${BASH_REMATCH[1]}"
# local -r version_minor="${BASH_REMATCH[2]}"
# local -r version_patch="${BASH_REMATCH[3]}"
# local -r version_prerelease="${BASH_REMATCH[4]}"
# local -r version_prerelease_rev="${BASH_REMATCH[5]}"
# local -r version_build_info="${BASH_REMATCH[6]}"
# local -r version_commits="${BASH_REMATCH[7]}"
# Sets: (e.g. for '1.2.3-alpha.4.56+abcd789-dirty')
# VERSION_MAJOR (e.g. '1')
# VERSION_MINOR (e.g. '2')
# VERSION_PATCH (e.g. '3')
# VERSION_PRERELEASE (e.g. 'alpha')
# VERSION_PRERELEASE_REV (e.g. '4')
# VERSION_BUILD_INFO (e.g. '.56+abcd789-dirty')
# VERSION_COMMITS (e.g. '56')
function kube::release::parse_and_validate_ci_version() {
# Accept things like "v1.2.3-alpha.0.456+abcd789-dirty" or "v1.2.3-beta.0.456"
# Accept things like "v1.2.3-alpha.4.56+abcd789-dirty" or "v1.2.3-beta.4.56"
local -r version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-(beta|alpha)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)\\+[-0-9a-z]*)?$"
local -r version="${1-}"
[[ "${version}" =~ ${version_regex} ]] || {
kube::log::error "Invalid ci version: '${version}'"
kube::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
return 1
}
VERSION_MAJOR="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}"
VERSION_PATCH="${BASH_REMATCH[3]}"
VERSION_PRERELEASE="${BASH_REMATCH[4]}"
VERSION_PRERELEASE_REV="${BASH_REMATCH[5]}"
VERSION_BUILD_INFO="${BASH_REMATCH[6]}"
VERSION_COMMITS="${BASH_REMATCH[7]}"
}

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1093,8 +1107,8 @@ function kube::release::gcs::publish_ci() {
kube::release::gcs::verify_release_files || return 1

kube::release::parse_and_validate_ci_version "${KUBE_GCS_PUBLISH_VERSION}" || return 1
local -r version_major="${BASH_REMATCH[1]}"
local -r version_minor="${BASH_REMATCH[2]}"
local -r version_major="${VERSION_MAJOR}"
local -r version_minor="${VERSION_MINOR}"

local -r publish_files=(ci/latest.txt ci/latest-${version_major}.txt ci/latest-${version_major}.${version_minor}.txt)

Expand Down Expand Up @@ -1123,8 +1137,8 @@ function kube::release::gcs::publish_official() {
kube::release::gcs::verify_release_files || return 1

kube::release::parse_and_validate_release_version "${KUBE_GCS_PUBLISH_VERSION}" || return 1
local -r version_major="${BASH_REMATCH[1]}"
local -r version_minor="${BASH_REMATCH[2]}"
local -r version_major="${VERSION_MAJOR}"
local -r version_minor="${VERSION_MINOR}"

local publish_files
if [[ "${release_kind}" == 'latest' ]]; then
Expand Down Expand Up @@ -1171,16 +1185,22 @@ function kube::release::gcs::verify_release_files() {
# publish_file: the GCS location to look in
# Returns:
# If new version is greater than the GCS version
#
# TODO(16529): This should all be outside of build an in release, and should be
# refactored to reduce code duplication. Also consider using strictly nested
# if and explicit handling of equals case.
function kube::release::gcs::verify_release_gt() {
local -r publish_file="${1-}"
local -r new_version=${KUBE_GCS_PUBLISH_VERSION}
local -r publish_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"

kube::release::parse_and_validate_release_version "${new_version}" || return 1

local -r version_major="${BASH_REMATCH[1]}"
local -r version_minor="${BASH_REMATCH[2]}"
local -r version_patch="${BASH_REMATCH[3]}"
local -r version_major="${VERSION_MAJOR}"
local -r version_minor="${VERSION_MINOR}"
local -r version_patch="${VERSION_PATCH}"
local -r version_prerelease="${VERSION_PRERELEASE}"
local -r version_prerelease_rev="${VERSION_PRERELEASE_REV}"

local gcs_version
if gcs_version="$(gsutil cat "${publish_file_dst}")"; then
Expand All @@ -1189,9 +1209,11 @@ function kube::release::gcs::verify_release_gt() {
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 -r gcs_version_major="${VERSION_MAJOR}"
local -r gcs_version_minor="${VERSION_MINOR}"
local -r gcs_version_patch="${VERSION_PATCH}"
local -r gcs_version_prerelease="${VERSION_PRERELEASE}"
local -r gcs_version_prerelease_rev="${VERSION_PRERELEASE_REV}"

local greater=true
if [[ "${version_major}" -lt "${gcs_version_major}" ]]; then
Expand All @@ -1202,7 +1224,26 @@ function kube::release::gcs::verify_release_gt() {
greater=false
elif [[ "${version_minor}" -gt "${gcs_version_minor}" ]]; then
: # fall out
elif [[ "${version_patch}" -le "${gcs_version_patch}" ]]; then
elif [[ "${version_patch}" -lt "${gcs_version_patch}" ]]; then
greater=false
elif [[ "${version_patch}" -gt "${gcs_version_patch}" ]]; then
: # fall out
# Use lexicographic (instead of integer) comparison because
# version_prerelease is a string, ("alpha" or "beta",) but first check if
# either is an official release (i.e. empty prerelease string).
#
# We have to do this because lexicographically "beta" > "alpha" > "", but
# we want official > beta > alpha.
elif [[ -n "${version_prerelease}" && -z "${gcs_version_prerelease}" ]]; then
greater=false
elif [[ -z "${version_prerelease}" && -n "${gcs_version_prerelease}" ]]; then
: # fall out
elif [[ "${version_prerelease}" < "${gcs_version_prerelease}" ]]; then
greater=false
elif [[ "${version_prerelease}" > "${gcs_version_prerelease}" ]]; then
: # fall out
# Finally resort to -le here, since we want strictly-greater-than.
elif [[ "${version_prerelease_rev}" -le "${gcs_version_prerelease_rev}" ]]; then
greater=false
fi

Expand All @@ -1228,19 +1269,23 @@ function kube::release::gcs::verify_release_gt() {
# publish_file: the GCS location to look in
# Returns:
# If new version is greater than the GCS version
#
# TODO(16529): This should all be outside of build an in release, and should be
# refactored to reduce code duplication. Also consider using strictly nested
# if and explicit handling of equals case.
function kube::release::gcs::verify_ci_ge() {
local -r publish_file="${1-}"
local -r new_version=${KUBE_GCS_PUBLISH_VERSION}
local -r publish_file_dst="gs://${KUBE_GCS_RELEASE_BUCKET}/${publish_file}"

kube::release::parse_and_validate_ci_version "${new_version}" || return 1

local -r version_major="${BASH_REMATCH[1]}"
local -r version_minor="${BASH_REMATCH[2]}"
local -r version_patch="${BASH_REMATCH[3]}"
local -r version_prerelease="${BASH_REMATCH[4]}"
local -r version_prerelease_rev="${BASH_REMATCH[5]}"
local -r version_commits="${BASH_REMATCH[7]}"
local -r version_major="${VERSION_MAJOR}"
local -r version_minor="${VERSION_MINOR}"
local -r version_patch="${VERSION_PATCH}"
local -r version_prerelease="${VERSION_PRERELEASE}"
local -r version_prerelease_rev="${VERSION_PRERELEASE_REV}"
local -r version_commits="${VERSION_COMMITS}"

local gcs_version
if gcs_version="$(gsutil cat "${publish_file_dst}")"; then
Expand All @@ -1249,12 +1294,12 @@ function kube::release::gcs::verify_ci_ge() {
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 -r gcs_version_prerelease="${BASH_REMATCH[4]}"
local -r gcs_version_prerelease_rev="${BASH_REMATCH[5]}"
local -r gcs_version_commits="${BASH_REMATCH[7]}"
local -r gcs_version_major="${VERSION_MAJOR}"
local -r gcs_version_minor="${VERSION_MINOR}"
local -r gcs_version_patch="${VERSION_PATCH}"
local -r gcs_version_prerelease="${VERSION_PRERELEASE}"
local -r gcs_version_prerelease_rev="${VERSION_PRERELEASE_REV}"
local -r gcs_version_commits="${VERSION_COMMITS}"

local greater=true
if [[ "${version_major}" -lt "${gcs_version_major}" ]]; then
Expand All @@ -1279,10 +1324,6 @@ function kube::release::gcs::verify_ci_ge() {
greater=false
elif [[ "${version_prerelease_rev}" -gt "${gcs_version_prerelease_rev}" ]]; then
: # fall out
elif [[ "${version_patch}" -lt "${gcs_version_patch}" ]]; then
greater=false
elif [[ "${version_patch}" -gt "${gcs_version_patch}" ]]; then
: # fall out
# If either version_commits is empty, it will be considered less-than, as
# expected, (e.g. 1.2.3-beta < 1.2.3-beta.1).
elif [[ "${version_commits}" -lt "${gcs_version_commits}" ]]; then
Expand Down

0 comments on commit c8d2ec6

Please sign in to comment.