build: make promote idempotent
This commit is contained in:
1 parent
32cd0a18bd
commit
c6c575ed7c
4 files changed
+48
-37
No files matched your search
@@ -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
|
||||
+35
-1
@@ -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 <<EOF > ${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
|
||||
}
|
||||
@@ -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 <<EOF > ${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} "$@"
|
||||
@@ -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
|
||||
;;
|
||||
|
||||
*)
|
||||
|
||||
Reference in new issue
Block a user