@@ -110,3 +110,172 @@ jobs:
110110 artifacts/SHA256SUMS
111111 body : ${{ steps.tag_message.outputs.has_body == 'true' && steps.tag_message.outputs.body || '' }}
112112 generate_release_notes : ${{ steps.tag_message.outputs.has_body != 'true' }}
113+
114+ update-homebrew :
115+ needs : release
116+ runs-on : ubuntu-latest
117+ steps :
118+ - uses : actions/download-artifact@v4
119+ with :
120+ path : artifacts
121+ merge-multiple : true
122+
123+ - name : Compute SHA256 for all binaries
124+ id : sha256
125+ run : |
126+ VERSION=${GITHUB_REF#refs/tags/v}
127+ echo "version=$VERSION" >> $GITHUB_OUTPUT
128+
129+ # Verify all expected artifacts exist
130+ for platform in darwin_amd64 darwin_arm64 linux_amd64 linux_arm64; do
131+ file="artifacts/roborev_${VERSION}_${platform}.tar.gz"
132+ if [ ! -f "$file" ]; then
133+ echo "ERROR: Missing artifact: $file"
134+ echo "Available artifacts:"
135+ ls -la artifacts/
136+ exit 1
137+ fi
138+ done
139+
140+ # macOS
141+ echo "darwin_amd64=$(sha256sum artifacts/roborev_${VERSION}_darwin_amd64.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
142+ echo "darwin_arm64=$(sha256sum artifacts/roborev_${VERSION}_darwin_arm64.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
143+
144+ # Linux
145+ echo "linux_amd64=$(sha256sum artifacts/roborev_${VERSION}_linux_amd64.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
146+ echo "linux_arm64=$(sha256sum artifacts/roborev_${VERSION}_linux_arm64.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
147+
148+ - name : Checkout tap repository
149+ uses : actions/checkout@v4
150+ with :
151+ repository : roborev-dev/homebrew-tap
152+ token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
153+ path : homebrew-tap
154+
155+ - name : Update formula
156+ env :
157+ VERSION : ${{ steps.sha256.outputs.version }}
158+ DARWIN_AMD64_SHA : ${{ steps.sha256.outputs.darwin_amd64 }}
159+ DARWIN_ARM64_SHA : ${{ steps.sha256.outputs.darwin_arm64 }}
160+ LINUX_AMD64_SHA : ${{ steps.sha256.outputs.linux_amd64 }}
161+ LINUX_ARM64_SHA : ${{ steps.sha256.outputs.linux_arm64 }}
162+ run : |
163+ cd homebrew-tap
164+
165+ # Use Ruby to update the formula (more robust than sed for nested blocks)
166+ ruby -i -e '
167+ content = File.read("Formula/roborev.rb")
168+
169+ # Update version
170+ content.gsub!(/version "[^"]*"/, %Q{version "#{ENV["VERSION"]}"})
171+
172+ # Track block depth for proper nesting
173+ # Formula structure: on_macos do / on_linux do > if Hardware::CPU.intel?/arm? > sha256
174+ macos_depth = 0
175+ linux_depth = 0
176+ in_intel = false
177+ in_arm = false
178+ updated = { darwin_amd64: false, darwin_arm64: false, linux_amd64: false, linux_arm64: false }
179+
180+ lines = content.lines.map do |line|
181+ stripped = line.strip
182+
183+ # Track on_macos/on_linux blocks by depth
184+ if line.include?("on_macos do")
185+ macos_depth = 1
186+ elsif line.include?("on_linux do")
187+ linux_depth = 1
188+ end
189+
190+ # Track CPU architecture blocks
191+ if line.include?("Hardware::CPU.intel?")
192+ in_intel = true
193+ elsif line.include?("Hardware::CPU.arm?")
194+ in_arm = true
195+ end
196+
197+ # Update sha256 based on current context
198+ if line.include?("sha256") && line.include?("\"")
199+ if macos_depth > 0 && in_intel
200+ line = line.gsub(/sha256 "[^"]*"/, %Q{sha256 "#{ENV["DARWIN_AMD64_SHA"]}"})
201+ updated[:darwin_amd64] = true
202+ elsif macos_depth > 0 && in_arm
203+ line = line.gsub(/sha256 "[^"]*"/, %Q{sha256 "#{ENV["DARWIN_ARM64_SHA"]}"})
204+ updated[:darwin_arm64] = true
205+ elsif linux_depth > 0 && in_intel
206+ line = line.gsub(/sha256 "[^"]*"/, %Q{sha256 "#{ENV["LINUX_AMD64_SHA"]}"})
207+ updated[:linux_amd64] = true
208+ elsif linux_depth > 0 && in_arm
209+ line = line.gsub(/sha256 "[^"]*"/, %Q{sha256 "#{ENV["LINUX_ARM64_SHA"]}"})
210+ updated[:linux_arm64] = true
211+ end
212+ end
213+
214+ # Track end statements - reset CPU flags on end, decrement block depth
215+ if stripped == "end"
216+ if in_intel
217+ in_intel = false
218+ elsif in_arm
219+ in_arm = false
220+ elsif macos_depth > 0
221+ macos_depth = 0
222+ elsif linux_depth > 0
223+ linux_depth = 0
224+ end
225+ end
226+
227+ line
228+ end
229+
230+ # Verify all checksums were updated
231+ missing = updated.select { |k, v| !v }.keys
232+ unless missing.empty?
233+ STDERR.puts "ERROR: Failed to update sha256 for: #{missing.join(", ")}"
234+ exit 1
235+ end
236+
237+ File.write("Formula/roborev.rb", lines.join)
238+ puts "Successfully updated formula to v#{ENV["VERSION"]}"
239+ ' Formula/roborev.rb
240+
241+ echo "--- Updated formula ---"
242+ cat Formula/roborev.rb
243+
244+ - name : Verify checksums in formula
245+ env :
246+ DARWIN_AMD64_SHA : ${{ steps.sha256.outputs.darwin_amd64 }}
247+ DARWIN_ARM64_SHA : ${{ steps.sha256.outputs.darwin_arm64 }}
248+ LINUX_AMD64_SHA : ${{ steps.sha256.outputs.linux_amd64 }}
249+ LINUX_ARM64_SHA : ${{ steps.sha256.outputs.linux_arm64 }}
250+ run : |
251+ cd homebrew-tap
252+ ERRORS=0
253+
254+ for sha in "$DARWIN_AMD64_SHA" "$DARWIN_ARM64_SHA" "$LINUX_AMD64_SHA" "$LINUX_ARM64_SHA"; do
255+ if ! grep -q "sha256 \"$sha\"" Formula/roborev.rb; then
256+ echo "ERROR: sha256 $sha not found in formula"
257+ ERRORS=$((ERRORS + 1))
258+ fi
259+ done
260+
261+ if [ $ERRORS -gt 0 ]; then
262+ echo "Checksum verification failed"
263+ exit 1
264+ fi
265+ echo "All checksums verified"
266+
267+ - name : Commit and push
268+ run : |
269+ cd homebrew-tap
270+ git config user.name "github-actions[bot]"
271+ git config user.email "github-actions[bot]@users.noreply.github.com"
272+
273+ # Check if there are changes to commit (handles re-runs)
274+ if git diff --quiet Formula/roborev.rb; then
275+ echo "No changes to formula, skipping commit"
276+ exit 0
277+ fi
278+
279+ git add Formula/roborev.rb
280+ git commit -m "Update roborev to v${{ steps.sha256.outputs.version }}"
281+ git push
0 commit comments