update-license-data: only check against latest tag

This commit is contained in:
Jonathan Chang 2020-07-17 20:45:15 +10:00
parent 0f5d9a5c47
commit f1f97c55b5
3 changed files with 24 additions and 12 deletions

View File

@ -1,28 +1,26 @@
# frozen_string_literal: true # frozen_string_literal: true
require "commands"
require "cli/parser" require "cli/parser"
require "json" require "utils/github"
require "net/http"
require "open-uri"
module Homebrew module Homebrew
module_function module_function
SPDX_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze SPDX_PATH = (HOMEBREW_LIBRARY_PATH/"data/spdx.json").freeze
SPDX_DATA_URL = "https://raw.githubusercontent.com/spdx/license-list-data/HEAD/json/licenses.json" SPDX_API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
def update_license_data_args def update_license_data_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
`update_license_data` <cmd> `update-license-data` [<options>]
Update SPDX license data in the Homebrew repository. Update SPDX license data in the Homebrew repository.
EOS EOS
switch "--fail-if-changed", switch "--fail-if-changed",
description: "Return a failing status code if current license data's version is different from " \ 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." "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."
max_named 0 max_named 0
end end
end end
@ -30,10 +28,18 @@ module Homebrew
def update_license_data def update_license_data
update_license_data_args.parse update_license_data_args.parse
ohai "Updating SPDX license data..." ohai "Updating SPDX license data..."
curl_download(SPDX_DATA_URL, to: SPDX_PATH, partial: false)
return unless args.fail_if_changed? 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)
safe_system "git", "diff", "--stat", "--exit-code", SPDX_PATH Homebrew.failed = !system("git", "diff", "--stat", "--exit-code", SPDX_PATH) if args.fail_if_changed?
return unless args.commit?
ohai "git add"
safe_system "git", "add", SPDX_PATH
ohai "git commit"
system "git", "commit", "--message", "data/spdx.json: update to #{latest_tag}"
end end
end end

View File

@ -1048,12 +1048,14 @@ directory.
* `-g`, `--git`: * `-g`, `--git`:
Initialise a Git repository in the unpacked source. This is useful for creating patches for the software. Initialise a Git repository in the unpacked source. This is useful for creating patches for the software.
### `update_license_data` *`cmd`* ### `update-license-data` [*`options`*]
Update SPDX license data in the Homebrew repository. Update SPDX license data in the Homebrew repository.
* `--fail-if-changed`: * `--fail-if-changed`:
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. 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.
* `--commit`:
Commit changes to the SPDX license data.
### `update-test` [*`options`*] ### `update-test` [*`options`*]

View File

@ -1357,13 +1357,17 @@ Patches for \fIformula\fR will be applied to the unpacked source\.
\fB\-g\fR, \fB\-\-git\fR \fB\-g\fR, \fB\-\-git\fR
Initialise a Git repository in the unpacked source\. This is useful for creating patches for the software\. Initialise a Git repository in the unpacked source\. This is useful for creating patches for the software\.
. .
.SS "\fBupdate_license_data\fR \fIcmd\fR" .SS "\fBupdate\-license\-data\fR [\fIoptions\fR]"
Update SPDX license data in the Homebrew repository\. Update SPDX license data in the Homebrew repository\.
. .
.TP .TP
\fB\-\-fail\-if\-changed\fR \fB\-\-fail\-if\-changed\fR
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\. 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\.
. .
.TP
\fB\-\-commit\fR
Commit changes to the SPDX license data\.
.
.SS "\fBupdate\-test\fR [\fIoptions\fR]" .SS "\fBupdate\-test\fR [\fIoptions\fR]"
Run a test of \fBbrew update\fR with a new repository clone\. If no options are passed, use \fBorigin/master\fR as the start commit\. Run a test of \fBbrew update\fR with a new repository clone\. If no options are passed, use \fBorigin/master\fR as the start commit\.
. .