| 
									
										
										
										
											2023-04-03 22:27:46 +08:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2023-04-05 01:18:11 +08:00
										 |  |  | require "test_runner_formula" | 
					
						
							| 
									
										
										
										
											2023-04-05 03:52:26 +08:00
										 |  |  | require "github_runner_matrix" | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2023-04-03 22:27:46 +08:00
										 |  |  |   sig { returns(Homebrew::CLI::Parser) } | 
					
						
							|  |  |  |   def self.determine_test_runners_args | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |         `determine-test-runners` {<testing-formulae> [<deleted-formulae>]|--all-supported} | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |         Determines the runners used to test formulae or their dependents. For internal use in Homebrew taps. | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |       switch "--all-supported", | 
					
						
							|  |  |  |              description: "Instead of selecting runners based on the chosen formula, return all supported runners." | 
					
						
							| 
									
										
										
										
											2023-04-04 23:58:32 +08:00
										 |  |  |       switch "--eval-all", | 
					
						
							|  |  |  |              description: "Evaluate all available formulae, whether installed or not, to determine testing " \ | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |                           "dependents.", | 
					
						
							|  |  |  |              env:         :eval_all | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  |       switch "--dependents", | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |              description: "Determine runners for testing dependents. Requires `--eval-all` or `HOMEBREW_EVAL_ALL`.", | 
					
						
							|  |  |  |              depends_on:  "--eval-all" | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |       named_args max: 2
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       conflicts "--all-supported", "--dependents" | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       hide_from_man_page! | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-04-05 01:09:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-03 22:27:46 +08:00
										 |  |  |   sig { void } | 
					
						
							|  |  |  |   def self.determine_test_runners | 
					
						
							| 
									
										
										
										
											2023-04-04 13:54:35 +08:00
										 |  |  |     args = determine_test_runners_args.parse | 
					
						
							| 
									
										
										
										
											2023-04-04 16:19:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2023-04-04 23:58:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |     testing_formulae = args.named.first&.split(",").to_a | 
					
						
							|  |  |  |     testing_formulae.map! { |name| TestRunnerFormula.new(Formulary.factory(name), eval_all: args.eval_all?) } | 
					
						
							| 
									
										
										
										
											2023-04-04 13:54:35 +08:00
										 |  |  |                     .freeze | 
					
						
							| 
									
										
										
										
											2023-11-17 01:38:10 +00:00
										 |  |  |     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?) | 
					
						
							| 
									
										
										
										
											2023-04-06 02:13:15 +08:00
										 |  |  |     runners = runner_matrix.active_runner_specs_hash | 
					
						
							| 
									
										
										
										
											2023-04-05 03:52:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 10:56:29 +08:00
										 |  |  |     ohai "Runners", JSON.pretty_generate(runners) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 02:13:15 +08:00
										 |  |  |     github_output = ENV.fetch("GITHUB_OUTPUT") | 
					
						
							| 
									
										
										
										
											2023-04-04 13:54:35 +08:00
										 |  |  |     File.open(github_output, "a") do |f| | 
					
						
							|  |  |  |       f.puts("runners=#{runners.to_json}") | 
					
						
							|  |  |  |       f.puts("runners_present=#{runners.present?}") | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-04-03 20:36:45 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |