cask: extract refresh_for_tag to tolerate asymmetric variations#22427
Conversation
There was a problem hiding this comment.
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_TAGSSimulateSystem.with_tag+refresh+to_hcomparison in abegin/rescue. - Skip tags that raise
CaskInvalidErrororCaskUnreadableErrorduring 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.
6db7465 to
f01fb86
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, code looks good!
Mirrors the existing rescue patterns in
bump-cask-pr.rbandgenerate-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.
f01fb86 to
8ce86ba
Compare
refresh_for_tag to tolerate asymmetric variations
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>
8ce86ba to
339364a
Compare
Cask#to_hash_with_variationsiteratesOnSystem::VALID_OS_ARCH_TAGSand refreshes the cask for each tag, but with no rescue. When a cask useson_systemblocks that legitimately omit some platforms — e.g.— the
(linux, arm)iteration raisedCaskInvalidError: invalid 'sha256' value: niland aborted variation generation entirely. This brokegenerate-cask-ci-matrixonhomebrew-caskPRs 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 returnsnil(instead of raising) when the cask intentionally omits that tag. It re-raises for casks withouton_systemblocks, since those failures aren't platform-specific.All three existing callers of the pattern now use it:
Cask#to_hash_with_variationsdev-cmd/bump-cask-pr(loads the source cask once, then refreshes per tag)dev-cmd/generate-cask-ci-matrixThe helper uses
SimulateSystem.with(notwith_tag) so it tolerates the invalid OS/arch combinationsbump-cask-prcan generate on older macOS hosts, matching the previous behaviour.brew lgtm(style, typechecking and tests) with your changes locally?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 returnsnil) and#to_hash_with_variations(omits the unsupported tag). Verified withbrew lgtmand thecask,bump-cask-prandgenerate-cask-ci-matrixspecs.