Skip to content

Commit f13baef

Browse files
committed
fix: write .version directly instead of hardcoding the version in urls
ci/bump_homebrew_formula.rb now writes Formula/linear-cli/.version to the release tag directly (the formula's own single source of truth, per rubyists/homebrew-tap's matching change) instead of rewriting a literal version number inside each url - the url lines are now a constant `v#{version}/<asset>` in the formula's own source, so only the sha256 that follows each one actually needs updating per release. Verified against a real copy of the formula: correct .version/sha256 output, url lines left untouched, idempotent on a repeated run with the same inputs, and the resulting formula evaluates to the correct version/url/sha256 via a small Homebrew-Formula-DSL stub. Also bumps the vendor/rubyists-homebrew-tap submodule pointer to the merged fix (rubyists/homebrew-tap#6).
1 parent d13ddf4 commit f13baef

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

ci/bump_homebrew_formula.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#!/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.
2+
# Bumps a Homebrew formula to a new rubyists/linear-cli release: writes
3+
# `.version` (the formula's own single source of truth - it interpolates
4+
# `#{version}` into each `url` itself, see the formula file, so the url
5+
# lines never need touching here) and updates each platform's `sha256`.
6+
# The `.github/workflows/main.yaml` `homebrew-tap-bump` job's only real
7+
# logic, kept out of the workflow YAML so it's runnable/testable locally
8+
# without a real CI run.
69
#
710
# Usage: bump_homebrew_formula.rb FORMULA_PATH TAG SHA256SUMS_PATH
811
#
912
# 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"
13+
# TAG the release tag, e.g. "v1.4.0"
1114
# SHA256SUMS_PATH that release's own SHA256SUMS asset, as downloaded
1215

1316
formula_path, tag, sha256sums_path = ARGV
@@ -22,27 +25,30 @@
2225
acc[name.strip] = sha if name
2326
end
2427

28+
version = tag.delete_prefix("v")
29+
version_file = File.join(File.dirname(formula_path), ".version")
30+
File.write(version_file, "#{version}\n")
31+
2532
content = File.read(formula_path)
2633

2734
%w[macos_aarch64 linux_x86_64].each do |target|
2835
asset = "lc_#{target}.tar.gz"
2936
sha = sha256sums.fetch(asset) { abort "No checksum found for #{asset} in #{sha256sums_path}" }
3037

38+
# The url line is a constant - it always reads v#{version}/<asset>
39+
# verbatim in the formula's own source, never a literal version - only
40+
# the sha256 that follows it actually changes per release.
3141
pattern = /
32-
url\ "https:\/\/github\.com\/rubyists\/linear-cli\/releases\/download\/v[\d.]+\/#{Regexp.escape(asset)}"
33-
\n(\s*)
34-
sha256\ "[a-f0-9]+"
42+
(url\ "https:\/\/github\.com\/rubyists\/linear-cli\/releases\/download\/v\#\{version\}\/#{Regexp.escape(asset)}"
43+
\n\s*sha256\ ")[a-f0-9]+(")
3544
/x
3645

3746
unless content.match?(pattern)
3847
abort "Could not find a url/sha256 pair for #{asset} in #{formula_path}"
3948
end
4049

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
50+
content = content.sub(pattern, "\\1#{sha}\\2")
4551
end
4652

4753
File.write(formula_path, content)
48-
puts "Bumped #{formula_path} to #{tag}"
54+
puts "Wrote #{version_file} (#{version}) and updated #{formula_path}'s sha256 pairs to match"

0 commit comments

Comments
 (0)