Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script to create GitHub release
#!/bin/bash
MESSAGE="0"
VERSION="0"
DRAFT="false"
PRE="false"
BRANCH="master"
GITHUB_ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
# get repon name and owner
REPO_REMOTE=$(git config --get remote.origin.url)
if [ -z $REPO_REMOTE ]; then
echo "Not a git repository"
exit 1
fi
REPO_NAME=$(basename -s .git $REPO_REMOTE)
REPO_OWNER=$(git config --get user.name)
# get args
while getopts v:m:b:draft:pre: option
do
case "${option}"
in
v) VERSION="$OPTARG";;
m) MESSAGE="$OPTARG";;
b) BRANCH="$OPTARG";;
draft) DRAFT="true";;
pre) PRE="true";;
esac
done
if [ $VERSION == "0" ]; then
echo "Usage: git-release -v <version> [-b <branch>] [-m <message>] [-draft] [-pre]"
exit 1
fi
# set default message
if [ "$MESSAGE" == "0" ]; then
MESSAGE=$(printf "Release of version %s" $VERSION)
fi
API_JSON=$(printf '{"tag_name": "v%s","target_commitish": "%s","name": "v%s","body": "%s","draft": %s,"prerelease": %s}' "$VERSION" "$BRANCH" "$VERSION" "$MESSAGE" "$DRAFT" "$PRE" )
API_RESPONSE_STATUS=$(curl --data "$API_JSON" -s -i https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases?access_token=$GITHUB_ACCESS_TOKEN)
echo "$API_RESPONSE_STATUS"
@mcguffin

This comment has been minimized.

Copy link
Owner Author

@mcguffin mcguffin commented Aug 10, 2017

Script Setup

  1. Move the script to some directory covered by your local $PATH variable.
  2. Go to your github account and create a presonal access token, granting access to the repo scope
  3. Replace <YOUR_ACCESS_TOKEN> with (surprise!) your access token.

Usage
Your repository's remote origin has to be a github location. Setup and commit a .gitattributes file to exclude developer related files like sources or tests.

  1. cd into the root directory of your git repo.
  2. Simple: git-release -v some.version.number
  3. For advanced options just type git-release
@mcguffin

This comment has been minimized.

Copy link
Owner Author

@mcguffin mcguffin commented Dec 2, 2017

Discontinued in favor of git-release.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment