brew/Library/Homebrew/dev-cmd/update-license-data.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "cli/parser"
2020-08-04 10:07:57 -07:00
require "utils/spdx"
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
`update-license-data` [<options>]
Update SPDX license data in the Homebrew repository.
2020-06-25 05:10:29 +08:00
EOS
switch "--fail-if-not-changed",
description: "Return a failing status code if current license data's version is the same as " \
"the upstream. This can be used to notify CI when the SPDX license data is out of date."
switch "--commit",
description: "Commit changes to the SPDX license data."
2020-06-25 05:46:18 +08:00
max_named 0
end
2020-06-25 05:46:18 +08:00
end
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
ohai "Updating SPDX license data..."
2020-08-04 10:07:57 -07:00
SPDX.download_latest_license_data!
Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX::DATA_PATH) if args.fail_if_not_changed?
return unless args.commit?
2020-06-25 05:46:18 +08:00
ohai "git add"
safe_system "git", "add", SPDX::DATA_PATH
ohai "git commit"
system "git", "commit", "--message", "spdx license data: update to #{SPDX.latest_tag}"
end
2020-06-25 05:46:18 +08:00
end