-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable prerelease push official release #16919
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,18 +346,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 | ||
|
@@ -368,23 +376,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]}" | ||
} | ||
|
||
# --------------------------------------------------------------------------- | ||
|
@@ -1070,8 +1084,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) | ||
|
||
|
@@ -1100,8 +1114,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 | ||
|
@@ -1148,16 +1162,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 | ||
|
@@ -1166,9 +1186,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 | ||
|
@@ -1179,7 +1201,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 | ||
|
||
|
@@ -1205,19 +1246,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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines got accidentally copy-pasted in; they're identical to comparisons above, so should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's exactly this kind of copy-n-paste error that my comment above is aimed at :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. I expected that to be hideous, but I like the way it reads much more. Done. |
||
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 | ||
|
@@ -1226,12 +1271,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 | ||
|
@@ -1256,10 +1301,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would much prefer a strictly nested if, with explicit handling of equals, e.g. something along the lines of (in pseudo-code):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. Added that to TODO.