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:
Bevan Kay
2022-05-10 15:41:44 +10:00
committed by GitHub
co-authored by Sam Ford
parent 07830c0f9c
commit e428eedace
+11 -2
View File
@@ -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?