forked from rook/rook
build: fix promote to github
This commit is contained in:
@@ -72,6 +72,9 @@ To promote a release run the `promote` target as follows:
|
||||
make promote CHANNEL=alpha VERSION=v0.4.0
|
||||
```
|
||||
|
||||
NOTE: Promoting requires that you have AWS credentials (in ~/.aws or in environment), github token (export GITHUB_TOKEN), and
|
||||
quay.io write access (via ~/.docker/credentials).
|
||||
|
||||
After promoting a release, on S3 there will be a path for each channel and release promoted as follows:
|
||||
|
||||
```
|
||||
|
||||
@@ -68,7 +68,6 @@ publish() {
|
||||
local arch=$2
|
||||
local file=$(get_archive_name $os $arch)
|
||||
|
||||
echo uploading $file to S3
|
||||
s3_upload ${RELEASE_DIR}/$file
|
||||
|
||||
# we will always tag master builds as latest. i.e. auto-promote master
|
||||
@@ -78,7 +77,6 @@ publish() {
|
||||
|
||||
if [[ ${os} == "linux" ]]; then
|
||||
file=$(get_archive_name $os $arch "debug")
|
||||
echo uploading $file to S3
|
||||
s3_upload ${RELEASE_DIR}/$file
|
||||
|
||||
if [[ "${RELEASE_CHANNEL}" == "master" ]]; then
|
||||
@@ -91,16 +89,20 @@ promote() {
|
||||
local os=$1
|
||||
local arch=$2
|
||||
local file=$(get_archive_name $os $arch)
|
||||
local ext=$(get_archive_ext $os)
|
||||
|
||||
echo promoting $file to channel ${RELEASE_CHANNEL}
|
||||
s3_promote_file $file
|
||||
github_upload ${RELEASE_DIR}/$file $ext
|
||||
if [[ ! -e ${RELEASE_DIR}/$file ]]; then
|
||||
s3_download ${RELEASE_DIR}/$file
|
||||
fi
|
||||
github_upload ${RELEASE_DIR}/$file
|
||||
|
||||
if [[ ${os} == "linux" ]]; then
|
||||
file=$(get_archive_name $os $arch "debug")
|
||||
s3_promote_file $file
|
||||
github_upload ${RELEASE_DIR}/$file $ext
|
||||
if [[ ! -e ${RELEASE_DIR}/$file ]]; then
|
||||
s3_download ${RELEASE_DIR}/$file
|
||||
fi
|
||||
github_upload ${RELEASE_DIR}/$file
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
+61
-10
@@ -36,48 +36,99 @@ check_release_version() {
|
||||
fi
|
||||
}
|
||||
|
||||
get_mediatype_from_extension() {
|
||||
local file=$1
|
||||
local ext=${file##*.}
|
||||
local mediatype
|
||||
|
||||
case ${ext} in
|
||||
gz) echo "application/gzip" ;;
|
||||
zip) echo "application/zip" ;;
|
||||
*) echo "UNSUPPORTED" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
github_get_release_id() {
|
||||
curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
"https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases/tags/${RELEASE_VERSION}" | jq -r '.id'
|
||||
}
|
||||
|
||||
github_get_upload_url() {
|
||||
curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
"https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases/tags/${RELEASE_VERSION}" | jq -r '.upload_url'
|
||||
}
|
||||
|
||||
github_create_release() {
|
||||
id=$(github_get_release_id)
|
||||
|
||||
if [[ ${id} == "null" ]]; then
|
||||
curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
echo creating a new github release for ${RELEASE_VERSION}
|
||||
id=$(curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\": \"${RELEASE_VERSION}\",\"target_commitish\": \"master\",\"name\": \"${RELEASE_VERSION}\",\"body\": \"TBD\",\"draft\": true,\"prerelease\": true}" \
|
||||
"https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases"
|
||||
-d "{\"tag_name\": \"${RELEASE_VERSION}\",\"target_commitish\": \"master\",\"name\": \"${RELEASE_VERSION}\",\"body\": \"TBD\",\"draft\": false,\"prerelease\": true}" \
|
||||
"https://api.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases" | jq -r '.id')
|
||||
|
||||
if [[ ${id} == "null" ]]; then
|
||||
echo error: failed to create github release
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
github_upload() {
|
||||
local filepath=$1
|
||||
local mediatype=$2
|
||||
local mediatype=$(get_mediatype_from_extension $filepath)
|
||||
local filename=$(basename $filepath)
|
||||
|
||||
id=$(github_get_release_id)
|
||||
upload_url=$(github_get_upload_url)
|
||||
|
||||
curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
if [[ ${upload_url} == "null" ]]; then
|
||||
echo error: could not get upload url for github release
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! -e ${filepath} ]]; then
|
||||
echo error: could not find file ${filepath}
|
||||
return 1
|
||||
fi
|
||||
|
||||
upload_url=${upload_url%{*} # remove the trailing {?name,label}
|
||||
|
||||
echo uploading ${filename} github release ${RELEASE_VERSION}
|
||||
id=$(curl -4 -s -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Accept: application/vnd.github.manifold-preview" \
|
||||
-H "Content-Type: application/${mediatype}" \
|
||||
-H "Content-Type: ${mediatype}" \
|
||||
--data-binary @${filepath} \
|
||||
"https://uploads.github.com/repos/${GITHUB_USER}/${GITHUB_REPO}/releases/${id}/assets?name=${filename}"
|
||||
"${upload_url}?name=${filename}" | jq -r '.id')
|
||||
if [[ ${id} == "null" ]]; then
|
||||
echo error: failed to upload ${filename} to github
|
||||
return 1
|
||||
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
|
||||
|
||||
s3_upload() {
|
||||
local filepath=$1
|
||||
local filename=$(basename $filepath)
|
||||
|
||||
# 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
|
||||
echo uploading ${filename} to S3 bucket ${RELEASE_S3_BUCKET}
|
||||
aws s3 cp --only-show-errors ${filepath} s3://${RELEASE_S3_BUCKET}/${RELEASE_CHANNEL}/${RELEASE_VERSION}/${filename}
|
||||
}
|
||||
|
||||
s3_download() {
|
||||
local filepath=$1
|
||||
local filename=$(basename $filepath)
|
||||
|
||||
echo downloading ${filename} from S3 bucket ${RELEASE_S3_BUCKET}
|
||||
aws s3 cp --only-show-errors s3://${RELEASE_S3_BUCKET}/${RELEASE_CHANNEL}/${RELEASE_VERSION}/${filename} ${filepath}
|
||||
}
|
||||
|
||||
s3_promote_file() {
|
||||
local filename=$1
|
||||
|
||||
echo copying ${filename} from master to ${RELEASE_CHANNEL} in S3 bucket ${RELEASE_S3_BUCKET}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user