Using Homebrew for distributing Go apps (part 2)

2023-04-13

Go · Golang · Goreleaser · Homebrew · Ruby · Tech

1 minute

For personal reference:

This is a followup on a previous post that is a bit more manual. This is a little bit easier.

a) Create your own Homebrew tap

Create a new GitHub public repository with a prefix homebrew-, i.e. homebrew-tap. This will host all the apps that you want to distribute via your tap. Users will install your apps using the following commands:

# No need to include the 'homebrew-' prefix
$ brew tap flowerinthenight/tap
$ brew install <toolname>

# Or one-liner
$ brew install flowerinthenight/tap/<toolname>

b) Let’s use Github Actions to setup goreleaser

First, add a .goreleaser.yml config file to your Go repo. Here’s an example:

The section of note here is the brews: part. You can check goreleaser’s Quickstart guide for more information.

Here’s an example of a GitHub Action config on how to setup goreleaser to do the release for our tags.

See the name: Run goreleaser section. You need to add a personal access token with repo, workflow, write:packages permissions to your repository’s secrets. In this example, the name used is GH_PAT but you can use other names as well.

c) Do a tagged release

Tagged releases should now do a deployment to your tap.

$ git tag v1.0.0
$ git push --tags