2020-11-25 17:03:23 +01:00
|
|
|
# typed: true
|
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"
|
2022-09-02 08:24:33 +01:00
|
|
|
require "system_command"
|
2020-06-23 01:39:10 +08:00
|
|
|
|
|
|
|
module Homebrew
|
2022-09-02 08:24:33 +01:00
|
|
|
include SystemCommand::Mixin
|
2020-10-20 12:03:48 +02:00
|
|
|
|
2020-06-23 01:39:10 +08:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2020-06-25 05:46:18 +08:00
|
|
|
def update_license_data_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2021-01-15 15:04:02 -05:00
|
|
|
description <<~EOS
|
|
|
|
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",
|
2022-09-02 08:24:33 +01:00
|
|
|
hidden: true,
|
2020-07-17 14:14:12 +01:00
|
|
|
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-11-12 10:40:41 -05:00
|
|
|
|
2021-01-10 14:26:40 -05:00
|
|
|
named_args :none
|
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
|
2023-02-07 19:25:51 +01:00
|
|
|
odisabled "brew update-license-data --fail-if-not-changed" if args.fail_if_not_changed?
|
2020-06-30 15:18:10 +08:00
|
|
|
|
2020-08-04 10:07:57 -07:00
|
|
|
SPDX.download_latest_license_data!
|
2022-09-02 08:24:33 +01:00
|
|
|
diff = system_command "git", args: [
|
|
|
|
"-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", SPDX::DATA_PATH
|
|
|
|
]
|
|
|
|
if diff.status.success?
|
|
|
|
ofail "No changes to SPDX license data."
|
|
|
|
else
|
|
|
|
puts "SPDX license data updated."
|
|
|
|
end
|
2020-06-23 01:39:10 +08:00
|
|
|
end
|
2020-06-25 05:46:18 +08:00
|
|
|
end
|