Last active
April 26, 2018 19:42
-
-
Save robert-wallis/f76f33e4f1133c5233a852a2633771b8 to your computer and use it in GitHub Desktop.
Publish git tag with build folder gzipped to github releases from the command line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2018, Robert A. Wallis, All Rights Reserved | |
# | |
# make_release.sh expects a `git tag v1.2.3` style tag to have been created for the version `1.2.3` stored in buildnumber.txt | |
# It then creates a release out of the commit notes from the previous version's tag to the current version. | |
# And uploads the contents of the build/ folder as v1.2.3.tgz as an asset. | |
set -e | |
GITHUB_USER="robert-wallis" | |
GITHUB_REPO="yourRepoHere" | |
GITHUB="https://api.github.com" | |
GITHUB_UPLOADS="https://uploads.github.com" | |
VERSION="v$(cat buildnumber.txt)" | |
if [[ "$(which jq)" == "" ]]; then | |
echo "please install jq; brew install jq" | |
exit -1 | |
fi | |
if [[ "$VERSION" == "v" ]]; then | |
echo "buildnumber.txt empty" | |
exit -1 | |
fi | |
LAST_TAGS="$(git tag | sort --version-sort | tail -n 2)" | |
LAST_TAG="${LAST_TAGS##*$'\n'}" | |
if [[ "$VERSION" == $LAST_TAG ]]; then | |
LAST_TAG=(${LAST_TAGS[@]}) | |
fi | |
LOGS=$(git log --pretty=format:'- %h %B' $LAST_TAG..HEAD | jq -Rj '(. + "\\n")') | |
BACKUP_FILE="${VERSION}.tgz" | |
tar -czvf "${BACKUP_FILE}" build/ | |
echo "Github 2FA for ${GITHUB_USER}?" | |
read OTP | |
BODY="$(echo $LOGS | tr \" \')" | |
JSON=$(cat <<-ENDJSON | |
{ | |
"tag_name": "${VERSION}", | |
"target_commitish": "", | |
"name": "${VERSION}", | |
"body": "${BODY}", | |
"draft": true, | |
"prerelease": true | |
} | |
ENDJSON | |
) | |
echo "Creating Release ${VERSION}" | |
echo "$JSON" | curl -u ${GITHUB_USER} -X POST -H "X-GitHub-OTP: ${OTP}" -d @- "${GITHUB}/repos/${GITHUB_USER}/${GITHUB_REPO}/releases" > res.json | |
RELEASE_ID=$(cat res.json | jq -r '.id') | |
HTML_URL=$(cat res.json | jq -r '.html_url') | |
rm res.json | |
MIME_TYPE=$(file -b --mime-type ${BACKUP_FILE}) | |
echo "Uploading Build Archive ${MIME_TYPE} to Release id ${RELEASE_ID}" | |
curl -u ${GITHUB_USER} -X POST -H "X-GitHub-OTP: ${OTP}" -H "Content-Type: ${MIME_TYPE}" --data-binary "@${BACKUP_FILE}" "${GITHUB_UPLOADS}/repos/${GITHUB_USER}/${GITHUB_REPO}/releases/${RELEASE_ID}/assets?name=${BACKUP_FILE}" | |
rm ${BACKUP_FILE} | |
echo "Done making release: ${VERSION} ${HTML_URL}" | |
open "${HTML_URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment