Last active
August 29, 2015 14:26
-
-
Save jabooth/990a4c3eae4e188a13e2 to your computer and use it in GitHub Desktop.
Upload a dataset release to GitHub
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/bash | |
| # | |
| # Upload release datasets to github. | |
| # | |
| # Usage: | |
| # ~/dataset.sh ./path/to/dataset | |
| # | |
| # Note that the path should go to the internal file inside the git repo | |
| # in question, and not that by convention this folder name MUST MATCH | |
| # the name of the repo. | |
| # | |
| TOKEN=`cat ~/.mbtoken` | |
| ORG=menpo | |
| P=$1 | |
| NAME=`basename $P` | |
| echo tarring up dataset called $NAME at $P | |
| TMP_PATH=/tmp/$NAME.tar.gz | |
| tar -zcf $TMP_PATH $P | |
| SHASUM=`shasum $TMP_PATH` | |
| echo "SHA: $SHASUM" | |
| RELEASES=`curl -sS -H "Authorization: token $TOKEN" https://api.github.com/repos/$ORG/$NAME/releases` | |
| UPLOAD_TEMPLATE=`echo $RELEASES | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj[0]["upload_url"])'` | |
| UPLOAD_URL=`echo $UPLOAD_TEMPLATE | sed "s/{?name}/?name=$NAME.tar.gz/g"` | |
| ASSET_ID=`echo $RELEASES | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj[0]["assets"][0]["id"])'` | |
| DELETE_URL=https://api.github.com/repos/$ORG/$NAME/releases/assets/$ASSET_ID | |
| echo "Clearing any existing asset on latest release for $NAME" | |
| curl -X DELETE -H "Authorization: token $TOKEN" $DELETE_URL | |
| echo "Uploading $TMP_PATH to latest release for $NAME" | |
| curl -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/x-gzip" $UPLOAD_URL --data-binary "@$TMP_PATH" > /dev/null | |
| echo clearing up $TMP_PATH | |
| rm $TMP_PATH | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning to self - this just looks for the latest release and uploads. In the future you might want to add a second argument (version) to prevent any unexpected issues (uploading before a new tag is made)