Releasing Go Application to Homebrew

Jul 11, 2021 3 min read
Releasing Go Application to Homebrew

Releasing Go applications via Homebrew.

A good application will have a good release strategy.

Release Strategy ??

Use Case

Suppose you are given the task of deploying a small solution in your firm which does functionality X.

Let X = functionality to generate boilerplate code for a project which can be used by other software developers.

This solution will save a lot of time for the other developers who want to set up a similar project from scratch.

How can you ensure that other developers directly use the solution without any configuration changes or installation headaches?

A simple option is to publish the solution as a binary (.exe in windows). This binary should run on various platforms like Windows, macOS, Linux. Factors like the CPU architecture (x86, ARM) should also be considered before releasing the binary to a wider audience.

The Solution: GoReleaser

For Go projects, there is an amazing tool known as GoReleaser. While Goreleaser helps in releasing Go applications via Docker, GitHub Actions etc, for this blog we will only concentrate on releasing the binaries to Homebrew to satisfy our requirement.

A sample template of GoReleaser to release to Homebrew is at following link. The gist has comments as well:

Sample GoReleaser yaml
Sample GoReleaser yaml. GitHub Gist: instantly share code, notes, and snippets.

Installation:

brew install goreleaser

Add GoReleaser yml

goreleaser init

This adds a .goreleaser.yml file in the root directory of the project.

GoReleaser requires a new tag before publishing. Hence make sure the commit is tagged by using the following commands.

Tag a Release

git tag -a v0.1.0 -m "First release"
git push origin v0.1.0

//Note that git needs to be installed for the above commands to work

If GoReleaser needs to be tested for configurations without tagging and publishing it into Github use the following command

goreleaser --snapshot --skip-publish --rm-dist

Also don't forget to export your GITHUB_TOKEN or GITLAB_TOKEN as environment variables

export GITHUB_TOKEN="YOUR_GH_TOKEN"
export GITLAB_TOKEN="YOUR_GL_TOKEN"

To release a software package using GoReleaser, just type in the following command and it should push it to Homebrew. That's it!!!

Release a Go Binary

goreleaser release 

Remember, while pushing the package to Homebrew it creates a ruby file which is automatically added .

Conclusion

This post taught you how to create a small application in GO and release it via Homebrew .

Other developers in the firm can now install this application from Homebrew without knowing how this needs to be installed and what is inside.

We have a created a simple solution to the above problem statement and named the framework as Autobots. Autobots uses GoReleaser to release the binary to Homebrew. Take a look at our project at :

gochronicles/cli
Create production ready microservices mono repo pattern wired with Neo4j. Microservices for other languages and front end repos to be added as well in future. - gochronicles/cli

Join the conversation

Table of Contents
Great! Next, complete checkout for full access to Go Chronicles.
Welcome back! You've successfully signed in.
You've successfully subscribed to Go Chronicles.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.