2020-06-23 01:39:10 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "commands"
|
|
|
|
require "cli/parser"
|
|
|
|
require "json"
|
2020-06-25 19:20:26 +08:00
|
|
|
require "net/http"
|
2020-06-25 19:05:41 +08:00
|
|
|
require "open-uri"
|
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-06-28 01:54:41 +08:00
|
|
|
SPDX_DATA_URL = "https://raw.githubusercontent.com/spdx/license-list-data/HEAD/json/licenses.json"
|
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
|
|
|
|
`update_license_data` <cmd>
|
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-06-25 05:46:18 +08:00
|
|
|
switch "--fail-if-changed",
|
2020-06-29 16:20:07 +08:00
|
|
|
description: "Return a failing status code if current license data's version is different from " \
|
|
|
|
"the upstream. This can be used to notify CI when the SPDX license data is out of date."
|
2020-06-23 01:39:10 +08:00
|
|
|
|
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
|
|
|
|
update_license_data_args.parse
|
2020-06-29 16:20:07 +08:00
|
|
|
ohai "Updating SPDX license data..."
|
2020-06-30 01:08:29 +08:00
|
|
|
spdx_download_result = curl(SPDX_DATA_URL)
|
|
|
|
SPDX_PATH.write(spdx_download_result.stdout, true)
|
2020-06-25 05:46:18 +08:00
|
|
|
return unless args.fail_if_changed?
|
|
|
|
|
2020-06-29 16:20:07 +08:00
|
|
|
system("git diff --stat --exit-code #{SPDX_PATH}")
|
2020-06-23 01:39:10 +08:00
|
|
|
end
|
2020-06-25 05:46:18 +08:00
|
|
|
end
|