GitHub CLI Auth with token from environment variable
How to set GitHub CLI token in terminal without a file
Table of contents
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).
set -u echo "$GITHUB_TOKEN" > .githubtoken unset GITHUB_TOKEN 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' ./script.sh