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

40 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "commands"
require "cli/parser"
require "json"
2020-06-25 19:20:26 +08:00
require "net/http"
require "open-uri"
module Homebrew
module_function
SPDX_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze
SPDX_DATA_URL = "https://raw.githubusercontent.com/spdx/license-list-data/HEAD/json/licenses.json"
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>
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",
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-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
update_license_data_args.parse
ohai "Updating SPDX license data..."
curl_download(SPDX_DATA_URL, to: SPDX_PATH, partial: false)
2020-06-25 05:46:18 +08:00
return unless args.fail_if_changed?
safe_system "git", "diff", "--stat", "--exit-code", SPDX_PATH
end
2020-06-25 05:46:18 +08:00
end