Bash Shell Script To Create a Release on GitHub

This shell script will create a new Release on GitHub for your git repo. This script should be placed in the base of your local git repository.

You must configure the first 3 variables:

  • ACCESSTOKEN – Set this to your personal GitHub access token. You can create an access token in your GitHub account > Settings > Developer Settings > Personal access tokens.
  • GITUSER – Set this to your GitHub username.
  • NAME – If your local git repository directory name is exactly the same as the remote GitHub repository name, then leave this as is. Otherwise, set this to the name of your remote GitHub repository.
#! /bin/bash
# Create official Release on GitHub.

# config
ACCESSTOKEN="0123456789"
GITUSER="username"
NAME=${PWD##*/} # name of your GitHub repository

GITPATH=`pwd` # this file should be in the base of your local git repository
# Get version from readme
NEWVERSION=`grep "^Version" "$GITPATH/README.md" | awk -F' ' '{print $2}' | sed 's/[[:space:]]//g'`

# Let's begin...
echo ".........................................."
echo 
echo "Preparing to release version $NEWVERSION on GitHub"
echo 
echo ".........................................."
echo 

# Create a Release on GitHub
cd "$GITPATH"
echo "Creating a new release on GitHub"
API_JSON=$(printf '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": "Release of version %s","draft": false,"prerelease": false}' $NEWVERSION $NEWVERSION $NEWVERSION)
curl --data "$API_JSON" https://api.github.com/repos/${GITUSER}/${NAME}/releases?access_token=${ACCESSTOKEN}

echo "*** FIN ***"

See more: , ,

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]