Created
January 22, 2014 16:09
-
-
Save shunirr/8561505 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
GH_TOKEN=$1 | |
UPLOAD_FILE=$2 | |
GH_USER_NAME=$3 | |
GH_REPO_NAME=$4 | |
VERSION=$5 | |
if [ $# -ne 5 ]; then | |
echo "Invalid arguments." | |
echo "Usage: $0 GH_TOKEN UPLOAD_FILE GH_USER_NAME GH_REPO_NAME VERSION" | |
exit 1 | |
fi | |
JQ=`which jq` | |
if [ ! -f $JQ ]; then | |
echo "require jq" | |
echo "'sudo apt-get install jq'" | |
exit 1 | |
fi | |
BRANCH=$TRAVIS_BRANCH | |
if [ ! $BRANCH ]; then | |
BRANCH="master" | |
fi | |
curl -o release.json \ | |
-H "Authorization: token $GH_TOKEN" \ | |
-H "Accept: application/json" \ | |
-H "Content-type: application/json" \ | |
-X POST \ | |
-d "{\"tag_name\":\"$VERSION\",\"target_commitish\":\"$BRANCH\",\"name\":\"$VERSION\"}" \ | |
https://api.github.com/repos/$GH_USER_NAME/$GH_REPO_NAME/releases | |
UPLOAD_URL=`cat release.json | $JQ ".upload_url" | sed "s/{?name}/?name=$UPLOAD_FILE/g" | sed "s/\"//g"` | |
rm release.json | |
if [ $UPLOAD_URL ]; then | |
curl -H "Authorization: token $GH_TOKEN" \ | |
-H "Accept: application/json" \ | |
-H "Content-type: application/octet-stream" \ | |
-X POST \ | |
--data-binary @$UPLOAD_FILE \ | |
"$UPLOAD_URL" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment