mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
Fix CI matrix. (#143773)
This commit is contained in:
+32
-26
@@ -18,36 +18,40 @@ module CiMatrix
|
||||
|
||||
def self.filter_runners(cask_content)
|
||||
# Retrieve arguments from `depends_on macos:`
|
||||
args = case cask_content
|
||||
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)]
|
||||
required_macos = case cask_content
|
||||
when /depends_on macos:\s+\[((?:#{DEPENDS_ON_MACOS_ARRAY_MEMBER})+)\]/o
|
||||
Regexp.last_match(1).scan(/#{DEPENDS_ON_MACOS_ARRAY_MEMBER}/o).flatten.map(&:to_sym).map do |v|
|
||||
{
|
||||
version: v,
|
||||
comparator: "==",
|
||||
}
|
||||
end
|
||||
when /depends_on macos:\s+"?:([^\s"]+)"?/ # e.g. `depends_on macos: :big_sur`
|
||||
[
|
||||
{
|
||||
version: Regexp.last_match(1).to_sym,
|
||||
comparator: "==",
|
||||
},
|
||||
]
|
||||
when /depends_on macos:\s+"([=<>]=)\s+:([^\s"]+)"/ # e.g. `depends_on macos: ">= :monterey"`
|
||||
[
|
||||
{
|
||||
version: Regexp.last_match(2).to_sym,
|
||||
comparator: 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?
|
||||
|
||||
# Preform same checks as `brew install` would
|
||||
required_macos = if args.count > 1
|
||||
{ versions: args, comparator: "==" }
|
||||
elsif MacOSVersions::SYMBOLS.key?(args.first)
|
||||
{ versions: [args.first], comparator: "==" }
|
||||
elsif /^\s*(?<comparator><|>|[=<>]=)\s*:?(?<version>\S+)\s*$/ =~ args.first
|
||||
{ versions: [version.to_sym], comparator: comparator }
|
||||
else # rubocop:disable Lint/DuplicateBranch
|
||||
{ versions: [args.first], comparator: "==" }
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
# Filter
|
||||
filtered_runners = RUNNERS.select do |runner, _|
|
||||
required_macos[:versions].any? do |v|
|
||||
MacOS::Version.from_symbol(runner[:symbol]).public_send(required_macos[:comparator], v)
|
||||
required_macos.any? do |r|
|
||||
MacOS::Version.from_symbol(runner.fetch(:symbol)).public_send(r.fetch(:comparator), r.fetch(:version))
|
||||
end
|
||||
end
|
||||
return filtered_runners unless filtered_runners.empty?
|
||||
@@ -56,8 +60,7 @@ module CiMatrix
|
||||
end
|
||||
|
||||
def self.random_runner(avalible_runners = RUNNERS)
|
||||
avalible_runners.reject { |_, weight| weight.zero? }
|
||||
.max_by { |(_, weight)| rand ** (1.0 / weight) }
|
||||
avalible_runners.max_by { |(_, weight)| rand ** (1.0 / weight) }
|
||||
.first
|
||||
end
|
||||
|
||||
@@ -67,9 +70,12 @@ module CiMatrix
|
||||
|
||||
macos_version_found = cask_content.match?(/\bMacOS\s*\.version\b/m)
|
||||
filtered_macos_found = filtered_runners.keys.any? do |runner|
|
||||
(macos_version_found && cask_content.include?(runner[:symbol].inspect)) ||
|
||||
cask_content.include?("on_#{runner[:symbol]}")
|
||||
(
|
||||
macos_version_found &&
|
||||
cask_content.include?(runner[:symbol].inspect)
|
||||
) || cask_content.include?("on_#{runner[:symbol]}")
|
||||
end
|
||||
|
||||
if filtered_macos_found
|
||||
# If the cask varies on a MacOS version, test it on every possible macOS version.
|
||||
filtered_runners.keys
|
||||
|
||||
Reference in New Issue
Block a user