release/release.sh WIP

This commit is contained in:
Isaac Hollander McCreery 2015-10-26 17:31:41 -07:00
parent 30608dfc83
commit 7215f2c4ec

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright 2014 The Kubernetes Authors All rights reserved. # Copyright 2015 The Kubernetes Authors All rights reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -14,136 +14,127 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO What does this script do? # This script automates the release processes for all pre-releases and official
# releases for Kubernetes. See docs/devel/releasing.md for more info.
set -o errexit set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
# TODO Audit echos to make sure they're all consistent. # TODO Audit echos to make sure they're all consistent.
# TODO Refactor to remove globals?
# Sets global DRY_RUN
function main() { function main() {
if [ "$#" -gt 3 ]; then # Parse arguments
if [[ "$#" -ne 2 && "$#" -ne 3 ]]; then
usage usage
exit 1 exit 1
fi fi
local -r new_version=${1-}
declare -r NEW_VERSION=${1-}
# TODO(ihmccreery) Stop calling it githash; it's not a githash. # TODO(ihmccreery) Stop calling it githash; it's not a githash.
declare -r GITHASH=${2-} local -r githash=${2-}
DRY_RUN=true DRY_RUN=true
if [[ "${3-}" == "--no-dry-run" ]]; then if [[ "${3-}" == "--no-dry-run" ]]; then
DRY_RUN=false DRY_RUN=false
else else
echo "!!! THIS IS A DRY RUN" echo "THIS IS A DRY RUN"
fi fi
declare -r ALPHA_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.0-alpha\\.([1-9][0-9]*)$" # Get and verify version info
declare -r OFFICIAL_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$" local -r alpha_version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.0-alpha\\.([1-9][0-9]*)$"
declare -r SERIES_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$" local -r official_version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
if [[ "${NEW_VERSION}" =~ $ALPHA_VERSION_REGEX ]]; then local -r series_version_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
RELEASE_TYPE='alpha' if [[ "${new_version}" =~ $alpha_version_regex ]]; then
VERSION_MAJOR="${BASH_REMATCH[1]}" local -r release_type='alpha'
VERSION_MINOR="${BASH_REMATCH[2]}" local -r version_major="${BASH_REMATCH[1]}"
VERSION_ALPHA_REV="${BASH_REMATCH[3]}" local -r version_minor="${BASH_REMATCH[2]}"
ANCESTOR="v${VERSION_MAJOR}.${VERSION_MINOR}.0-alpha.$((VERSION_ALPHA_REV-1))" local -r version_alpha_rev="${BASH_REMATCH[3]}"
elif [[ "${NEW_VERSION}" =~ $OFFICIAL_VERSION_REGEX ]]; then elif [[ "${new_version}" =~ $official_version_regex ]]; then
RELEASE_TYPE='official' local -r release_type='official'
VERSION_MAJOR="${BASH_REMATCH[1]}" local -r version_major="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}" local -r version_minor="${BASH_REMATCH[2]}"
VERSION_PATCH="${BASH_REMATCH[3]}" local -r version_patch="${BASH_REMATCH[3]}"
ANCESTOR="${NEW_VERSION}-beta" elif [[ "${new_version}" =~ $series_version_regex ]]; then
RELEASE_BRANCH="release-${VERSION_MAJOR}.${VERSION_MINOR}" local -r release_type='series'
elif [[ "${NEW_VERSION}" =~ $SERIES_VERSION_REGEX ]]; then local -r version_major="${BASH_REMATCH[1]}"
RELEASE_TYPE='series' local -r version_minor="${BASH_REMATCH[2]}"
VERSION_MAJOR="${BASH_REMATCH[1]}"
VERSION_MINOR="${BASH_REMATCH[2]}"
# NOTE: We check the second alpha version, ...-alpha.1, because ...-alpha.0
# is the branch point for the previous release cycle, so could provide a
# false positive if we accidentally try to release off of the old release
# branch.
ANCESTOR="v${VERSION_MAJOR}.${VERSION_MINOR}.0-alpha.1"
RELEASE_BRANCH="release-${VERSION_MAJOR}.${VERSION_MINOR}"
else else
usage usage
echo echo
echo "!!! You specified an invalid version '${NEW_VERSION}'." echo "!!! You specified an invalid version '${new_version}'."
exit 1 exit 1
fi fi
# Get the git commit from the githash and verify it # Get the git commit from the githash and verify it
declare -r GIT_COMMIT_REGEX="^[0-9a-f]{7}$" local -r git_commit_regex="^[0-9a-f]{7}$"
declare -r GIT_COMMIT=$(echo "${GITHASH}" | awk -F'+' '{print $2}' | head -c7) local -r git_commit=$(echo "${githash}" | awk -F'+' '{print $2}' | head -c7)
if ! [[ "${GIT_COMMIT}" =~ $GIT_COMMIT_REGEX ]]; then if ! [[ "${git_commit}" =~ $git_commit_regex ]]; then
usage usage
echo echo
echo "!!! You specified an invalid githash '${GITHASH}'." echo "!!! You specified an invalid githash '${githash}'."
echo "!!! Tried to extract commit, got ${GIT_COMMIT}." echo "!!! Tried to extract commit, got ${git_commit}."
exit 1 exit 1
fi fi
echo "Doing ${RELEASE_TYPE} release '${NEW_VERSION}'." echo "Doing ${release_type} release '${new_version}'."
# Set the default umask for the release. This ensures consistency # Set the default umask for the release. This ensures consistency
# across our release builds. # across our release builds.
# #
# TODO(ihmccreery): This should be in our build process, not our release # TODO(ihmccreery): This should be in our build process, not our release
# process. # process.
declare -r RELEASE_UMASK=${RELEASE_UMASK:-022} local -r release_umask=${release_umask:-022}
umask "${RELEASE_UMASK}" umask "${release_umask}"
declare -r GITHUB="https://github.com/kubernetes/kubernetes.git" local -r github="https://github.com/kubernetes/kubernetes.git"
declare -r DIR="/tmp/kubernetes-${RELEASE_TYPE}-release-${NEW_VERSION}-$(date +%s)" local -r dir="/tmp/kubernetes-${release_type}-release-${new_version}-$(date +%s)"
echo "Cloning from '${GITHUB}'..." echo "Cloning from '${github}'..."
git clone "${GITHUB}" "${DIR}" git clone "${github}" "${dir}"
# !!! REMINDER !!! # !!! REMINDER !!!
# #
# Past this point, you are dealing with a different clone of the repo at some # Past this point, you are dealing with a different clone of the repo at some
# version. Don't assume you're executing code from the same repo as this script # version. Don't assume you're executing code from the same repo as this script
# is running in. This is a version agnostic process. # is running in. This is a version agnostic process.
pushd "${DIR}" pushd "${dir}"
if [[ "${RELEASE_TYPE}" == 'alpha' ]]; then if [[ "${release_type}" == 'alpha' ]]; then
git checkout "${GIT_COMMIT}" git checkout "${git_commit}"
verify-at-git-commit verify-at-git-commit "${git_commit}"
verify-ancestor verify-ancestor "v${version_major}.${version_minor}.0-alpha.$((${version_alpha_rev}-1))"
alpha-release "${NEW_VERSION}" alpha-release "${new_version}"
elif [[ "${RELEASE_TYPE}" == 'official' ]]; then elif [[ "${release_type}" == 'official' ]]; then
declare -r RELEASE_BRANCH="release-${VERSION_MAJOR}.${VERSION_MINOR}" local -r release_branch="release-${version_major}.${version_minor}"
declare -r BETA_VERSION="v${VERSION_MAJOR}.${VERSION_MINOR}.$((${VERSION_PATCH}+1))-beta" local -r beta_version="v${version_major}.${version_minor}.$((${version_patch}+1))-beta"
git checkout "${RELEASE_BRANCH}" git checkout "${release_branch}"
verify-at-git-commit verify-at-git-commit "${git_commit}"
# TODO uncomment this once we've pushed v1.1.1-beta verify-ancestor "${new_version}-beta"
#verify-ancestor
official-release "${NEW_VERSION}" official-release "${new_version}"
beta-release "${BETA_VERSION}" beta-release "${beta_version}"
else # [[ "${RELEASE_TYPE}" == 'series' ]] else # [[ "${release_type}" == 'series' ]]
declare -r RELEASE_BRANCH="release-${VERSION_MAJOR}.${VERSION_MINOR}" local -r release_branch="release-${version_major}.${version_minor}"
declare -r ALPHA_VERSION="v${VERSION_MAJOR}.$((${VERSION_MINOR}+1)).0-alpha.0" local -r alpha_version="v${version_major}.$((${version_minor}+1)).0-alpha.0"
declare -r BETA_VERSION="v${VERSION_MAJOR}.${VERSION_MINOR}.0-beta" local -r beta_version="v${version_major}.${version_minor}.0-beta"
git checkout "${GIT_COMMIT}" git checkout "${git_commit}"
verify-at-git-commit verify-at-git-commit "${git_commit}"
verify-ancestor # NOTE: We check the second alpha version, ...-alpha.1, because ...-alpha.0
# is the branch point for the previous release cycle, so could provide a
# false positive if we accidentally try to release off of the old release
# branch.
verify-ancestor "v${version_major}.${version_minor}.0-alpha.1"
# TODO (Fix versioning.md if you don't do this.) We maybe could actually do alpha-release "${alpha_version}"
# the alpha rev (in a series release) at HEAD, and patch the version/base.go
# logic then. We'd then have some part of the tree between the branch of
# vX.Y series and the vX.(Y+1).0-alpha.0 tag, but I don't think that's a
# problem.
alpha-release "${ALPHA_VERSION}"
echo "Branching ${RELEASE_BRANCH}." echo "Branching ${release_branch}."
git checkout -b "${RELEASE_BRANCH}" git checkout -b "${release_branch}"
beta-release "${BETA_VERSION}" beta-release "${beta_version}"
fi fi
cleanup cleanup "${dir}"
} }
function usage() { function usage() {
@ -157,7 +148,7 @@ function alpha-release() {
echo "Doing an alpha release of ${alpha_version}." echo "Doing an alpha release of ${alpha_version}."
echo "Tagging ${alpha_version} at $(git rev-parse --short HEAD)." echo "Tagging ${alpha_version} at $(current-git-commit)."
git tag -a -m "Kubernetes pre-release ${alpha_version}" "${alpha_version}" git tag -a -m "Kubernetes pre-release ${alpha_version}" "${alpha_version}"
git-push "${alpha_version}" git-push "${alpha_version}"
build build
@ -170,13 +161,10 @@ function beta-release() {
echo "Doing a beta release of ${beta_version}." echo "Doing a beta release of ${beta_version}."
# TODO We need to rev something so that we have a separate commit on the versionize-docs-and-commit "${beta_version}"
# release-X.Y branch, since we don't want master to pick up with beta tag.
# TODO rev-docs and/or version?
versionize-docs-and-commit
rev-version-and-commit rev-version-and-commit
echo "Tagging ${beta_version} at $(git rev-parse --short HEAD)." echo "Tagging ${beta_version} at $(current-git-commit)."
git tag -a -m "Kubernetes pre-release ${beta_version}" "${beta_version}" git tag -a -m "Kubernetes pre-release ${beta_version}" "${beta_version}"
git-push "${beta_version}" git-push "${beta_version}"
build build
@ -189,11 +177,10 @@ function official-release() {
echo "Doing an official release of ${official_version}." echo "Doing an official release of ${official_version}."
# TODO rev-docs and/or version? versionize-docs-and-commit "${official_version}"
versionize-docs-and-commit
rev-version-and-commit rev-version-and-commit
echo "Tagging ${official_version} at $(git rev-parse --short HEAD)." echo "Tagging ${official_version} at $(current-git-commit)."
git tag -a -m "Kubernetes release ${official_version}" "${official_version}" git tag -a -m "Kubernetes release ${official_version}" "${official_version}"
git-push "${official_version}" git-push "${official_version}"
build build
@ -202,20 +189,26 @@ function official-release() {
} }
function verify-at-git-commit() { function verify-at-git-commit() {
echo "Verifying we are at ${GIT_COMMIT}." local -r git_commit="${1}"
if [[ $(git rev-parse --short HEAD) != ${GIT_COMMIT} ]]; then echo "Verifying we are at ${git_commit}."
echo "!!! We are not at commit ${GIT_COMMIT}!" if [[ $(current-git-commit) != ${git_commit} ]]; then
cleanup echo "!!! We are not at commit ${git_commit}!"
cleanup "${dir}"
exit 1 exit 1
fi fi
} }
function current-git-commit() {
git rev-parse --short HEAD
}
function verify-ancestor() { function verify-ancestor() {
local -r ancestor="${1}"
# Check to make sure the/a previous version is an ancestor. # Check to make sure the/a previous version is an ancestor.
echo "Checking that previous version '${ANCESTOR}' is an ancestor." echo "Checking that previous version '${ancestor}' is an ancestor."
if ! git merge-base --is-ancestor "${ANCESTOR}" HEAD; then if ! git merge-base --is-ancestor "${ancestor}" HEAD; then
echo "!!! Previous version '${ANCESTOR}' is not an ancestor!" echo "!!! Previous version '${ancestor}' is not an ancestor!"
cleanup cleanup "${dir}"
exit 1 exit 1
fi fi
} }
@ -230,12 +223,12 @@ function git-push() {
fi fi
} }
# TODO(ihmccreery): Review and fix this function.
function versionize-docs-and-commit() { function versionize-docs-and-commit() {
echo "FAKE versionize-docs-and-commit" local -r version="${1}"
# # NOTE: This is using versionize-docs.sh at the release point. echo "Versionizing docs and committing."
# ./build/versionize-docs.sh ${NEW_VERSION} # NOTE: This is using versionize-docs.sh at the release point.
# git commit -am "Versioning docs and examples for ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" ./build/versionize-docs.sh ${version}
git commit -am "Versioning docs and examples for ${version}."
} }
# TODO(ihmccreery): Review and fix this function. # TODO(ihmccreery): Review and fix this function.
@ -253,9 +246,9 @@ function rev-version-and-commit() {
# VERSION_FILE="./pkg/version/base.go" # VERSION_FILE="./pkg/version/base.go"
# GIT_MINOR="${VERSION_MINOR}.${VERSION_PATCH}" # GIT_MINOR="${version_minor}.${VERSION_PATCH}"
# echo "+++ Updating to ${NEW_VERSION}" # echo "+++ Updating to ${NEW_VERSION}"
# $SED -ri -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${VERSION_MAJOR}\"/" "${VERSION_FILE}" # $SED -ri -e "s/gitMajor\s+string = \"[^\"]*\"/gitMajor string = \"${version_major}\"/" "${VERSION_FILE}"
# $SED -ri -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\"/" "${VERSION_FILE}" # $SED -ri -e "s/gitMinor\s+string = \"[^\"]*\"/gitMinor string = \"${GIT_MINOR}\"/" "${VERSION_FILE}"
# $SED -ri -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION-${release_branch}+\$Format:%h\$\"/" "${VERSION_FILE}" # $SED -ri -e "s/gitVersion\s+string = \"[^\"]*\"/gitVersion string = \"$NEW_VERSION-${release_branch}+\$Format:%h\$\"/" "${VERSION_FILE}"
# gofmt -s -w "${VERSION_FILE}" # gofmt -s -w "${VERSION_FILE}"
@ -272,9 +265,10 @@ function build() {
} }
function cleanup() { function cleanup() {
local -r dir="${1}"
if ${DRY_RUN}; then if ${DRY_RUN}; then
echo "Dry run:" echo "Dry run:"
echo " pushd ${DIR}" echo " pushd ${dir}"
echo "to have a look around." echo "to have a look around."
else else
popd popd