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

dev-cmd/determine-test-runner: add --all-supported #16227

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
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
33 changes: 23 additions & 10 deletions .github/workflows/doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,34 @@ env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_NO_AUTO_UPDATE: 1
jobs:
determine-runners:
runs-on: ubuntu-22.04
outputs:
runners: ${{ steps.determine-runners.outputs.runners }}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: false
cask: false
test-bot: false

- name: Determine runners to use for this job
id: determine-runners
env:
HOMEBREW_MACOS_TIMEOUT: 30
run: brew determine-test-runners --all-supported

tests:
needs: determine-runners
strategy:
matrix:
include:
- runner: "13-arm64-${{ github.run_id }}"
- runner: "13-${{ github.run_id }}"
- runner: "12-arm64-${{ github.run_id }}"
- runner: "12-${{ github.run_id }}"
- runner: "11-arm64"
cleanup: true
- runner: "11-${{ github.run_id }}"
include: ${{ fromJson(needs.determine-runners.outputs.runners) }}
fail-fast: false
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
env:
PATH: "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
timeout-minutes: ${{ matrix.timeout }}
defaults:
run:
working-directory: /tmp
Expand Down
35 changes: 22 additions & 13 deletions Library/Homebrew/dev-cmd/determine-test-runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ module Homebrew
def self.determine_test_runners_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`determine-test-runners` <testing-formulae> [<deleted-formulae>]
`determine-test-runners` {<testing-formulae> [<deleted-formulae>]|--all-supported}

Determines the runners used to test formulae or their dependents.
Determines the runners used to test formulae or their dependents. For internal use in Homebrew taps.
EOS
switch "--all-supported",
description: "Instead of selecting runners based on the chosen formula, return all supported runners."
switch "--eval-all",
description: "Evaluate all available formulae, whether installed or not, to determine testing " \
"dependents."
"dependents.",
env: :eval_all
switch "--dependents",
description: "Determine runners for testing dependents. Requires `--eval-all` or `HOMEBREW_EVAL_ALL`."
description: "Determine runners for testing dependents. Requires `--eval-all` or `HOMEBREW_EVAL_ALL`.",
depends_on: "--eval-all"

named_args min: 1, max: 2
named_args max: 2

conflicts "--all-supported", "--dependents"

hide_from_man_page!
end
Expand All @@ -30,16 +36,19 @@ def self.determine_test_runners_args
def self.determine_test_runners
args = determine_test_runners_args.parse

eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all?

odie "`--dependents` requires `--eval-all` or `HOMEBREW_EVAL_ALL`!" if args.dependents? && !eval_all
if args.no_named? && !args.all_supported?
raise Homebrew::CLI::MinNamedArgumentsError, 1
elsif args.all_supported? && !args.no_named?
raise UsageError, "`--all-supported` is mutually exclusive to other arguments."
end

testing_formulae = args.named.first.split(",")
testing_formulae.map! { |name| TestRunnerFormula.new(Formulary.factory(name), eval_all: eval_all) }
testing_formulae = args.named.first&.split(",").to_a
testing_formulae.map! { |name| TestRunnerFormula.new(Formulary.factory(name), eval_all: args.eval_all?) }
.freeze
deleted_formulae = args.named.second&.split(",").freeze

runner_matrix = GitHubRunnerMatrix.new(testing_formulae, deleted_formulae, dependent_matrix: args.dependents?)
deleted_formulae = args.named.second&.split(",").to_a.freeze
runner_matrix = GitHubRunnerMatrix.new(testing_formulae, deleted_formulae,
all_supported: args.all_supported?,
dependent_matrix: args.dependents?)
runners = runner_matrix.active_runner_specs_hash

ohai "Runners", JSON.pretty_generate(runners)
Expand Down
28 changes: 18 additions & 10 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
class GitHubRunnerMatrix
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
MaybeStringArray = T.type_alias { T.nilable(T::Array[String]) }
private_constant :MaybeStringArray

RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) }
private_constant :RunnerSpec

Expand Down Expand Up @@ -38,13 +35,19 @@ class GitHubRunnerMatrix
sig {
params(
testing_formulae: T::Array[TestRunnerFormula],
deleted_formulae: MaybeStringArray,
deleted_formulae: T::Array[String],
all_supported: T::Boolean,
dependent_matrix: T::Boolean,
).void
}
def initialize(testing_formulae, deleted_formulae, dependent_matrix:)
def initialize(testing_formulae, deleted_formulae, all_supported:, dependent_matrix:)
if all_supported && (testing_formulae.present? || deleted_formulae.present? || dependent_matrix)
raise ArgumentError, "all_supported is mutually exclusive to other arguments"
end

@testing_formulae = T.let(testing_formulae, T::Array[TestRunnerFormula])
@deleted_formulae = T.let(deleted_formulae, MaybeStringArray)
@deleted_formulae = T.let(deleted_formulae, T::Array[String])
@all_supported = T.let(all_supported, T::Boolean)
@dependent_matrix = T.let(dependent_matrix, T::Boolean)

@runners = T.let([], T::Array[GitHubRunner])
Expand Down Expand Up @@ -103,13 +106,16 @@ def create_runner(platform, arch, spec, macos_version = nil)
end

NEWEST_GITHUB_ACTIONS_MACOS_RUNNER = :ventura
OLDEST_GITHUB_ACTIONS_MACOS_RUNNER = :big_sur
GITHUB_ACTIONS_RUNNER_TIMEOUT = 360

sig { void }
def generate_runners!
return if @runners.present?

@runners << create_runner(:linux, :x86_64, linux_runner_spec)
if !@all_supported || ENV.key?("HOMEBREW_LINUX_RUNNER")
@runners << create_runner(:linux, :x86_64, linux_runner_spec)
end

github_run_id = ENV.fetch("GITHUB_RUN_ID")
timeout = ENV.fetch("HOMEBREW_MACOS_TIMEOUT").to_i
Expand All @@ -132,6 +138,7 @@ def generate_runners!
# Use GitHub Actions macOS Runner for testing dependents if compatible with timeout.
runner, runner_timeout = if (@dependent_matrix || use_github_runner) &&
macos_version <= NEWEST_GITHUB_ACTIONS_MACOS_RUNNER &&
macos_version >= OLDEST_GITHUB_ACTIONS_MACOS_RUNNER &&
runner_timeout <= GITHUB_ACTIONS_RUNNER_TIMEOUT
["macos-#{version}", GITHUB_ACTIONS_RUNNER_TIMEOUT]
else
Expand All @@ -149,6 +156,7 @@ def generate_runners!
next if macos_version < :big_sur

runner = +"#{version}-arm64"
runner_timeout = timeout

# Use bare metal runner when testing dependents on ARM64 Monterey.
use_ephemeral = macos_version >= (@dependent_matrix ? :ventura : :monterey)
Expand All @@ -174,9 +182,7 @@ def generate_runners!
def active_runner?(runner)
if @dependent_matrix
formulae_have_untested_dependents?(runner)
else
return true if @deleted_formulae.present?

elsif !@all_supported && @deleted_formulae.empty?
compatible_formulae = @testing_formulae.dup

platform = runner.platform
Expand All @@ -191,6 +197,8 @@ def active_runner?(runner)
end

compatible_formulae.present?
else
true
end
end

Expand Down
Loading