Skip to content
Snippets Groups Projects
Commit f1f97c55 authored by Jonathan Chang's avatar Jonathan Chang
Browse files

update-license-data: only check against latest tag

parent 0f5d9a5c
No related branches found
No related tags found
No related merge requests found
# frozen_string_literal: true
require "commands"
require "cli/parser"
require "json"
require "net/http"
require "open-uri"
require "utils/github"
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"
SPDX_API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
def update_license_data_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`update_license_data` <cmd>
`update-license-data` [<options>]
Update SPDX license data in the Homebrew repository.
EOS
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."
switch "--commit",
description: "Commit changes to the SPDX license data."
max_named 0
end
end
......@@ -30,10 +28,18 @@ module Homebrew
def update_license_data
update_license_data_args.parse
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)
Homebrew.failed = !system("git", "diff", "--stat", "--exit-code", SPDX_PATH) if args.fail_if_changed?
return unless args.commit?
safe_system "git", "diff", "--stat", "--exit-code", SPDX_PATH
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
......@@ -1048,12 +1048,14 @@ directory.
* `-g`, `--git`:
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.
* `--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.
* `--commit`:
Commit changes to the SPDX license data.
### `update-test` [*`options`*]
......
......@@ -1357,13 +1357,17 @@ Patches for \fIformula\fR will be applied to the unpacked source\.
\fB\-g\fR, \fB\-\-git\fR
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\.
.
.TP
\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\.
.
.TP
\fB\-\-commit\fR
Commit changes to the SPDX license data\.
.
.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\.
.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment