| 
									
										
										
										
											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`)." | 
					
						
							|  |  |  |       flag   "--issue=", | 
					
						
							|  |  |  |              description: "If specified, post a comment to this issue number if the job fails." | 
					
						
							|  |  |  |       flag   "--macos=", | 
					
						
							|  |  |  |              description: "Version of macOS the bottle should be built for." | 
					
						
							|  |  |  |       flag   "--workflow=", | 
					
						
							|  |  |  |              description: "Dispatch specified workflow (default: `dispatch-build-bottle.yml`)." | 
					
						
							|  |  |  |       switch "--upload", | 
					
						
							|  |  |  |              description: "Upload built bottles to Bintray." | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  |     # Fixup version for ARM/Apple Silicon | 
					
						
							| 
									
										
										
										
											2020-12-09 11:55:27 +00:00
										 |  |  |     # TODO: fix label name to be 11-arm64 instead and remove this. | 
					
						
							|  |  |  |     args.macos&.gsub!(/^11-arm$/, "11-arm64") | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 22:36:06 +01:00
										 |  |  |     macos = args.macos&.yield_self do |s| | 
					
						
							|  |  |  |       MacOS::Version.from_symbol(s.to_sym) | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |     rescue MacOSVersionError | 
					
						
							| 
									
										
										
										
											2020-11-29 22:36:06 +01:00
										 |  |  |       MacOS::Version.new(s) | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  |     raise UsageError, "Must specify --macos option" if macos.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Fixup label for ARM/Apple Silicon | 
					
						
							| 
									
										
										
										
											2020-12-09 11:55:27 +00:00
										 |  |  |     macos_label = if macos.arch == :arm64 | 
					
						
							|  |  |  |       # TODO: fix label name to be 11-arm64 instead. | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  |       "#{macos}-arm" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       macos.to_s | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-11-29 22:36:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |     tap = Tap.fetch(args.tap || CoreTap.instance.name) | 
					
						
							|  |  |  |     user, repo = tap.full_name.split("/") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     workflow = args.workflow || "dispatch-build-bottle.yml" | 
					
						
							|  |  |  |     ref = "master" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     args.named.to_resolved_formulae.each do |formula| | 
					
						
							|  |  |  |       # Required inputs | 
					
						
							|  |  |  |       inputs = { | 
					
						
							|  |  |  |         formula: formula.name, | 
					
						
							| 
									
										
										
										
											2020-12-07 13:20:01 +00:00
										 |  |  |         macos:   macos_label, | 
					
						
							| 
									
										
										
										
											2020-07-06 22:19:17 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Optional inputs | 
					
						
							|  |  |  |       # These cannot be passed as nil to GitHub API | 
					
						
							|  |  |  |       inputs[:issue] = args.issue if args.issue | 
					
						
							|  |  |  |       inputs[:upload] = args.upload?.to_s if args.upload? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for macOS #{macos}" | 
					
						
							|  |  |  |       GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |