Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github_runner_matrix: decouple macOS versions from MacOSVersion#supported_release? #18306

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def active_runner_specs_hash
private

SELF_HOSTED_LINUX_RUNNER = "linux-self-hosted-1"
GITHUB_ACTIONS_LONG_TIMEOUT = 4320
GITHUB_ACTIONS_SHORT_TIMEOUT = 120
# ARM macOS timeout, keep this under 1/2 of GitHub's job execution time limit for self-hosted runners.
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#usage-limits
GITHUB_ACTIONS_LONG_TIMEOUT = 2160 # 36 hours
GITHUB_ACTIONS_SHORT_TIMEOUT = 60

sig { returns(LinuxRunnerSpec) }
def linux_runner_spec
Expand Down Expand Up @@ -118,8 +120,17 @@ def create_runner(platform, arch, spec, macos_version = nil)
runner.freeze
end

NEWEST_HOMEBREW_CORE_MACOS_RUNNER = :sonoma
OLDEST_HOMEBREW_CORE_MACOS_RUNNER = :monterey
NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER = :sonoma

sig { params(macos_version: MacOSVersion).returns(T::Boolean) }
def runner_enabled?(macos_version)
macos_version <= NEWEST_HOMEBREW_CORE_MACOS_RUNNER && macos_version >= OLDEST_HOMEBREW_CORE_MACOS_RUNNER
end

NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER = :ventura
OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER = :big_sur
OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER = :monterey
NEWEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER = :sonoma
OLDEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER = :sonoma
GITHUB_ACTIONS_RUNNER_TIMEOUT = 360
Expand Down Expand Up @@ -149,49 +160,49 @@ def generate_runners!

MacOSVersion::SYMBOLS.each_value do |version|
macos_version = MacOSVersion.new(version)
next if macos_version.unsupported_release?
next unless runner_enabled?(macos_version)

github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER
github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER

runner, timeout = if use_github_runner && github_runner_available
["macos-#{version}", GITHUB_ACTIONS_RUNNER_TIMEOUT]
elsif macos_version >= :monterey
["#{version}-arm64#{ephemeral_suffix}", runner_timeout]
else
["#{version}-x86_64#{ephemeral_suffix}", runner_timeout]
["#{version}-arm64", runner_timeout]
end

# macOS 12-x86_64 is usually slower.
timeout += 30 if macos_version <= :monterey
spec = MacOSRunnerSpec.new(
name: "macOS #{version}-x86_64",
name: "macOS #{version}-arm64",
runner:,
timeout:,
cleanup: !runner.end_with?(ephemeral_suffix),
)
@runners << create_runner(:macos, :x86_64, spec, macos_version)
@runners << create_runner(:macos, :arm64, spec, macos_version)

next if macos_version < :big_sur
next if macos_version > NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER

github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER
github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER

runner, timeout = if use_github_runner && github_runner_available
["macos-#{version}", GITHUB_ACTIONS_RUNNER_TIMEOUT]
elsif macos_version >= :monterey
["#{version}-arm64#{ephemeral_suffix}", runner_timeout]
else
["#{version}-arm64", runner_timeout]
["#{version}-x86_64#{ephemeral_suffix}", runner_timeout]
end

# macOS 12-x86_64 is usually slower.
timeout += 30 if macos_version <= :monterey
# The ARM runners are typically over twice as fast as the Intel runners.
timeout /= 2 if !(use_github_runner && github_runner_available) && timeout < GITHUB_ACTIONS_LONG_TIMEOUT
timeout *= 2 if !(use_github_runner && github_runner_available) && timeout < GITHUB_ACTIONS_LONG_TIMEOUT
spec = MacOSRunnerSpec.new(
name: "macOS #{version}-arm64",
name: "macOS #{version}-x86_64",
runner:,
timeout:,
cleanup: !runner.end_with?(ephemeral_suffix),
)
@runners << create_runner(:macos, :arm64, spec, macos_version)
@runners << create_runner(:macos, :x86_64, spec, macos_version)
end

@runners.freeze
Expand Down