From c6c575ed7ceca67ca2e4f9d6de9f75919c3bbd31 Mon Sep 17 00:00:00 2001 From: Bassam Tabbara Date: Wed, 5 Apr 2017 12:34:31 -0700 Subject: [PATCH] build: make promote idempotent --- build/makelib/release.mk | 5 +++-- build/release/common.sh | 36 +++++++++++++++++++++++++++++++++++- build/release/metadata.sh | 32 -------------------------------- build/release/release.sh | 12 ++++++++++-- 4 files changed, 48 insertions(+), 37 deletions(-) delete mode 100755 build/release/metadata.sh diff --git a/build/makelib/release.mk b/build/makelib/release.mk index 77406b294..1b8893a13 100644 --- a/build/makelib/release.mk +++ b/build/makelib/release.mk @@ -44,7 +44,7 @@ RELEASE_PLATFORMS ?= RELEASE_CLIENT_ONLY_PLATFORMS ?= # Optional. the flavors to release -RELEASE_FLAVORS := metadata binaries containers +RELEASE_FLAVORS := binaries containers # Optional. Github token repo and user GITHUB_TOKEN ?= @@ -104,7 +104,8 @@ release.build: release.build.all release.publish: release.publish.all release.promote: - @build/release/release.sh init + @build/release/release.sh promote.init @$(MAKE) release.promote.all + @build/release/release.sh promote.complete release.cleanup: release.cleanup.all diff --git a/build/release/common.sh b/build/release/common.sh index 4e4fa8e10..4ad1e3e70 100644 --- a/build/release/common.sh +++ b/build/release/common.sh @@ -75,6 +75,21 @@ github_create_release() { fi } +github_delete_release() { + id=$(github_get_release_id) + + if [[ ${id} != "null" ]]; then + echo deleting existing github release ${id} for ${RELEASE_VERSION} + curl -4 -s -X DELETE -H "Authorization: token ${GITHUB_TOKEN}" \ + "https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases/${id}" + fi +} + +github_create_or_replace_release() { + github_delete_release + github_create_release +} + github_upload() { local filepath=$1 local mediatype=$(get_mediatype_from_extension $filepath) @@ -106,6 +121,21 @@ github_upload() { fi } +write_version_file() { + # upload a file with the version number + cat < ${RELEASE_DIR}/version +${version} +EOF +} + +publish_version_file() { + s3_upload ${RELEASE_DIR}/version + + if [[ "${RELEASE_CHANNEL}" == "master" ]]; then + s3_promote_file version + fi +} + # we assume that AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and possibly AWS_DEFAULT_REGION are already set # or ~/.aws/credentials and ~/.aws/config are configured @@ -132,5 +162,9 @@ s3_promote_file() { if [[ "${RELEASE_CHANNEL}" != "master" ]]; then aws s3 cp --only-show-errors s3://${RELEASE_S3_BUCKET}/master/${RELEASE_VERSION}/${filename} s3://${RELEASE_S3_BUCKET}/${RELEASE_CHANNEL}/${RELEASE_VERSION}/${filename} fi - aws s3 cp --only-show-errors s3://${RELEASE_S3_BUCKET}/master/${RELEASE_VERSION}/${filename} s3://${RELEASE_S3_BUCKET}/${RELEASE_CHANNEL}/current/${filename} +} + +s3_promote_release() { + echo copying ${RELEASE_VERSION} to current for channel ${RELEASE_CHANNEL} in S3 bucket ${RELEASE_S3_BUCKET} + aws s3 sync --only-show-errors --delete s3://${RELEASE_S3_BUCKET}/master/${RELEASE_VERSION} s3://${RELEASE_S3_BUCKET}/${RELEASE_CHANNEL}/current } diff --git a/build/release/metadata.sh b/build/release/metadata.sh deleted file mode 100755 index 50fff982d..000000000 --- a/build/release/metadata.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -e - -scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source ${scriptdir}/common.sh - -build() { - # upload a file with the version number - cat < ${RELEASE_DIR}/version -${version} -EOF -} - -publish() { - s3_upload ${RELEASE_DIR}/version - - if [[ "${RELEASE_CHANNEL}" == "master" ]]; then - s3_promote_file version - fi -} - -promote() { - s3_promote_file version -} - -cleanup() { - : -} - -action=$1 -shift - -${action} "$@" diff --git a/build/release/release.sh b/build/release/release.sh index 92a16a392..aae321dfa 100755 --- a/build/release/release.sh +++ b/build/release/release.sh @@ -19,12 +19,20 @@ case ${action} in ${scriptdir}/${flavor}.sh ${action} ${platform%_*} ${platform#*_} ;; - init) + promote.init) if check_release_version; then echo ${RELEASE_VERSION} can not be promoted. Must build from a tag like v0.4.0. exit 1 fi - github_create_release + + echo promoting release ${RELEASE_VERSION} to channel ${RELEASE_CHANNEL} + write_version_file + publish_version_file + github_create_or_replace_release + ;; + + promote.complete) + s3_promote_release ;; *)