Skip to content

Commit 30e25c5

Browse files
carlocabBo98
andcommitted
github_runner_matrix: deploy new x86_64 runner when required
Closes #18356. Co-authored-by: Bo Anderson <[email protected]>
1 parent 3b649d1 commit 30e25c5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Library/Homebrew/github_runner_matrix.rb

+26-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def initialize(testing_formulae, deleted_formulae, all_supported:, dependent_mat
6060
@dependent_matrix = T.let(dependent_matrix, T::Boolean)
6161
@compatible_testing_formulae = T.let({}, T::Hash[GitHubRunner, T::Array[TestRunnerFormula]])
6262
@formulae_with_untested_dependents = T.let({}, T::Hash[GitHubRunner, T::Array[TestRunnerFormula]])
63+
@deploy_new_x86_64_runner = T.let(all_supported, T::Boolean)
6364

6465
@runners = T.let([], T::Array[GitHubRunner])
6566
generate_runners!
@@ -122,13 +123,30 @@ def create_runner(platform, arch, spec, macos_version = nil)
122123

123124
NEWEST_HOMEBREW_CORE_MACOS_RUNNER = :sequoia
124125
OLDEST_HOMEBREW_CORE_MACOS_RUNNER = :ventura
125-
NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER = :sonoma
126+
NEWEST_DEFAULT_HOMEBREW_CORE_INTEL_MACOS_RUNNER = :sonoma
126127

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

133+
NEW_INTEL_MACOS_MUST_BUILD_FORMULAE = %w[pkg-config pkgconf].freeze
134+
135+
sig { returns(T::Boolean) }
136+
def deploy_new_x86_64_runner?
137+
return true if @testing_formulae.any? { |f| NEW_INTEL_MACOS_MUST_BUILD_FORMULAE.include?(f.name) }
138+
return true if @testing_formulae.any? { |f| f.formula.class.pour_bottle_only_if == :clt_installed }
139+
140+
Formula.all.any? do |formula|
141+
next false if formula.class.pour_bottle_only_if != :clt_installed
142+
143+
non_test_dependencies = Dependency.expand(formula, cache_key: "determine-test-runners") do |_, dependency|
144+
Dependency.prune if dependency.test?
145+
end
146+
non_test_dependencies.any? { |dep| @testing_formulae.map(&:name).include?(dep.name) }
147+
end
148+
end
149+
132150
NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER = :ventura
133151
OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER = :monterey
134152
NEWEST_GITHUB_ACTIONS_ARM_MACOS_RUNNER = :sonoma
@@ -181,7 +199,13 @@ def generate_runners!
181199
)
182200
@runners << create_runner(:macos, :arm64, spec, macos_version)
183201

184-
next if !@all_supported && macos_version > NEWEST_HOMEBREW_CORE_INTEL_MACOS_RUNNER
202+
# `#deploy_new_x86_64_runner?` is expensive, so:
203+
# - avoid calling it if we don't have to
204+
# - cache the result to a variable to avoid calling it multiple times
205+
if macos_version > NEWEST_DEFAULT_HOMEBREW_CORE_INTEL_MACOS_RUNNER &&
206+
!(@deploy_new_x86_64_runner ||= deploy_new_x86_64_runner?)
207+
next
208+
end
185209

186210
github_runner_available = macos_version <= NEWEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER &&
187211
macos_version >= OLDEST_GITHUB_ACTIONS_INTEL_MACOS_RUNNER

0 commit comments

Comments
 (0)