Class: Homebrew::DevCmd::DetermineTestRunners Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/determine-test-runners.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/determine_test_runners.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::DevCmd::DetermineTestRunners::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/determine_test_runners.rbi', line 10

def args; end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'dev-cmd/determine-test-runners.rb', line 51

def run
  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

  runners = if args.cask?
    require "cask/ci/runner_matrix"

    repository = ENV.fetch("GITHUB_REPOSITORY", nil)
    tap = if repository.present?
      Tap.fetch(repository)
    else
      Tap.from_path(Dir.pwd) || CoreCaskTap.instance
    end
    Homebrew::API.with_no_api_env do
      Cask::CI::RunnerMatrix.generate(tap, args.named.fetch(0).split(/[,\s]+/).reject(&:empty?),
                                      added_casks:  args.named.second.to_s.split(/[,\s]+/),
                                      labels:       Cask::CI::RunnerMatrix.labels(args.url),
                                      skip_install: args.skip_install?,
                                      new_cask:     args.new?)
    end
  else
    testing_formulae = args.named.first&.split(",").to_a.map do |name|
      TestRunnerFormula.new(Formulary.factory(name), include_uninstalled: true)
    end.freeze
    deleted_formulae = args.named.second&.split(",").to_a.freeze
    dependent_shards = args.dependent_shards || "1"
    unless dependent_shards.match?(/\A[1-9]\d*\z/)
      raise UsageError,
            "`--dependent-shards` must be a positive integer."
    end

    runner_matrix = GitHubRunnerMatrix.new(testing_formulae, deleted_formulae,
                                           all_supported:    args.all_supported?,
                                           dependent_matrix: args.dependents?,
                                           dependent_shards: dependent_shards.to_i)
    runner_matrix.active_runner_specs_hash
  end

  ohai "Runners", JSON.pretty_generate(runners)

  # gracefully handle non-GitHub Actions environments
  github_output = if ENV.key?("GITHUB_ACTIONS")
    ENV.fetch("GITHUB_OUTPUT")
  else
    ENV.fetch("GITHUB_OUTPUT", nil)
  end
  return unless github_output

  File.open(github_output, "a") do |f|
    f.puts("runners=#{runners.to_json}")
    f.puts("runners_present=#{runners.present?}")
  end
end