Skip to content

Commit

Permalink
Add Homebrew tap support via goreleaser (#48)
Browse files Browse the repository at this point in the history
* Add Homebrew tap support via goreleaser

A Homebrew tap is a third-party git repo that contains a "formula" that
homebrew can use to install some software not included in homebrew core.
The repo is usually presumed to be on GitHub, and must be named
something like '<owner>/homebrew-<tap name>' - in our case,
'homebrew-otel-cli'.

It seems that goreleaser supports automatically creating a formula and
then pushing it up to a third-party repo. In order to take advantage of
this support, someone will need to create a repo suitable for hosting
this, and generate the required credentials and pass them to goreleaser
as an env variable (which can be a GitHub secret used in the actions
workflow). Then, when goreleaser runs, it will push the latest formula
to the configured repo and homebrew users can install it.

As an end-user - presuming the repo is 'equinix-labs/homebrew-otel-cli',
you would do something like this:

```
$ brew tap 'equinix-labs/otel-cli'
$ brew install otel-cli
```

Note that while the repo *must* be named 'homebrew-otel-cli', users
drop the 'homebrew-' prefix when adding the tap.

I tested this by running: `goreleaser release --snapshot --skip-publish --rm-dist`
and the following formula was output to `dist/otel-cli.rb`, which looks
correct to me:

```ruby

class OtelCli < Formula
  desc "OpenTelemetry command-line tool for sending events from shell scripts & similar environments"
  homepage "https://github.com/packethost/otel-cli"
  version "v0.0.4-next"
  license "Apache-2.0"
  bottle :unneeded

  on_macos do
    if Hardware::CPU.intel?
      url "https://github.com/packethost/otel-cli/releases/download/v0.0.3/otel-cli_v0.0.4-next_Darwin_x86_64.tar.gz"
      sha256 "fe6f51aa4ce8a3cb2e599d455fa36b2f553130fa850ad2fd0ad7ad1657820d1a"
    end
    if Hardware::CPU.arm?
      url "https://github.com/packethost/otel-cli/releases/download/v0.0.3/otel-cli_v0.0.4-next_Darwin_arm64.tar.gz"
      sha256 "e1f9ce6e736d3e9b2346728d83942cdce3277f0dcbc0af72eb992ceb71b6bb56"
    end
  end

  on_linux do
    if Hardware::CPU.intel?
      url "https://github.com/packethost/otel-cli/releases/download/v0.0.3/otel-cli_v0.0.4-next_Linux_x86_64.tar.gz"
      sha256 "23c919ccf087f5f093f87ed14fe57e47deb2d16fb2c0940d9f9d576074be4e18"
    end
    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
      url "https://github.com/packethost/otel-cli/releases/download/v0.0.3/otel-cli_v0.0.4-next_Linux_arm64.tar.gz"
      sha256 "9d661508f6a0b121a0002ea05c2b361fb8bea14e9e448f76889a29c3d001d470"
    end
  end

  def install
    bin.install "otel-cli"
  end
end
```

* update settings & reorder file

Switched to point at equinix-labs instead of packethost.

Switched publisher to myself.

I think merging main reordered things so I've reordered the file.

Switched to use GITHUB_TOKEN instead - is this bad? My guess is
@ahayworth has a lot of tokens so has to be more careful?

Signed-off-by: Amy Tobey <atobey@equinix.com>

* disable skip_upload for now, to test

Signed-off-by: Amy Tobey <atobey@equinix.com>

* re-enable skip_upload

Test succeeded :)

equinix-labs/homebrew-otel-cli@5d44b32

Signed-off-by: Amy Tobey <atobey@equinix.com>

* mention brew tap & packages in the README

Signed-off-by: Amy Tobey <atobey@equinix.com>

Co-authored-by: Amy Tobey <atobey@equinix.com>
  • Loading branch information
ahayworth and Amy Tobey authored Aug 24, 2021
1 parent 673be1b commit 980a370
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
50 changes: 34 additions & 16 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
before:
hooks:
- go mod tidy

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: 'SNAPSHOT-{{ .Commit }}'

changelog:
sort: asc
filters:
exclude:
- '^demos:'
- '^configs:'
- Merge pull request
- Merge branch
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
Expand Down Expand Up @@ -51,19 +68,20 @@ archives:
386: i386
amd64: x86_64

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: 'SNAPSHOT-{{ .Commit }}'

changelog:
sort: asc
filters:
exclude:
- '^demos:'
- '^configs:'
- Merge pull request
- Merge branch
- go mod tidy

brews:
# This means the repository must be equinix-labs/homebrew-otel-cli
- name: "otel-cli"
url_template: "https://github.com/equinix-labs/otel-cli/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
tap:
owner: "equinix-labs"
name: "homebrew-otel-cli"
token: "{{ .Env.GITHUB_TOKEN }}"
commit_author:
name: "tobert"
email: "atobey@equinix.com"
homepage: "https://github.com/equinix-labs/otel-cli"
description: "OpenTelemetry command-line tool for sending events from shell scripts & similar environments"
license: "Apache-2.0"
# If set to auto, the release will not be uploaded to the homebrew tap
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
skip_upload: "auto"
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ program too much and you don't spam outbound connections on each command.

## Getting Started

The easiest way is a go get:
We publish a number of package formats for otel-cli, including tar.gz, zip (windows),
apk (Alpine), rpm (Red Hat variants), deb (Debian variants), and a brew tap. These
can be found on the repo's [Releases](https://github.com/equinix-labs/otel-cli/releases) page.

On most platforms the easiest way is a go get:

```shell
go get github.com/equinix-labs/otel-cli
```

To use the brew tap e.g. on MacOS:

```shell
brew tap equinix-labs/otel-cli
brew install otel-cli
```


Alternatively, clone the repo and build it locally:

```shell
Expand Down

0 comments on commit 980a370

Please sign in to comment.