Merge pull request #15309 from carlocab/longer-big-sur-timeout

github_runner_matrix: set `timeout` on macOS
This commit is contained in:
Carlo Cabrera 2023-04-25 17:52:51 +08:00 committed by GitHub
commit e69e8e04c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 15 deletions

View File

@ -13,7 +13,7 @@ class GitHubRunnerMatrix
RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) } RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) }
private_constant :RunnerSpec 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 private_constant :MacOSRunnerSpecHash
LinuxRunnerSpecHash = T.type_alias do LinuxRunnerSpecHash = T.type_alias do
@ -108,6 +108,7 @@ class GitHubRunnerMatrix
github_run_id = ENV.fetch("GITHUB_RUN_ID") github_run_id = ENV.fetch("GITHUB_RUN_ID")
github_run_attempt = ENV.fetch("GITHUB_RUN_ATTEMPT") 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 = +"-#{github_run_id}-#{github_run_attempt}"
ephemeral_suffix << "-deps" if @dependent_matrix ephemeral_suffix << "-deps" if @dependent_matrix
ephemeral_suffix.freeze ephemeral_suffix.freeze
@ -116,9 +117,16 @@ class GitHubRunnerMatrix
macos_version = OS::Mac::Version.new(version) macos_version = OS::Mac::Version.new(version)
next if macos_version.unsupported_release? 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( spec = MacOSRunnerSpec.new(
name: "macOS #{version}-x86_64", name: "macOS #{version}-x86_64",
runner: "#{version}#{ephemeral_suffix}", runner: "#{version}#{ephemeral_suffix}",
timeout: runner_timeout,
cleanup: false, cleanup: false,
) )
@runners << create_runner(:macos, :x86_64, spec, macos_version) @runners << create_runner(:macos, :x86_64, spec, macos_version)
@ -126,15 +134,14 @@ class GitHubRunnerMatrix
next unless macos_version >= :big_sur next unless macos_version >= :big_sur
# Use bare metal runner when testing dependents on ARM64 Monterey. # Use bare metal runner when testing dependents on ARM64 Monterey.
use_ephemeral = (macos_version >= :ventura && @dependent_matrix) || use_ephemeral = macos_version >= (@dependent_matrix ? :ventura : :monterey)
(macos_version >= :monterey && !@dependent_matrix)
runner, cleanup = if use_ephemeral runner, cleanup = if use_ephemeral
["#{version}-arm64#{ephemeral_suffix}", false] ["#{version}-arm64#{ephemeral_suffix}", false]
else else
["#{version}-arm64", true] ["#{version}-arm64", true]
end 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) @runners << create_runner(:macos, :arm64, spec, macos_version)
end end
@ -154,9 +161,12 @@ class GitHubRunnerMatrix
arch = runner.arch arch = runner.arch
macos_version = runner.macos_version macos_version = runner.macos_version
compatible_formulae.select! { |formula| formula.public_send(:"#{platform}_compatible?") } compatible_formulae.select! do |formula|
compatible_formulae.select! { |formula| formula.public_send(:"#{arch}_compatible?") } next false if macos_version && !formula.compatible_with?(macos_version)
compatible_formulae.select! { |formula| formula.compatible_with?(macos_version) } if macos_version
formula.public_send(:"#{platform}_compatible?") &&
formula.public_send(:"#{arch}_compatible?")
end
compatible_formulae.present? compatible_formulae.present?
end end
@ -178,9 +188,12 @@ class GitHubRunnerMatrix
compatible_dependents = formula.dependents(platform: platform, arch: arch, macos_version: macos_version&.to_sym) compatible_dependents = formula.dependents(platform: platform, arch: arch, macos_version: macos_version&.to_sym)
.dup .dup
compatible_dependents.select! { |dependent_f| dependent_f.public_send(:"#{platform}_compatible?") } compatible_dependents.select! do |dependent_f|
compatible_dependents.select! { |dependent_f| dependent_f.public_send(:"#{arch}_compatible?") } next false if macos_version && !dependent_f.compatible_with?(macos_version)
compatible_dependents.select! { |dependent_f| dependent_f.compatible_with?(macos_version) } if 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, # These arrays will generally have been generated by different Formulary caches,
# so we can only compare them by name and not directly. # so we can only compare them by name and not directly.

View File

@ -4,13 +4,15 @@
class MacOSRunnerSpec < T::Struct class MacOSRunnerSpec < T::Struct
const :name, String const :name, String
const :runner, String const :runner, String
const :timeout, Integer
const :cleanup, T::Boolean 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 def to_h
{ {
name: name, name: name,
runner: runner, runner: runner,
timeout: timeout,
cleanup: cleanup, cleanup: cleanup,
} }
end end

View File

@ -16,6 +16,7 @@ describe "brew determine-test-runners" do
{ {
"HOMEBREW_LINUX_RUNNER" => linux_runner, "HOMEBREW_LINUX_RUNNER" => linux_runner,
"HOMEBREW_LINUX_CLEANUP" => "false", "HOMEBREW_LINUX_CLEANUP" => "false",
"HOMEBREW_MACOS_TIMEOUT" => "90",
"GITHUB_RUN_ID" => ephemeral_suffix.split("-").second, "GITHUB_RUN_ID" => ephemeral_suffix.split("-").second,
"GITHUB_RUN_ATTEMPT" => ephemeral_suffix.split("-").third, "GITHUB_RUN_ATTEMPT" => ephemeral_suffix.split("-").third,
}.freeze }.freeze

View File

@ -7,6 +7,7 @@ describe GitHubRunnerMatrix do
before do before do
allow(ENV).to receive(:fetch).with("HOMEBREW_LINUX_RUNNER").and_return("ubuntu-latest") 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_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_ID").and_return("12345")
allow(ENV).to receive(:fetch).with("GITHUB_RUN_ATTEMPT").and_return("1") allow(ENV).to receive(:fetch).with("GITHUB_RUN_ATTEMPT").and_return("1")
end end

View File

@ -4,7 +4,7 @@ require "github_runner"
describe GitHubRunner do describe GitHubRunner do
let(:runner) 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") version = OS::Mac::Version.new("11")
described_class.new(platform: :macos, arch: :arm64, spec: spec, macos_version: version) described_class.new(platform: :macos, arch: :arm64, spec: spec, macos_version: version)
end end

View File

@ -3,10 +3,10 @@
require "macos_runner_spec" require "macos_runner_spec"
describe MacOSRunnerSpec do 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 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) expect(spec.respond_to?("#{attribute}=")).to be(false)
end end
end end

View File

@ -89,7 +89,7 @@ class TestRunnerFormula
def dependents(platform:, arch:, macos_version:) def dependents(platform:, arch:, macos_version:)
cache_key = :"#{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? all = eval_all || Homebrew::EnvConfig.eval_all?
formula_selector, eval_all_env = if all formula_selector, eval_all_env = if all
[:all, "1"] [:all, "1"]
@ -110,5 +110,7 @@ class TestRunnerFormula
Homebrew::SimulateSystem.clear Homebrew::SimulateSystem.clear
end end
end end
@dependent_hash.fetch(cache_key)
end end
end end