2020-06-23 01:39:10 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cli/parser"
|
2020-07-17 20:45:15 +10:00
|
|
|
require "utils/github"
|
2020-06-23 01:39:10 +08:00
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module_function
|
|
|
|
|
2020-06-30 01:08:29 +08:00
|
|
|
SPDX_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze
|
2020-07-17 20:45:15 +10:00
|
|
|
SPDX_API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
|
2020-06-23 01:39:10 +08:00
|
|
|
|
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-07-17 20:45:15 +10:00
|
|
|
latest_tag = GitHub.open_api(SPDX_API_URL)["tag_name"]
|
|
|
|
data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/licenses.json"
|
|
|
|
curl_download(data_url, to: SPDX_PATH, partial: false)
|
|
|
|
|
2020-07-17 14:14:12 +01:00
|
|
|
Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX_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"
|
|
|
|
safe_system "git", "add", SPDX_PATH
|
|
|
|
ohai "git commit"
|
|
|
|
system "git", "commit", "--message", "data/spdx.json: update to #{latest_tag}"
|
2020-06-23 01:39:10 +08:00
|
|
|
end
|
2020-06-25 05:46:18 +08:00
|
|
|
end
|