GitHub CLI Auth with token from environment variable

Streamline Your Release Process: Automate GitHub Releases with GitHub CLI and CircleCI using this Handy Script!

You can use the github cli to automate release processes in continuous deployment situations. In CircleCI for instance set a context environment variable to the GitHub token for your user. Then in a script echo the variable into a file and read that with the Github cli. Be sure to unset the environment variable to ensure that the CLI does not complain (It checks the environment before executing to find your token and prevent use).

#!/bin/env bash
set -u
echo "$GITHUB_TOKEN" > .githubtoken
gh auth login --with-token < .githubtoken
rm .githubtoken
gh release create $VERSION --notes "Release $VERSION. $COMMIT_MESSAGE"

Run it to create a github release automatically in a shell with a temporary file:

GITHUB_TOKEN='your-token' VERSION='v0.0.1' COMMIT_MESSAGE='We did it' ./