Skip to content

Commit

Permalink
Suppory lazy evaluation/memoization of deploy_new_x86_64_runner?
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocab committed Sep 21, 2024
1 parent 41c5f72 commit c34e4bc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def initialize(testing_formulae, deleted_formulae, all_supported:, dependent_mat
@dependent_matrix = T.let(dependent_matrix, T::Boolean)
@compatible_testing_formulae = T.let({}, T::Hash[GitHubRunner, T::Array[TestRunnerFormula]])
@formulae_with_untested_dependents = T.let({}, T::Hash[GitHubRunner, T::Array[TestRunnerFormula]])
@deploy_new_x86_64_runner = T.let(all_supported, T::Boolean)

@runners = T.let([], T::Array[GitHubRunner])
generate_runners!
Expand Down Expand Up @@ -122,7 +123,7 @@ def create_runner(platform, arch, spec, macos_version = nil)

NEWEST_HOMEBREW_CORE_MACOS_RUNNER = :sequoia
OLDEST_HOMEBREW_CORE_MACOS_RUNNER = :ventura
NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER = :sonoma
NEWEST_DEFAULT_HOMEBREW_CORE_INTEL_MACOS_RUNNER = :sonoma

sig { params(macos_version: MacOSVersion).returns(T::Boolean) }
def runner_enabled?(macos_version)
Expand Down Expand Up @@ -175,10 +176,6 @@ def generate_runners!
ephemeral_suffix << "-long" if runner_timeout == GITHUB_ACTIONS_LONG_TIMEOUT
ephemeral_suffix.freeze

# `#deploy_new_x86_64_runner?` is expensive, so:
# - avoid calling it if we don't have to
# - cache the result to a variable to avoid calling it multiple times
deploy_new_x86_64_runner = @all_supported || deploy_new_x86_64_runner?
MacOSVersion::SYMBOLS.each_value do |version|
macos_version = MacOSVersion.new(version)
next unless runner_enabled?(macos_version)
Expand All @@ -202,7 +199,13 @@ def generate_runners!
)
@runners << create_runner(:macos, :arm64, spec, macos_version)

next if macos_version > NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER && !deploy_new_x86_64_runner
# `#deploy_new_x86_64_runner?` is expensive, so:
# - avoid calling it if we don't have to
# - cache the result to a variable to avoid calling it multiple times
if macos_version > NEWEST_DEFAULT_HOMEBREW_CORE_INTEL_MACOS_RUNNER &&
!(@deploy_new_x86_64_runner ||= deploy_new_x86_64_runner?)
next
end

github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER
Expand Down

0 comments on commit c34e4bc

Please sign in to comment.