Skip to content

fix: generate brew style-compliant cask in homebrew-tap workflow#2898

Merged
markphelps merged 1 commit intomainfrom
fix/homebrew-tap-brew-style
Apr 1, 2026
Merged

fix: generate brew style-compliant cask in homebrew-tap workflow#2898
markphelps merged 1 commit intomainfrom
fix/homebrew-tap-brew-style

Conversation

@markphelps
Copy link
Copy Markdown
Contributor

@markphelps markphelps commented Mar 31, 2026

Summary

  • Fix the homebrew-tap workflow to generate a cask file that passes brew style checks without manual intervention
  • Previously required running brew style --fix manually on the PR (e.g. replicate/homebrew-tap@0394f59)

Changes

Style violations fixed (from brew style --fix)

Issue Before After
Arch block order on_intel before on_arm on_arm before on_intel (alphabetical)
Field order in arch blocks url before sha256 sha256 before url (with blank line between)
Homepage URL https://cog.run https://cog.run/ (trailing slash required)
Binary arch selection Hardware::CPU.intel? ternary on_intel/on_arm block syntax with proper alignment
args: alignment in postflight Indented ~8 spaces Aligned to system_command call column

Audit violations fixed (from brew audit)

Issue Fix
"Use sha256 :no_check when URL is unversioned" URLs now use Ruby #{version} interpolation so Homebrew recognizes them as versioned
"URL domain does not match homepage domain" Added verified: "github.com/replicate/cog/" parameter to url stanzas

Note: The "cask token conflicts with homebrew/core formula" warning is expected and intentional — both the formula and cask are the same project (cog).

Template approach

Switched from a shell-expanded heredoc with indentation stripping to a quoted heredoc (<<'CASK') with explicit sed variable substitution. This is more robust and keeps the template visually matching the final output.

Testing

Simulated the generation locally and verified the output matches brew style expectations.

@markphelps markphelps requested a review from a team as a code owner March 31, 2026 21:00
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 31, 2026

Thanks for fixing the brew style compliance issues. The switch to quoted heredoc with explicit sed substitution is a good maintainability improvement.

One minor suggestion: Consider adding shell escaping to the sed substitution for better robustness against special characters:

# Substitute shell variables into the generated cask
sed -i "s|\\${VERSION}|${VERSION}|g" cog.rb
sed -i "s|\\${SHA_ARM}|${SHA_ARM}|g" cog.rb
sed -i "s|\\${SHA_X86}|${SHA_X86}|g" cog.rb
sed -i "s|\\${BASE_URL}|${BASE_URL//\\/\\\\/}|g" cog.rb

The additional escaping ensures the literal ${VAR} pattern is matched even if shell expansion occurs unexpectedly. The BASE_URL escaping handles forward slashes in URLs more safely. However, this is optional since the inputs are controlled in this workflow context.

@markphelps markphelps force-pushed the fix/homebrew-tap-brew-style branch from dd829cb to cdaa8a2 Compare March 31, 2026 21:03
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 31, 2026

Posted a suggestion about improving the sed variable substitution robustness. The current implementation is functional since inputs are controlled, but the escaping would make it more defensive against edge cases. Otherwise LGTM - the changes properly address all five brew style compliance issues mentioned in the PR description.

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 31, 2026

I'm Bonk, and I've done a quick review of your PR.

This PR fixes the Homebrew cask generation workflow to comply with brew style and brew audit checks, eliminating the need for manual fixes on generated PRs.

The changes properly address all the style and audit issues mentioned. The switch to a quoted heredoc with explicit sed substitution is a clean approach that makes the template readable while avoiding shell expansion issues.

One small suggestion for additional robustness:

# Substitute shell variables into the generated cask.
# Only version and sha256 need substitution — URLs use Ruby #{version}
# interpolation which Homebrew evaluates at install time.
sed -i "s|\\\${VERSION}|${VERSION}|g" cog.rb
sed -i "s|\\\${SHA_ARM}|${SHA_ARM}|g" cog.rb
sed -i "s|\\\${SHA_X86}|${SHA_X86}|g" cog.rb

The extra backslash ensures the literal ${VAR} pattern is matched even in edge cases. However, since the inputs are controlled (validated tag format and extracted checksums), the current implementation is functionally correct.

LGTM

github run

@markphelps markphelps merged commit 482b4ac into main Apr 1, 2026
41 checks passed
@markphelps markphelps deleted the fix/homebrew-tap-brew-style branch April 1, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants