Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/github-release.sh
#!/usr/bin/env bash | #!/usr/bin/env bash | ||||
export LC_ALL=C | export LC_ALL=C | ||||
set -euo pipefail | set -euo pipefail | ||||
SCRIPT_PATH="$(dirname "$0")" | SCRIPT_PATH="$(dirname "$0")" | ||||
ORIGINAL_PWD=$(pwd) | ORIGINAL_PWD=$(pwd) | ||||
TOPLEVEL="$(cd "${SCRIPT_PATH}"; git rev-parse --show-toplevel)" | TOPLEVEL="$(cd "${SCRIPT_PATH}"; git rev-parse --show-toplevel)" | ||||
OAUTH_TOKEN_PATH="${PWD}/.github-oauth-token" | OAUTH_TOKEN_PATH="${PWD}/.github-oauth-token" | ||||
TAG="" | RELEASE_NOTES_DIR="${TOPLEVEL}/doc/release-notes" | ||||
help_message() { | help_message() { | ||||
echo "Create a draft Github release and upload binaries." | echo "Create a draft Github release and upload binaries." | ||||
echo "Usage: $0 <options>" | echo "Usage: $0 <options>" | ||||
echo "-a, --asset-dir (required) Path to the top-level directory outputted by a Gitian build." | echo "-a, --asset-dir (required) Path to the top-level directory outputted by a Gitian build." | ||||
echo " This directory must contain linux, osx, and win binaries in those respective sub-directories." | echo " This directory must contain linux, osx, and win binaries in those respective sub-directories." | ||||
echo "-d, --dry-run Run through the script, but do not touch existing tags, push to Github, or upload release files." | echo "-d, --dry-run Run through the script, but do not touch existing tags, push to Github, or upload release files." | ||||
echo "-h, --help Display this help message." | echo "-h, --help Display this help message." | ||||
echo "-o, --oauth-token Path to a file containing your OAuth token (defaults to: '${OAUTH_TOKEN_PATH}')." | echo "-o, --oauth-token Path to a file containing your OAuth token (defaults to: '${OAUTH_TOKEN_PATH}')." | ||||
echo "-r, --release-notes Path to the release notes file (defaults to: '${RELEASE_NOTES_DIR}/release-notes-<version>.md')." | |||||
echo "-t, --tag (required) The git tag create a release for. This tag must already exist." | echo "-t, --tag (required) The git tag create a release for. This tag must already exist." | ||||
} | } | ||||
ASSET_DIR="" | ASSET_DIR="" | ||||
DRY_RUN="false" | DRY_RUN="false" | ||||
RELEASE_NOTES_PATH="" | |||||
TAG="" | |||||
# Parse command line arguments | # Parse command line arguments | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
-a|--assets-dir) | -a|--assets-dir) | ||||
ASSET_DIR=$(cd $2; pwd) | ASSET_DIR=$(cd $2; pwd) | ||||
shift # shift past argument | shift # shift past argument | ||||
shift # shift past value | shift # shift past value | ||||
;; | ;; | ||||
-d|--dry-run) | -d|--dry-run) | ||||
DRY_RUN="true" | DRY_RUN="true" | ||||
shift # shift past argument | shift # shift past argument | ||||
;; | ;; | ||||
-h|--help) | -h|--help) | ||||
help_message | help_message | ||||
exit 0 | exit 0 | ||||
;; | ;; | ||||
-o|--oauth-token) | -o|--oauth-token) | ||||
OAUTH_TOKEN_PATH="$2" | OAUTH_TOKEN_PATH="$2" | ||||
shift # shift past argument | shift # shift past argument | ||||
shift # shift past value | shift # shift past value | ||||
;; | ;; | ||||
-r|--release-notes) | |||||
RELEASE_NOTES_PATH="$2" | |||||
shift # shift past argument | |||||
shift # shift past value | |||||
;; | |||||
-t|--tag) | -t|--tag) | ||||
TAG="$2" | TAG="$2" | ||||
shift # shift past argument | shift # shift past argument | ||||
shift # shift past value | shift # shift past value | ||||
;; | ;; | ||||
*) | *) | ||||
echo "Unknown argument: $1" | echo "Unknown argument: $1" | ||||
help_message | help_message | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for FILENAME in "${ASSET_LIST[@]}"; do | ||||
fi | fi | ||||
done | done | ||||
else | else | ||||
echo "Error: Asset directory '${ASSET_DIR}' does not exist" | echo "Error: Asset directory '${ASSET_DIR}' does not exist" | ||||
exit 32 | exit 32 | ||||
fi | fi | ||||
# Fetch release notes | # Fetch release notes | ||||
RELEASE_NOTES=$(jq -Rs '.' "${TOPLEVEL}/doc/release-notes/release-notes-${VERSION}.md") | if [ -z "${RELEASE_NOTES_PATH}" ]; then | ||||
RELEASE_NOTES_PATH="${RELEASE_NOTES_DIR}/release-notes-${VERSION}.md" | |||||
fi | |||||
RELEASE_NOTES=$(jq -Rs '.' "${RELEASE_NOTES_PATH}") | |||||
if [ "${RELEASE_NOTES}" == '""' ]; then | if [ "${RELEASE_NOTES}" == '""' ]; then | ||||
echo "Error: Could not fetch release notes for version '${VERSION}'" | echo "Error: Could not fetch release notes for version '${VERSION}'" | ||||
exit 40 | exit 40 | ||||
fi | fi | ||||
# Format request data | # Format request data | ||||
POST_DATA="{\"tag_name\": \"${TAG}\", \"name\": \"${VERSION}\", \"body\": ${RELEASE_NOTES}, \"draft\": true}" | POST_DATA="{\"tag_name\": \"${TAG}\", \"name\": \"${VERSION}\", \"body\": ${RELEASE_NOTES}, \"draft\": true}" | ||||
URL="https://api.github.com/repos/bitcoin-abc/bitcoin-abc/releases" | URL="https://api.github.com/repos/bitcoin-abc/bitcoin-abc/releases" | ||||
Show All 29 Lines |