mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
cmd/lib/ci_matrix: fix depends_on regex (#123093)
* fix regex * ci_matrix: rework `depends_on macos` array regex * ci_matrix: error on unhandled `depends_on macos` Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
This commit is contained in:
+11
-2
@@ -13,15 +13,24 @@ module CiMatrix
|
||||
{ symbol: :monterey, name: "macos-12" } => 0.1,
|
||||
}.freeze
|
||||
|
||||
# This string uses regex syntax and is intended to be interpolated into
|
||||
# `Regexp` literals, so the backslashes must be escaped to be preserved.
|
||||
DEPENDS_ON_MACOS_ARRAY_MEMBER = '\\s*"?:([^\\s",]+)"?,?\\s*'
|
||||
|
||||
def self.filter_runners(cask_content)
|
||||
# Retrieve arguments from `depends_on macos:`
|
||||
args = case cask_content
|
||||
when /depends_on macos: \[((.*,?\s*)*)\]/
|
||||
Regexp.last_match(1).scan(/\s*"?:([^\s",]+)"?,?\s*/).flatten.map(&:to_sym)
|
||||
when /depends_on macos: \[((?:#{DEPENDS_ON_MACOS_ARRAY_MEMBER})+)\]/o
|
||||
Regexp.last_match(1).scan(/#{DEPENDS_ON_MACOS_ARRAY_MEMBER}/o).flatten.map(&:to_sym)
|
||||
when /depends_on macos: "?:([^\s"]+)"?/
|
||||
[*Regexp.last_match(1).to_sym]
|
||||
when /depends_on macos: "([=<>]=\s:?\S+)"/
|
||||
[*Regexp.last_match(1)]
|
||||
when /depends_on macos:/
|
||||
# In this case, `depends_on macos:` is present but wasn't matched by the
|
||||
# previous regexes. We want this to visibly fail so we can address the
|
||||
# shortcoming instead of quietly defaulting to `RUNNERS`.
|
||||
odie "Unhandled `depends_on macos` argument"
|
||||
end
|
||||
return RUNNERS if args.nil?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user