| 
									
										
										
										
											2020-11-25 17:03:23 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							|  |  |  | require "utils/github" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |   def dispatch_build_bottle_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |         Build bottles for these formulae with GitHub Actions. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       flag   "--tap=", | 
					
						
							|  |  |  |              description: "Target tap repository (default: `homebrew/core`)." | 
					
						
							| 
									
										
										
										
											2021-10-22 16:30:31 +01:00
										 |  |  |       flag   "--timeout=", | 
					
						
							|  |  |  |              description: "Build timeout (in minutes, default: 60)." | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |       flag   "--issue=", | 
					
						
							|  |  |  |              description: "If specified, post a comment to this issue number if the job fails." | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |       comma_array "--macos=", | 
					
						
							|  |  |  |                   description: "Version(s) of macOS the bottle should be built for." | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |       flag   "--workflow=", | 
					
						
							|  |  |  |              description: "Dispatch specified workflow (default: `dispatch-build-bottle.yml`)." | 
					
						
							|  |  |  |       switch "--upload", | 
					
						
							| 
									
										
										
										
											2021-05-12 13:37:18 +01:00
										 |  |  |              description: "Upload built bottles." | 
					
						
							| 
									
										
										
										
											2021-03-03 15:55:47 +01:00
										 |  |  |       switch "--linux", | 
					
						
							|  |  |  |              description: "Dispatch bottle for Linux (using GitHub runners)." | 
					
						
							| 
									
										
										
										
											2021-06-25 19:40:43 +02:00
										 |  |  |       switch "--linux-self-hosted", | 
					
						
							|  |  |  |              description: "Dispatch bottle for Linux (using self-hosted runner)." | 
					
						
							| 
									
										
										
										
											2021-07-05 18:24:43 +02:00
										 |  |  |       switch "--linux-wheezy", | 
					
						
							| 
									
										
										
										
											2021-06-25 19:40:43 +02:00
										 |  |  |              description: "Use Debian Wheezy container for building the bottle on Linux." | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 00:48:25 +01:00
										 |  |  |       conflicts "--linux", "--linux-self-hosted" | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args :formula, min: 1
 | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def dispatch_build_bottle | 
					
						
							|  |  |  |     args = dispatch_build_bottle_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 15:55:47 +01:00
										 |  |  |     tap = Tap.fetch(args.tap || CoreTap.instance.name) | 
					
						
							|  |  |  |     user, repo = tap.full_name.split("/") | 
					
						
							|  |  |  |     ref = "master" | 
					
						
							|  |  |  |     workflow = args.workflow || "dispatch-build-bottle.yml" | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 00:48:25 +01:00
										 |  |  |     runners = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (macos = args.macos&.compact_blank) && macos.present? | 
					
						
							|  |  |  |       runners += macos.map do |element| | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |         # We accept runner name syntax (11-arm64) or bottle syntax (arm64_big_sur) | 
					
						
							| 
									
										
										
										
											2022-04-23 01:47:37 +01:00
										 |  |  |         os, arch = element.then do |s| | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |           tag = Utils::Bottles::Tag.from_symbol(s.to_sym) | 
					
						
							|  |  |  |           [tag.to_macos_version, tag.arch] | 
					
						
							|  |  |  |         rescue ArgumentError, MacOSVersionError | 
					
						
							|  |  |  |           os, arch = s.split("-", 2) | 
					
						
							|  |  |  |           [MacOS::Version.new(os), arch&.to_sym] | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-11-29 22:36:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |         if arch.present? && arch != :x86_64 | 
					
						
							|  |  |  |           "#{os}-#{arch}" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           os.to_s | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-03-03 15:55:47 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2022-06-14 00:48:25 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.linux? | 
					
						
							| 
									
										
										
										
											2022-09-27 10:30:08 +01:00
										 |  |  |       runners << "ubuntu-22.04" | 
					
						
							| 
									
										
										
										
											2021-06-25 19:40:43 +02:00
										 |  |  |     elsif args.linux_self_hosted? | 
					
						
							| 
									
										
										
										
											2022-06-14 00:48:25 +01:00
										 |  |  |       runners << "linux-self-hosted-1" | 
					
						
							| 
									
										
										
										
											2021-03-03 15:55:47 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 00:48:25 +01:00
										 |  |  |     raise UsageError, "Must specify --macos or --linux or --linux-self-hosted option" if runners.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |     args.named.to_resolved_formulae.each do |formula| | 
					
						
							|  |  |  |       # Required inputs | 
					
						
							|  |  |  |       inputs = { | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |         runner:  runners.join(","), | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |         formula: formula.name, | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Optional inputs | 
					
						
							|  |  |  |       # These cannot be passed as nil to GitHub API | 
					
						
							| 
									
										
										
										
											2021-10-22 16:30:31 +01:00
										 |  |  |       inputs[:timeout] = args.timeout if args.timeout | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |       inputs[:issue] = args.issue if args.issue | 
					
						
							|  |  |  |       inputs[:upload] = args.upload?.to_s if args.upload? | 
					
						
							| 
									
										
										
										
											2021-07-05 18:24:43 +02:00
										 |  |  |       inputs[:wheezy] = args.linux_wheezy?.to_s if args.linux_wheezy? | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 05:13:11 +01:00
										 |  |  |       ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for #{runners.join(", ")}" | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |       GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |