Image for a hint

You can automate publishing releases to GitHub to save some time and prevent human-factor mistakes. The hint shows you how to create the release and then upload an attachment with GitHub API using curl.

You can run such script manually from your local PC or automate processes using a CI system.

Create bash script (e.g. with next commands:

#!/usr/bin/env bash

# user/organisation where repo is hosted and repo name e.g. for devforth/reponame:
GH_TOKEN=`cat ~/.ghtoken`
<run some build command>
VERSION=`grep '"version":' version.json | cut -d\" -f4`
git add -u
git commit -m "$VERSION release"
git push
res=`curl --user "$GH_USER:$GH_TOKEN" -X POST${GH_REPO_USER}/${GH_REPO}/releases \
-d "
\"tag_name\": \"v$VERSION\",
\"target_commitish\": \"$GH_TARGET\",
\"name\": \"v$VERSION\",
\"body\": \"new version $VERSION\",
\"draft\": false,
\"prerelease\": false
echo Create release result: ${res}
rel_id=`echo ${res} | python -c 'import json,sys;print(json.load(sys.stdin)["id"])'`
curl --user "$GH_USER:$GH_TOKEN" -X POST${GH_REPO_USER}/${GH_REPO}/releases/${rel_id}/assets?name=${file_name}\
--header 'Content-Type: text/javascript ' --upload-file ${ASSETS_PATH}/${file_name}
rm ${ASSETS_PATH}/${file_name}

Script assumes that <run some build command> will auto-update version.json file, which can be something like this:

"version": "1.1.5",

Also, it assumes that after <run some build command> file named yourproj-${VERSION}.ext will be created in ASSETS_PATH, e.g. build/yourproj-1.1.5.ext (This file will be uploaded as a release attachment)

We recommend following semver for your projects.

Creating access token

The script assumes that you store your GitHub access token in ~/.ghtoken file in your filesystem.

To create it go to the, and tick 'repo':

Scopes select

Enter some description and press Generate token.

Copy and paste token to ~/.ghtoken file:

echo "<yourValueLike:>a1d23d126223b709e8f1211thisfakecf013155" > ~/.ghtoken

Please don't store the token in the file system if you are not sure that it is protected enough from multi-user or remote access on your machine.