Skip to content

Commit d2dfbd5

Browse files
committed
feat: bump the homebrew-tap formula automatically after each release
New homebrew-tap-bump job, parallel to the container job (both need: [burrito-package]) - reads the just-published release's tag + SHA256SUMS, updates rubyists/homebrew-tap's Formula/linear-cli/linear-cli.rb url/sha256 for both platforms via ci/bump_homebrew_formula.rb, and opens a PR there via peter-evans/create-pull-request@v8 (no-op if nothing changed). Uses the RELEASE_PLEASE_TOKEN org secret to push/PR against a different repo than the one the workflow runs in - the default GITHUB_TOKEN is scoped only to this repo. The actual bump logic lives in ci/bump_homebrew_formula.rb rather than inline in the workflow YAML, so it's runnable/testable locally without a real CI run - verified directly against a real copy of the formula and real release checksums, confirmed idempotent, and re-verified after the tap repo's Formula/lc.rb -> Formula/linear-cli/linear-cli.rb move. Depends on rubyists/homebrew-tap#3 (submodule pointer bumped to that branch's tip - update again once it merges if the SHA changes from a squash-merge).
1 parent 2ebda29 commit d2dfbd5

3 files changed

Lines changed: 100 additions & 1 deletion

File tree

.github/workflows/main.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,54 @@ jobs:
350350
name: container-sbom
351351
path: container-sbom.cdx.json
352352
retention-days: 90
353+
354+
homebrew-tap-bump:
355+
needs: [burrito-package]
356+
name: Bump the Homebrew tap formula
357+
runs-on: ubuntu-latest
358+
steps:
359+
-
360+
name: Checkout linear-cli (for ci/bump_homebrew_formula.rb)
361+
uses: actions/checkout@v7
362+
with:
363+
path: linear-cli
364+
-
365+
# RELEASE_PLEASE_TOKEN (org secret) - the default GITHUB_TOKEN is
366+
# scoped only to this repo, and can't push/open a PR against a
367+
# different one.
368+
name: Checkout rubyists/homebrew-tap
369+
uses: actions/checkout@v7
370+
with:
371+
repository: rubyists/homebrew-tap
372+
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
373+
path: homebrew-tap
374+
-
375+
name: Download this release's SHA256SUMS
376+
env:
377+
GH_TOKEN: ${{ github.token }}
378+
run: |
379+
gh release download "${{ needs.burrito-package.outputs.tag_name }}" \
380+
--repo rubyists/linear-cli --pattern SHA256SUMS --output linear-cli/SHA256SUMS
381+
-
382+
name: Bump the formula's url/sha256 for each platform
383+
run: |
384+
ruby linear-cli/ci/bump_homebrew_formula.rb \
385+
homebrew-tap/Formula/linear-cli/linear-cli.rb \
386+
"${{ needs.burrito-package.outputs.tag_name }}" \
387+
linear-cli/SHA256SUMS
388+
-
389+
# No-op (no PR opened, nothing pushed) when there's nothing to
390+
# commit - same action/behavior already relied on in
391+
# usage-rules-sync.yaml.
392+
name: Open a PR bumping the formula, if anything changed
393+
uses: peter-evans/create-pull-request@v8
394+
with:
395+
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
396+
path: homebrew-tap
397+
commit-message: "fix: bump linear-cli formula to ${{ needs.burrito-package.outputs.tag_name }}"
398+
title: "fix: bump linear-cli formula to ${{ needs.burrito-package.outputs.tag_name }}"
399+
body: >-
400+
Auto-generated after rubyists/linear-cli's
401+
${{ needs.burrito-package.outputs.tag_name }} release.
402+
branch: "bump-formula-${{ needs.burrito-package.outputs.tag_name }}"
403+
delete-branch: true

ci/bump_homebrew_formula.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env ruby
2+
# Bumps a Homebrew formula's per-platform `url`/`sha256` pairs to a new
3+
# rubyists/linear-cli release - the `.github/workflows/main.yaml`
4+
# `homebrew-tap-bump` job's only real logic, kept out of the workflow YAML
5+
# so it's runnable/testable locally without a real CI run.
6+
#
7+
# Usage: bump_homebrew_formula.rb FORMULA_PATH TAG SHA256SUMS_PATH
8+
#
9+
# FORMULA_PATH path to the formula file (e.g. Formula/linear-cli/linear-cli.rb)
10+
# TAG the release tag, e.g. "v1.3.0"
11+
# SHA256SUMS_PATH that release's own SHA256SUMS asset, as downloaded
12+
13+
formula_path, tag, sha256sums_path = ARGV
14+
15+
unless formula_path && tag && sha256sums_path
16+
abort "Usage: #{$PROGRAM_NAME} FORMULA_PATH TAG SHA256SUMS_PATH"
17+
end
18+
19+
sha256sums =
20+
File.readlines(sha256sums_path).each_with_object({}) do |line, acc|
21+
sha, name = line.split(/\s+/, 2)
22+
acc[name.strip] = sha if name
23+
end
24+
25+
content = File.read(formula_path)
26+
27+
%w[macos_aarch64 linux_x86_64].each do |target|
28+
asset = "lc_#{target}.tar.gz"
29+
sha = sha256sums.fetch(asset) { abort "No checksum found for #{asset} in #{sha256sums_path}" }
30+
31+
pattern = /
32+
url\ "https:\/\/github\.com\/rubyists\/linear-cli\/releases\/download\/v[\d.]+\/#{Regexp.escape(asset)}"
33+
\n(\s*)
34+
sha256\ "[a-f0-9]+"
35+
/x
36+
37+
unless content.match?(pattern)
38+
abort "Could not find a url/sha256 pair for #{asset} in #{formula_path}"
39+
end
40+
41+
content = content.sub(pattern) do
42+
indent = ::Regexp.last_match(1)
43+
%(url "https://github.com/rubyists/linear-cli/releases/download/#{tag}/#{asset}"\n#{indent}sha256 "#{sha}")
44+
end
45+
end
46+
47+
File.write(formula_path, content)
48+
puts "Bumped #{formula_path} to #{tag}"

0 commit comments

Comments
 (0)