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

Revert "Livecheck: Use Homebrew curl based on root domain" #13298

Merged
merged 1 commit into from
May 18, 2022
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
1 change: 0 additions & 1 deletion Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ source "https://rubygems.org"
# * nokogiri - use rexml instead for XML parsing

# installed gems (should all be require: false)
gem "addressable", require: false
gem "bootsnap", require: false
gem "byebug", require: false
gem "json_schemer", require: false
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ PLATFORMS

DEPENDENCIES
activesupport (< 7)
addressable
bootsnap
byebug
concurrent-ruby
Expand Down
40 changes: 15 additions & 25 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require "livecheck/livecheck_version"
require "livecheck/skip_conditions"
require "livecheck/strategy"
require "addressable"
require "ruby-progressbar"
require "uri"

Expand Down Expand Up @@ -530,33 +529,26 @@ def preprocess_url(url)
url
end

# livecheck should fetch a URL using brewed curl if the formula/cask
# contains a `stable`/`url` or `head` URL `using: :homebrew_curl` that
# shares the same root domain.
# Fetch with brewed curl if using the download or homepage URL
# and the download URL specifies `using: :homebrew_curl`.
sig { params(formula_or_cask: T.any(Formula, Cask::Cask), url: String).returns(T::Boolean) }
def use_homebrew_curl?(formula_or_cask, url)
url_root_domain = Addressable::URI.parse(url)&.domain
return false if url_root_domain.blank?
if checkable_urls(formula_or_cask).include?(url)
case formula_or_cask
when Formula
[:stable, :head].any? do |spec_name|
next false unless (spec = formula_or_cask.send(spec_name))

# Collect root domains of URLs with `using: :homebrew_curl`
homebrew_curl_root_domains = []
case formula_or_cask
when Formula
[:stable, :head].each do |spec_name|
next unless (spec = formula_or_cask.send(spec_name))
next unless spec.using == :homebrew_curl

domain = Addressable::URI.parse(spec.url)&.domain
homebrew_curl_root_domains << domain if domain.present?
spec.using == :homebrew_curl
end
when Cask::Cask
formula_or_cask.url.using == :homebrew_curl
else
T.absurd(formula_or_cask)
end
when Cask::Cask
return false unless formula_or_cask.url.using == :homebrew_curl

domain = Addressable::URI.parse(formula_or_cask.url.to_s)&.domain
homebrew_curl_root_domains << domain if domain.present?
else
false
end

homebrew_curl_root_domains.include?(url_root_domain)
end

# Identifies the latest version of the formula and returns a Hash containing
Expand Down Expand Up @@ -670,7 +662,6 @@ def latest_version(
when "PageMatch", "HeaderMatch"
use_homebrew_curl?((referenced_formula_or_cask || formula_or_cask), url)
end
puts "Homebrew curl?: Yes" if debug && homebrew_curl.present?

strategy_data = strategy.find_versions(
url: url,
Expand Down Expand Up @@ -752,7 +743,6 @@ def latest_version(
version_info[:meta][:url][:strategy] = strategy_data[:url]
end
version_info[:meta][:url][:final] = strategy_data[:final_url] if strategy_data[:final_url]
version_info[:meta][:url][:homebrew_curl] = homebrew_curl if homebrew_curl.present?

version_info[:meta][:strategy] = strategy.present? ? strategy_name : nil
version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names[s] } if strategies.present?
Expand Down
68 changes: 7 additions & 61 deletions Library/Homebrew/test/livecheck/livecheck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
formula("test") do
desc "Test formula"
homepage "https://brew.sh"
url "https://brew.sh/test-0.0.1.tgz"
url "https://brew.sh/test-0.0.1.tgz", using: :homebrew_curl
head "https://github.com/Homebrew/brew.git"

livecheck do
Expand All @@ -31,7 +31,7 @@
cask "test" do
version "0.0.1,2"

url "https://brew.sh/test-0.0.1.dmg"
url "https://brew.sh/test-0.0.1.dmg", using: :homebrew_curl
name "Test"
desc "Test cask"
homepage "https://brew.sh"
Expand Down Expand Up @@ -158,67 +158,13 @@
end

describe "::use_homebrew_curl?" do
let(:example_url) { "https://www.example.com/test-0.0.1.tgz" }

let(:f_homebrew_curl) do
formula("test") do
desc "Test formula"
homepage "https://brew.sh"
url "https://brew.sh/test-0.0.1.tgz", using: :homebrew_curl
# head is deliberably omitted to exercise more of the method

livecheck do
url "https://formulae.brew.sh/api/formula/ruby.json"
regex(/"stable":"(\d+(?:\.\d+)+)"/i)
end
end
end

let(:c_homebrew_curl) do
Cask::CaskLoader.load(+<<-RUBY)
cask "test" do
version "0.0.1,2"

url "https://brew.sh/test-0.0.1.dmg", using: :homebrew_curl
name "Test"
desc "Test cask"
homepage "https://brew.sh"

livecheck do
url "https://formulae.brew.sh/api/formula/ruby.json"
regex(/"stable":"(\d+(?:\.\d+)+)"/i)
end
end
RUBY
end

it "returns `true` when URL matches a `using: :homebrew_curl` URL" do
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, livecheck_url)).to be(true)
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, homepage_url)).to be(true)
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, stable_url)).to be(true)
expect(livecheck.use_homebrew_curl?(c_homebrew_curl, livecheck_url)).to be(true)
expect(livecheck.use_homebrew_curl?(c_homebrew_curl, homepage_url)).to be(true)
expect(livecheck.use_homebrew_curl?(c_homebrew_curl, cask_url)).to be(true)
end

it "returns `false` if URL root domain differs from `using: :homebrew_curl` URLs" do
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, example_url)).to be(false)
expect(livecheck.use_homebrew_curl?(c_homebrew_curl, example_url)).to be(false)
end

it "returns `false` if a `using: homebrew_curl` URL is not present" do
it "uses brewed curl if called for by the download URL" do
expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false)
expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(false)
expect(livecheck.use_homebrew_curl?(f, stable_url)).to be(false)
expect(livecheck.use_homebrew_curl?(f, example_url)).to be(false)
expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(true)
expect(livecheck.use_homebrew_curl?(f, stable_url)).to be(true)
expect(livecheck.use_homebrew_curl?(c, livecheck_url)).to be(false)
expect(livecheck.use_homebrew_curl?(c, homepage_url)).to be(false)
expect(livecheck.use_homebrew_curl?(c, cask_url)).to be(false)
expect(livecheck.use_homebrew_curl?(c, example_url)).to be(false)
end

it "returns `false` if URL string does not contain a domain" do
expect(livecheck.use_homebrew_curl?(f_homebrew_curl, "test")).to be(false)
expect(livecheck.use_homebrew_curl?(c, homepage_url)).to be(true)
expect(livecheck.use_homebrew_curl?(c, cask_url)).to be(true)
end
end

Expand Down