From 6a1f1d4049f626c1ee03c4130fcf63f71b06760b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Mar 2023 03:46:11 +0200 Subject: [PATCH] Fix CI matrix. (#143773) --- cmd/lib/ci_matrix.rb | 58 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/cmd/lib/ci_matrix.rb b/cmd/lib/ci_matrix.rb index 86cf8fed0d..cd32932a36 100644 --- a/cmd/lib/ci_matrix.rb +++ b/cmd/lib/ci_matrix.rb @@ -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*(?<|>|[=<>]=)\s*:?(?\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