diff --git a/cmd/lib/ci_matrix.rb b/cmd/lib/ci_matrix.rb index e5f43fb619..14076639c7 100644 --- a/cmd/lib/ci_matrix.rb +++ b/cmd/lib/ci_matrix.rb @@ -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?