DEV Community

Sheldon
Sheldon

Posted on β€’ Originally published at sheldonhull.com on

2

Quickly Create Github Release via Cli

Intro

I've been trying to improve modularization with Terraform.Using Terraform Cloud, you get a private module repository.The modules are linked to tags in git.

I've wanted additionally to specifically create releases for the versions in addition to the tags, to make tracking of usable versions a little cleaner.

There are several ways to do this, including using the GitHub API, npm modules, and more.I wanted a simple CLI tool to do this and ran across this great Go utility that worked seamlessly for me.

I've used the Hub cli but the create release syntax never really worked for me.

github-release

Github-release is a simple golang cli that worked great for me.Note that this is a fork.This fork is more up to date than the original.

With go installed just run this to get it installed and available in PATH.

go get github.com/itchio/gothub

Enter fullscreen mode Exit fullscreen mode

To simplify GitHub access, ensure you set an environment variable for your user called GITHUB_TOKEN.

With PowerShell you can do it quickly like this (you might need to close and reopen vscode/terminal for this to be recognized)

 [System.Environment]::SetEnvironmentVariable('GITHUB_TOKEN','tokenhere','User')

Enter fullscreen mode Exit fullscreen mode

Usage

To use this, you can chain together some steps and see how it can save you time on creating a GitHub release.

Setup Parameters
$MyUser            = 'sheldonhull' # or organization name
$RepoName          = 'test-repo'
$Message           = 'My Message here'
$ChangeDescription = 'My change notes for the release'
$Prerelease        = '--pre-release' # or just leave '' if you don't want to mark as prerelease

If you want to cleanup the one just created before updating, you could run the following statement to delete a prerelease

github-release delete --user $MyUser --repo $RepoName --tag $version
Add Current Changes and Commit
git add .
git commit -am"$Message"

Using GitVersion, a fantastic cross platform versioning tool, you can calculate the semver version on demand and use this to tag your commit/create your version.

To install gitversion on windows, try: choco install gitversion.portable -y

Dynamically Create Version
$version = (gitversion | ConvertFrom-Json).SemVer

Now the magic…​

Create Release
github-release release --user $MyUser --repo $RepoName --tag $version --name "πŸš€ $Version" --description "$ChangeDescription" $Prerelease

After finished you can output the release contents to list out what exists in Github.

Review Releases
github-release info --user $MyUser --repo $RepoName

This helped me get moving faster ⚑ on using Github releases without the tedious work to create.If this helped you or have any feedback, drop a comment below and let me know!The comments are powered by Utterances which will open a Github issue to discuss further. πŸ‘

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free β†’

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay