Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pedrolopesme/c3f6302ca0d85b556e8c68c33bab6c44 to your computer and use it in GitHub Desktop.
Save pedrolopesme/c3f6302ca0d85b556e8c68c33bab6c44 to your computer and use it in GitHub Desktop.
Homebrew Formula for a Go app

Homebrew Formula for a Go app

These are quick notes from making a glan Formula and Tap.

Add go build script to your Git repo

gobuild.sh

#!/bin/bash

set -eux

export GOPATH="$(pwd)/.gobuild"
SRCDIR="${GOPATH}/src/github.com/<YOUR GITHUB USER>/<YOUR GITHUB REPO>"

[ -d ${GOPATH} ] && rm -rf ${GOPATH}
mkdir -p ${GOPATH}/{src,pkg,bin}
mkdir -p ${SRCDIR}
cp main.go ${SRCDIR}
(
    echo ${GOPATH}
    cd ${SRCDIR}
    go get .
    go install .
)

Create tar.gz

You can do this by tagging your Github repository with a version (via Release).

Update Brew

brew update

Create Formula skel

brew create 'https://github.com/mickep76/tf/archive/X.X.tar.gz'

Modify Formula

/usr/local/Library/Formula/tf.rb

class Tf < Formula
  homepage "https://github.com/mickep76/tf"
  url "https://github.com/<YOUR GITHUB USER>/<YOUR GITHUB REPO>/archive/<THE VERSION YOU'VE CREATED>.tar.gz"
  sha256 "b59730cfbc3c62027bd91942c70d3d07c2bbc4f82b0332d17da977bb7f2041bc"

  depends_on "go" => :build

  def install
    system "gobuild.sh"
    bin.install ".gobuild/bin/<YOU PACKAGE NAME>" => "<YOUR PACKAGE NAME>"
  end

  test do
    system "#{bin}/<YOU PACKAGE NAME>", "--help"
  end
end

Audit Formula

brew audit --strict tf

Test local install

HOMEBREW_MAKE_JOBS=1 brew install -v <YOUR PACKAGE NAME>

Github pull request

Github pull request

Make your own Tap

Create a Git repo called "homebrew-something".

Add your formula to the root of the repo. After this you can use it like:

The "name" should not include "homebrew-" which is a prefix

brew tap <YOUR USER>/something
brew install <YOUR USERNAME>/something/<YOUR PACKAGE NAME>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment