From 3baacbbc727c62e2ceac11e334f6069f1c13d82a Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:42:36 +0800 Subject: [PATCH 1/7] github_runner_matrix: set `timeout` on macOS This will allow us to set a slightly longer timeout on Intel Big Sur, which is useful because the Intel Big Sur runner often exceeds our short time limit by itself. --- Library/Homebrew/github_runner_matrix.rb | 12 ++++++++++-- Library/Homebrew/macos_runner_spec.rb | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/github_runner_matrix.rb b/Library/Homebrew/github_runner_matrix.rb index 632c3b3c64..a5a61496ed 100644 --- a/Library/Homebrew/github_runner_matrix.rb +++ b/Library/Homebrew/github_runner_matrix.rb @@ -15,7 +15,7 @@ class GitHubRunnerMatrix RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) } private_constant :RunnerSpec - MacOSRunnerSpecHash = T.type_alias { { name: String, runner: String, cleanup: T::Boolean } } + MacOSRunnerSpecHash = T.type_alias { { name: String, runner: String, timeout: Integer, cleanup: T::Boolean } } private_constant :MacOSRunnerSpecHash LinuxRunnerSpecHash = T.type_alias do @@ -110,6 +110,7 @@ class GitHubRunnerMatrix github_run_id = ENV.fetch("GITHUB_RUN_ID") github_run_attempt = ENV.fetch("GITHUB_RUN_ATTEMPT") + timeout = ENV.fetch("HOMEBREW_MACOS_TIMEOUT").to_i ephemeral_suffix = +"-#{github_run_id}-#{github_run_attempt}" ephemeral_suffix << "-deps" if @dependent_matrix ephemeral_suffix.freeze @@ -118,9 +119,16 @@ class GitHubRunnerMatrix macos_version = OS::Mac::Version.new(version) next if macos_version.unsupported_release? + # Intel Big Sur is a bit slower than the other runners, + # so give it a little bit more time. The comparison below + # should be `==`, but it returns typecheck errors. + runner_timeout = timeout + runner_timeout += 30 if macos_version <= :big_sur + spec = MacOSRunnerSpec.new( name: "macOS #{version}-x86_64", runner: "#{version}#{ephemeral_suffix}", + timeout: runner_timeout, cleanup: false, ) @runners << create_runner(:macos, :x86_64, spec, macos_version) @@ -136,7 +144,7 @@ class GitHubRunnerMatrix ["#{version}-arm64", true] end - spec = MacOSRunnerSpec.new(name: "macOS #{version}-arm64", runner: runner, cleanup: cleanup) + spec = MacOSRunnerSpec.new(name: "macOS #{version}-arm64", runner: runner, timeout: timeout, cleanup: cleanup) @runners << create_runner(:macos, :arm64, spec, macos_version) end diff --git a/Library/Homebrew/macos_runner_spec.rb b/Library/Homebrew/macos_runner_spec.rb index eb3b5ff6c4..3107de1637 100644 --- a/Library/Homebrew/macos_runner_spec.rb +++ b/Library/Homebrew/macos_runner_spec.rb @@ -6,13 +6,15 @@ class MacOSRunnerSpec < T::Struct const :name, String const :runner, String + const :timeout, Integer const :cleanup, T::Boolean - sig { returns({ name: String, runner: String, cleanup: T::Boolean }) } + sig { returns({ name: String, runner: String, timeout: Integer, cleanup: T::Boolean }) } def to_h { name: name, runner: runner, + timeout: timeout, cleanup: cleanup, } end From 97655276b2d71eb5608354249f15a60a184b6298 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:54:44 +0800 Subject: [PATCH 2/7] github_runner_matrix: simplify --- Library/Homebrew/github_runner_matrix.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/github_runner_matrix.rb b/Library/Homebrew/github_runner_matrix.rb index a5a61496ed..75b8af43b5 100644 --- a/Library/Homebrew/github_runner_matrix.rb +++ b/Library/Homebrew/github_runner_matrix.rb @@ -136,8 +136,7 @@ class GitHubRunnerMatrix next unless macos_version >= :big_sur # Use bare metal runner when testing dependents on ARM64 Monterey. - use_ephemeral = (macos_version >= :ventura && @dependent_matrix) || - (macos_version >= :monterey && !@dependent_matrix) + use_ephemeral = macos_version >= (@dependent_matrix ? :ventura : :monterey) runner, cleanup = if use_ephemeral ["#{version}-arm64#{ephemeral_suffix}", false] else @@ -164,9 +163,12 @@ class GitHubRunnerMatrix arch = runner.arch macos_version = runner.macos_version - compatible_formulae.select! { |formula| formula.public_send(:"#{platform}_compatible?") } - compatible_formulae.select! { |formula| formula.public_send(:"#{arch}_compatible?") } - compatible_formulae.select! { |formula| formula.compatible_with?(macos_version) } if macos_version + compatible_formulae.select! do |formula| + next false if macos_version && !formula.compatible_with?(macos_version) + + formula.public_send(:"#{platform}_compatible?") && + formula.public_send(:"#{arch}_compatible?") + end compatible_formulae.present? end @@ -188,9 +190,12 @@ class GitHubRunnerMatrix compatible_dependents = formula.dependents(platform: platform, arch: arch, macos_version: macos_version&.to_sym) .dup - compatible_dependents.select! { |dependent_f| dependent_f.public_send(:"#{platform}_compatible?") } - compatible_dependents.select! { |dependent_f| dependent_f.public_send(:"#{arch}_compatible?") } - compatible_dependents.select! { |dependent_f| dependent_f.compatible_with?(macos_version) } if macos_version + compatible_dependents.select! do |dependent_f| + next false if macos_version && !dependent_f.compatible_with?(macos_version) + + dependent_f.public_send(:"#{platform}_compatible?") && + dependent_f.public_send(:"#{arch}_compatible?") + end # These arrays will generally have been generated by different Formulary caches, # so we can only compare them by name and not directly. From 1bcabbfa575c47e3687b90f24608dc4455a8ff4f Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:59:08 +0800 Subject: [PATCH 3/7] test_runner_formula: fix caching --- Library/Homebrew/test_runner_formula.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test_runner_formula.rb b/Library/Homebrew/test_runner_formula.rb index b3e2dded65..2fd0e6b8f4 100644 --- a/Library/Homebrew/test_runner_formula.rb +++ b/Library/Homebrew/test_runner_formula.rb @@ -91,7 +91,7 @@ class TestRunnerFormula def dependents(platform:, arch:, macos_version:) cache_key = :"#{platform}_#{arch}_#{macos_version}" - @dependent_hash.fetch(cache_key) do + @dependent_hash[cache_key] ||= begin all = eval_all || Homebrew::EnvConfig.eval_all? formula_selector, eval_all_env = if all [:all, "1"] @@ -112,5 +112,7 @@ class TestRunnerFormula Homebrew::SimulateSystem.clear end end + + @dependent_hash.fetch(cache_key) end end From 2568e5aec42e3eadfe8d3cae3cb73a5a22f83861 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:09:20 +0800 Subject: [PATCH 4/7] github_runner_matrix: fix test --- Library/Homebrew/test/github_runner_matrix_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/test/github_runner_matrix_spec.rb b/Library/Homebrew/test/github_runner_matrix_spec.rb index 5c7881fe54..92201d3693 100644 --- a/Library/Homebrew/test/github_runner_matrix_spec.rb +++ b/Library/Homebrew/test/github_runner_matrix_spec.rb @@ -7,6 +7,7 @@ describe GitHubRunnerMatrix do before do allow(ENV).to receive(:fetch).with("HOMEBREW_LINUX_RUNNER").and_return("ubuntu-latest") allow(ENV).to receive(:fetch).with("HOMEBREW_LINUX_CLEANUP").and_return("false") + allow(ENV).to receive(:fetch).with("HOMEBREW_MACOS_TIMEOUT").and_return("90") allow(ENV).to receive(:fetch).with("GITHUB_RUN_ID").and_return("12345") allow(ENV).to receive(:fetch).with("GITHUB_RUN_ATTEMPT").and_return("1") end From 1a86a91c1bd886f182191a73fce78ae0b98c118f Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:41:33 +0800 Subject: [PATCH 5/7] determine-test-runners: fix test --- Library/Homebrew/test/dev-cmd/determine-test-runners_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/test/dev-cmd/determine-test-runners_spec.rb b/Library/Homebrew/test/dev-cmd/determine-test-runners_spec.rb index 7405fdaa40..c593d3cd0a 100644 --- a/Library/Homebrew/test/dev-cmd/determine-test-runners_spec.rb +++ b/Library/Homebrew/test/dev-cmd/determine-test-runners_spec.rb @@ -16,6 +16,7 @@ describe "brew determine-test-runners" do { "HOMEBREW_LINUX_RUNNER" => linux_runner, "HOMEBREW_LINUX_CLEANUP" => "false", + "HOMEBREW_MACOS_TIMEOUT" => "90", "GITHUB_RUN_ID" => ephemeral_suffix.split("-").second, "GITHUB_RUN_ATTEMPT" => ephemeral_suffix.split("-").third, }.freeze From 0c21ad20cd06024547c0696ba7af565998754190 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:05:05 +0800 Subject: [PATCH 6/7] macos_runner_spec: fix test --- Library/Homebrew/test/macos_runner_spec_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/macos_runner_spec_spec.rb b/Library/Homebrew/test/macos_runner_spec_spec.rb index 381bde96d8..e0711b1909 100644 --- a/Library/Homebrew/test/macos_runner_spec_spec.rb +++ b/Library/Homebrew/test/macos_runner_spec_spec.rb @@ -3,10 +3,10 @@ require "macos_runner_spec" describe MacOSRunnerSpec do - let(:spec) { described_class.new(name: "macOS 11-arm64", runner: "11-arm64", cleanup: true) } + let(:spec) { described_class.new(name: "macOS 11-arm64", runner: "11-arm64", timeout: 90, cleanup: true) } it "has immutable attributes" do - [:name, :runner, :cleanup].each do |attribute| + [:name, :runner, :timeout, :cleanup].each do |attribute| expect(spec.respond_to?("#{attribute}=")).to be(false) end end From f3ff42f9c59410ddff6c8910f3fa902add524e47 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:06:17 +0800 Subject: [PATCH 7/7] github_runner: fix test --- Library/Homebrew/test/github_runner_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/github_runner_spec.rb b/Library/Homebrew/test/github_runner_spec.rb index b61e0868b1..f869363f21 100644 --- a/Library/Homebrew/test/github_runner_spec.rb +++ b/Library/Homebrew/test/github_runner_spec.rb @@ -4,7 +4,7 @@ require "github_runner" describe GitHubRunner do let(:runner) do - spec = MacOSRunnerSpec.new(name: "macOS 11-arm64", runner: "11-arm64", cleanup: true) + spec = MacOSRunnerSpec.new(name: "macOS 11-arm64", runner: "11-arm64", timeout: 90, cleanup: true) version = OS::Mac::Version.new("11") described_class.new(platform: :macos, arch: :arm64, spec: spec, macos_version: version) end