| 
									
										
										
										
											2020-06-23 01:39:10 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2020-08-04 10:07:57 -07:00
										 |  |  | require "utils/spdx" | 
					
						
							| 
									
										
										
										
											2020-06-23 01:39:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  |   def update_license_data_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  |         `update-license-data` [<options>] | 
					
						
							| 
									
										
										
										
											2020-06-23 02:25:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 16:20:07 +08:00
										 |  |  |          Update SPDX license data in the Homebrew repository. | 
					
						
							| 
									
										
										
										
											2020-06-25 05:10:29 +08:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-17 14:14:12 +01:00
										 |  |  |       switch "--fail-if-not-changed", | 
					
						
							|  |  |  |              description: "Return a failing status code if current license data's version is the same as " \ | 
					
						
							| 
									
										
										
										
											2020-06-29 16:20:07 +08:00
										 |  |  |                           "the upstream. This can be used to notify CI when the SPDX license data is out of date." | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  |       switch "--commit", | 
					
						
							|  |  |  |              description: "Commit changes to the SPDX license data." | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  |       max_named 0
 | 
					
						
							| 
									
										
										
										
											2020-06-23 01:39:10 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-06-23 01:39:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  |   def update_license_data | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = update_license_data_args.parse | 
					
						
							| 
									
										
										
										
											2020-06-29 16:20:07 +08:00
										 |  |  |     ohai "Updating SPDX license data..." | 
					
						
							| 
									
										
										
										
											2020-06-30 15:18:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 10:07:57 -07:00
										 |  |  |     SPDX.download_latest_license_data! | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 10:07:57 -07:00
										 |  |  |     Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX::JSON_PATH) if args.fail_if_not_changed? | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return unless args.commit? | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  |     ohai "git add" | 
					
						
							| 
									
										
										
										
											2020-08-04 10:07:57 -07:00
										 |  |  |     safe_system "git", "add", SPDX::JSON_PATH | 
					
						
							| 
									
										
										
										
											2020-07-17 20:45:15 +10:00
										 |  |  |     ohai "git commit" | 
					
						
							| 
									
										
										
										
											2020-08-10 11:32:05 -07:00
										 |  |  |     system "git", "commit", "--message", "data/spdx.json: update to #{SPDX.latest_tag}" | 
					
						
							| 
									
										
										
										
											2020-06-23 01:39:10 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-06-25 05:46:18 +08:00
										 |  |  | end |