Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livecheck: Add ExtractPlist skip to SkipConditions #16968

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LivecheckCmd < AbstractCommand
switch "--cask", "--casks",
description: "Only check casks."
switch "--extract-plist",
description: "Include casks using the ExtractPlist livecheck strategy."
description: "Enable checking multiple casks with ExtractPlist strategy."

conflicts "--debug", "--json"
conflicts "--tap=", "--eval-all", "--installed"
Expand Down
25 changes: 9 additions & 16 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def run_checks(
has_a_newer_upstream_version = T.let(false, T::Boolean)

formulae_and_casks_total = formulae_and_casks_to_check.count

if json && !quiet && $stderr.tty?
Tty.with($stderr) do |stderr|
stderr.puts Formatter.headline("Running checks", color: :blue)
Expand All @@ -218,7 +217,7 @@ def run_checks(
)
end

# If only one formula/cask is being checked, we enable extract-plist
# Allow ExtractPlist strategy if only one formula/cask is being checked.
extract_plist = true if formulae_and_casks_total == 1

formulae_checked = formulae_and_casks_to_check.map.with_index do |formula_or_cask, i|
Expand All @@ -241,29 +240,23 @@ def run_checks(
puts
end

if cask && !extract_plist && formula_or_cask.livecheck.strategy == :extract_plist
skip_info = {
cask: cask.token,
status: "skipped",
messages: ["Livecheck skipped due to the ExtractPlist strategy"],
meta: { livecheckable: true },
}

SkipConditions.print_skip_information(skip_info) if !newer_only && !quiet
next
end

# Check skip conditions for a referenced formula/cask
if referenced_formula_or_cask
skip_info = SkipConditions.referenced_skip_information(
referenced_formula_or_cask,
name,
full_name: use_full_name,
full_name: use_full_name,
verbose:,
extract_plist:,
)
end

skip_info ||= SkipConditions.skip_information(formula_or_cask, full_name: use_full_name, verbose:)
skip_info ||= SkipConditions.skip_information(
formula_or_cask,
full_name: use_full_name,
verbose:,
extract_plist:,
)
if skip_info.present?
next skip_info if json && !newer_only

Expand Down
37 changes: 34 additions & 3 deletions Library/Homebrew/livecheck/skip_conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@
Livecheck.status_hash(cask, "disabled", full_name:, verbose:)
end

sig {
params(

Check warning on line 155 in Library/Homebrew/livecheck/skip_conditions.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/skip_conditions.rb#L155

Added line #L155 was not covered by tests
cask: Cask::Cask,
_livecheckable: T::Boolean,
full_name: T::Boolean,
verbose: T::Boolean,
extract_plist: T::Boolean,
).returns(Hash)
}
def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, extract_plist: false)
return {} if extract_plist || cask.livecheck.strategy != :extract_plist

Livecheck.status_hash(
cask,
"skipped",
["Use `--extract-plist` to enable checking multiple casks with ExtractPlist strategy"],
full_name:,
verbose:,
)
end

sig {
params(
cask: Cask::Cask,
Expand Down Expand Up @@ -194,6 +215,7 @@
:cask_discontinued,
:cask_deprecated,
:cask_disabled,
:cask_extract_plist,
:cask_version_latest,
:cask_url_unversioned,
].freeze
Expand All @@ -211,9 +233,10 @@
package_or_resource: T.any(Formula, Cask::Cask, Resource),
full_name: T::Boolean,
verbose: T::Boolean,
extract_plist: T::Boolean,
).returns(Hash)
}
def skip_information(package_or_resource, full_name: false, verbose: false)
def skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
livecheckable = package_or_resource.livecheckable?

checks = case package_or_resource
Expand All @@ -227,7 +250,12 @@
return {} unless checks

checks.each do |method_name|
skip_hash = send(method_name, package_or_resource, livecheckable, full_name:, verbose:)
skip_hash = case method_name
when :cask_extract_plist
send(method_name, package_or_resource, livecheckable, full_name:, verbose:, extract_plist:)
else
send(method_name, package_or_resource, livecheckable, full_name:, verbose:)
end
return skip_hash if skip_hash.present?
end

Expand All @@ -244,18 +272,21 @@
original_package_or_resource_name: String,
full_name: T::Boolean,
verbose: T::Boolean,
extract_plist: T::Boolean,
).returns(T.nilable(Hash))
}
def referenced_skip_information(
livecheck_package_or_resource,
original_package_or_resource_name,
full_name: false,
verbose: false
verbose: false,
extract_plist: true
)
skip_info = SkipConditions.skip_information(
livecheck_package_or_resource,
full_name:,
verbose:,
extract_plist:,
)
return if skip_info.blank?

Expand Down
46 changes: 41 additions & 5 deletions Library/Homebrew/test/livecheck/skip_conditions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
url "https://brew.sh/test-0.0.1.tgz"
disable! date: "2020-06-25", because: :unmaintained
end,
versioned: formula("[email protected]") do
desc "Versioned test formula"
homepage "https://brew.sh"
url "https://brew.sh/test-0.0.1.tgz"
end,
head_only: formula("test_head_only") do
desc "HEAD-only test formula"
homepage "https://brew.sh"
Expand Down Expand Up @@ -74,6 +69,11 @@
skip "Not maintained"
end
end,
versioned: formula("[email protected]") do
desc "Versioned test formula"
homepage "https://brew.sh"
url "https://brew.sh/test-0.0.1.tgz"
end,
}
end

Expand Down Expand Up @@ -127,6 +127,18 @@

disable! date: "2020-06-25", because: :discontinued
end,
extract_plist: Cask::Cask.new("test_extract_plist_skip") do
version "0.0.1"

url "https://brew.sh/test-0.0.1.tgz"
name "Test ExtractPlist Skip"
desc "Skipped test cask"
homepage "https://brew.sh"

livecheck do
strategy :extract_plist
end
end,
latest: Cask::Cask.new("test_latest") do
version :latest
sha256 :no_check
Expand Down Expand Up @@ -267,6 +279,14 @@
livecheckable: false,
},
},
extract_plist: {
cask: "test_extract_plist_skip",
status: "skipped",
messages: ["Use `--extract-plist` to enable checking multiple casks with ExtractPlist strategy"],
meta: {
livecheckable: true,
},
},
latest: {
cask: "test_latest",
status: "latest",
Expand Down Expand Up @@ -381,6 +401,13 @@
end
end

context "when a cask has a `livecheck` block using `ExtractPlist` and `--extract-plist` is not used" do
it "skips" do
expect(skip_conditions.skip_information(casks[:extract_plist], extract_plist: false))
.to eq(status_hashes[:cask][:extract_plist])
end
end

context "when a cask without a livecheckable has `version :latest`" do
it "skips" do
expect(skip_conditions.skip_information(casks[:latest]))
Expand Down Expand Up @@ -497,6 +524,15 @@
end
end

context "when a cask has a `livecheck` block using `ExtractPlist` and `--extract-plist` is not used" do
it "skips" do
expect do
skip_conditions.referenced_skip_information(casks[:extract_plist], original_name, extract_plist: false)
end
.to raise_error(RuntimeError, "Referenced cask (test_extract_plist_skip) is automatically skipped")
end
end

context "when a cask without a livecheckable has `version :latest`" do
it "errors" do
expect { skip_conditions.referenced_skip_information(casks[:latest], original_name) }
Expand Down