Skip to content

Commit 3e6e7d4

Browse files
committed
Move Homebrew formula publishing from GoReleaser to GitHub Actions
Replaces the built-in GoReleaser brew configuration with a custom workflow job. This uses a template to explicitly handle multiple architectures and platforms, rendering the final formula with checksums fetched from the release before pushing to the homebrew-tap repository.
1 parent 37afecd commit 3e6e7d4

3 files changed

Lines changed: 104 additions & 18 deletions

File tree

.github/homebrew/ai.rb.tmpl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Ai < Formula
2+
desc "AI shell assistant — turn natural language into shell commands"
3+
homepage "https://github.com/hra42/ai"
4+
version "__VERSION__"
5+
license "Unlicense"
6+
7+
on_macos do
8+
on_arm do
9+
url "https://github.com/hra42/ai/releases/download/v__VERSION__/ai_darwin_arm64.tar.gz"
10+
sha256 "__SHA_DARWIN_ARM64__"
11+
end
12+
on_intel do
13+
url "https://github.com/hra42/ai/releases/download/v__VERSION__/ai_darwin_amd64.tar.gz"
14+
sha256 "__SHA_DARWIN_AMD64__"
15+
end
16+
end
17+
18+
on_linux do
19+
on_arm do
20+
url "https://github.com/hra42/ai/releases/download/v__VERSION__/ai_linux_arm64.tar.gz"
21+
sha256 "__SHA_LINUX_ARM64__"
22+
end
23+
on_intel do
24+
url "https://github.com/hra42/ai/releases/download/v__VERSION__/ai_linux_amd64.tar.gz"
25+
sha256 "__SHA_LINUX_AMD64__"
26+
end
27+
end
28+
29+
def install
30+
bin.install "ai"
31+
end
32+
33+
test do
34+
assert_match version.to_s, shell_output("#{bin}/ai --version")
35+
end
36+
end

.github/workflows/release.yml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,67 @@ jobs:
3030
args: release --clean
3131
env:
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
33+
34+
homebrew:
35+
needs: goreleaser
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v6
40+
41+
- name: Render and push formula
42+
env:
43+
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
44+
TAG: ${{ github.ref_name }}
45+
run: |
46+
set -euo pipefail
47+
48+
version="${TAG#v}"
49+
release_url="https://github.com/hra42/ai/releases/download/${TAG}"
50+
51+
# Download the release's checksums.txt and pull the four SHAs we need.
52+
curl -fsSL "${release_url}/checksums.txt" -o checksums.txt
53+
sha_for() {
54+
grep " $1\$" checksums.txt | awk '{print $1}' | head -n1
55+
}
56+
sha_darwin_arm64=$(sha_for ai_darwin_arm64.tar.gz)
57+
sha_darwin_amd64=$(sha_for ai_darwin_amd64.tar.gz)
58+
sha_linux_arm64=$(sha_for ai_linux_arm64.tar.gz)
59+
sha_linux_amd64=$(sha_for ai_linux_amd64.tar.gz)
60+
61+
for s in "$sha_darwin_arm64" "$sha_darwin_amd64" "$sha_linux_arm64" "$sha_linux_amd64"; do
62+
if [ -z "$s" ]; then
63+
echo "missing sha in checksums.txt" >&2
64+
cat checksums.txt >&2
65+
exit 1
66+
fi
67+
done
68+
69+
# Render the template.
70+
mkdir -p out/Formula
71+
sed \
72+
-e "s|__VERSION__|${version}|g" \
73+
-e "s|__SHA_DARWIN_ARM64__|${sha_darwin_arm64}|g" \
74+
-e "s|__SHA_DARWIN_AMD64__|${sha_darwin_amd64}|g" \
75+
-e "s|__SHA_LINUX_ARM64__|${sha_linux_arm64}|g" \
76+
-e "s|__SHA_LINUX_AMD64__|${sha_linux_amd64}|g" \
77+
.github/homebrew/ai.rb.tmpl > out/Formula/ai.rb
78+
79+
echo "::group::Rendered Formula/ai.rb"
80+
cat out/Formula/ai.rb
81+
echo "::endgroup::"
82+
83+
# Push to the tap repo.
84+
git config --global user.name "goreleaserbot"
85+
git config --global user.email "bot@goreleaser.com"
86+
git clone "https://x-access-token:${GH_TOKEN}@github.com/hra42/homebrew-tap.git" tap
87+
mkdir -p tap/Formula
88+
cp out/Formula/ai.rb tap/Formula/ai.rb
89+
cd tap
90+
git add Formula/ai.rb
91+
if git diff --cached --quiet; then
92+
echo "Formula unchanged — nothing to commit."
93+
exit 0
94+
fi
95+
git commit -m "ai ${version}"
96+
git push origin HEAD

.goreleaser.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,7 @@ release:
5757
extra_files:
5858
- glob: scripts/install.sh
5959

60-
brews:
61-
- name: ai
62-
repository:
63-
owner: hra42
64-
name: homebrew-tap
65-
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
66-
directory: Formula
67-
homepage: https://github.com/hra42/ai
68-
description: "AI shell assistant — turn natural language into shell commands"
69-
license: Unlicense
70-
commit_author:
71-
name: goreleaserbot
72-
email: bot@goreleaser.com
73-
install: |
74-
bin.install "ai"
75-
test: |
76-
system "#{bin}/ai", "--version"
60+
# Homebrew formula publishing is handled outside GoReleaser by the
61+
# `homebrew` job in .github/workflows/release.yml — it renders
62+
# .github/homebrew/ai.rb.tmpl with the version + sha256s from this
63+
# release and pushes Formula/ai.rb into hra42/homebrew-tap.

0 commit comments

Comments
 (0)