Skip to content

cask: extract refresh_for_tag to tolerate asymmetric variations#22427

Merged
MikeMcQuaid merged 1 commit into
mainfrom
cask-variations-tolerate-asymmetric
May 29, 2026
Merged

cask: extract refresh_for_tag to tolerate asymmetric variations#22427
MikeMcQuaid merged 1 commit into
mainfrom
cask-variations-tolerate-asymmetric

Conversation

@p-linnane
Copy link
Copy Markdown
Member

@p-linnane p-linnane commented May 27, 2026

Cask#to_hash_with_variations iterates OnSystem::VALID_OS_ARCH_TAGS and refreshes the cask for each tag, but with no rescue. When a cask uses on_system blocks that legitimately omit some platforms — e.g.

on_linux do
  sha256 x86_64_linux: "..."
  depends_on arch: :x86_64
end

— the (linux, arm) iteration raised CaskInvalidError: invalid 'sha256' value: nil and aborted variation generation entirely. This broke generate-cask-ci-matrix on homebrew-cask PRs submitting such casks (e.g. Homebrew/homebrew-cask#266359).

Per review feedback, rather than repeating the rescue in each caller, this extracts a shared Cask::Cask#refresh_for_tag(tag, &block) helper that refreshes the cask for a simulated OS/arch tag and returns nil (instead of raising) when the cask intentionally omits that tag. It re-raises for casks without on_system blocks, since those failures aren't platform-specific.

All three existing callers of the pattern now use it:

  • Cask#to_hash_with_variations
  • dev-cmd/bump-cask-pr (loads the source cask once, then refreshes per tag)
  • dev-cmd/generate-cask-ci-matrix

The helper uses SimulateSystem.with (not with_tag) so it tolerates the invalid OS/arch combinations bump-cask-pr can generate on older macOS hosts, matching the previous behaviour.


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR.

AI (Claude Code) assisted with the implementation and this description. Added a fixture cask (on-linux-asymmetric) plus specs for #refresh_for_tag (supported tag yields; unsupported tag returns nil) and #to_hash_with_variations (omits the unsupported tag). Verified with brew lgtm and the cask, bump-cask-pr and generate-cask-ci-matrix specs.


Copilot AI review requested due to automatic review settings May 27, 2026 04:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Cask::Cask#to_hash_with_variations to tolerate casks that intentionally define only a subset of OS/arch combinations inside on_system blocks, by rescuing per-tag CaskInvalidError/CaskUnreadableError during simulated tag refresh and skipping unsupported combinations instead of aborting the whole variations computation.

Changes:

  • Wrap the per-OnSystem::VALID_OS_ARCH_TAGS SimulateSystem.with_tag + refresh + to_h comparison in a begin/rescue.
  • Skip tags that raise CaskInvalidError or CaskUnreadableError during per-tag refresh, allowing supported tags to still be collected into the variations hash.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/cask/cask.rb Outdated
@p-linnane p-linnane force-pushed the cask-variations-tolerate-asymmetric branch from 6db7465 to f01fb86 Compare May 27, 2026 04:16
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, code looks good!

Mirrors the existing rescue patterns in bump-cask-pr.rb and generate-cask-ci-matrix.rb.

Given it's 3 cases: I think this would ideally instead provide a shared API that can be used by all 3 callers (and look for other potential callers) so we don't have to keep adding this in new places over time.

@p-linnane p-linnane force-pushed the cask-variations-tolerate-asymmetric branch from f01fb86 to 8ce86ba Compare May 28, 2026 23:38
@p-linnane p-linnane changed the title cask: tolerate asymmetric variations in to_hash_with_variations cask: extract refresh_for_tag to tolerate asymmetric variations May 28, 2026
@p-linnane p-linnane requested a review from Copilot May 28, 2026 23:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Add `Cask::Cask#refresh_for_tag`, which refreshes a cask for a simulated
OS/arch tag and tolerates casks that intentionally omit some platforms
(e.g. an `on_linux` block defining only `x86_64_linux`). Use it from
`to_hash_with_variations`, `bump-cask-pr` and `generate-cask-ci-matrix`
instead of repeating the rescue in each caller.

Previously `to_hash_with_variations` raised `invalid 'sha256' value: nil`
for such casks, aborting variation generation entirely.

Signed-off-by: Patrick Linnane <patrick@linnane.io>
@p-linnane p-linnane force-pushed the cask-variations-tolerate-asymmetric branch from 8ce86ba to 339364a Compare May 28, 2026 23:56
@p-linnane p-linnane requested a review from MikeMcQuaid May 29, 2026 00:00
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 29, 2026
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 29, 2026
Merged via the queue into main with commit f6adf1a May 29, 2026
37 checks passed
@MikeMcQuaid MikeMcQuaid deleted the cask-variations-tolerate-asymmetric branch May 29, 2026 08:44
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.

3 participants