2021-01-22 12:22:24 -08:00
|
|
|
# frozen_string_literal: true
|
2020-08-08 07:10:48 +05:30
|
|
|
|
|
|
|
require "livecheck/livecheck"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe Homebrew::Livecheck do
|
2020-08-08 07:10:48 +05:30
|
|
|
subject(:livecheck) { described_class }
|
|
|
|
|
2021-01-13 09:30:50 -05:00
|
|
|
let(:cask_url) { "https://brew.sh/test-0.0.1.dmg" }
|
|
|
|
let(:head_url) { "https://github.com/Homebrew/brew.git" }
|
|
|
|
let(:homepage_url) { "https://brew.sh" }
|
|
|
|
let(:livecheck_url) { "https://formulae.brew.sh/api/formula/ruby.json" }
|
|
|
|
let(:stable_url) { "https://brew.sh/test-0.0.1.tgz" }
|
2022-09-25 02:06:23 +02:00
|
|
|
let(:resource_url) { "https://brew.sh/foo-1.0.tar.gz" }
|
2021-01-12 15:00:49 -05:00
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
let(:f) do
|
|
|
|
formula("test") do
|
|
|
|
desc "Test formula"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
url "https://brew.sh/test-0.0.1.tgz"
|
2021-01-13 09:30:50 -05:00
|
|
|
head "https://github.com/Homebrew/brew.git"
|
2020-08-08 07:10:48 +05:30
|
|
|
|
|
|
|
livecheck do
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://formulae.brew.sh/api/formula/ruby.json"
|
2020-08-29 02:18:18 +05:30
|
|
|
regex(/"stable":"(\d+(?:\.\d+)+)"/i)
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
2022-08-07 20:47:17 +02:00
|
|
|
|
|
|
|
resource "foo" do
|
|
|
|
url "https://brew.sh/foo-1.0.tar.gz"
|
|
|
|
sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
|
|
|
|
|
|
|
livecheck do
|
|
|
|
url "https://brew.sh/test/releases"
|
|
|
|
regex(/foo[._-]v?(\d+(?:\.\d+)+)\.t/i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-24 22:19:18 -04:00
|
|
|
let(:f_stable_url_only) do
|
|
|
|
stable_url_s = stable_url
|
|
|
|
|
|
|
|
formula("test_stable_url_only") do
|
|
|
|
desc "Test formula with only a stable URL"
|
|
|
|
url stable_url_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-07 21:49:16 +02:00
|
|
|
let(:r) { f.resources.first }
|
2022-08-07 20:47:17 +02:00
|
|
|
|
2020-12-19 22:26:37 -05:00
|
|
|
let(:c) do
|
|
|
|
Cask::CaskLoader.load(+<<-RUBY)
|
|
|
|
cask "test" do
|
|
|
|
version "0.0.1,2"
|
|
|
|
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
url "https://brew.sh/test-0.0.1.dmg"
|
2020-12-19 22:26:37 -05:00
|
|
|
name "Test"
|
|
|
|
desc "Test cask"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
2020-12-19 22:26:37 -05:00
|
|
|
|
|
|
|
livecheck do
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://formulae.brew.sh/api/formula/ruby.json"
|
2022-12-13 10:54:22 +00:00
|
|
|
regex(/"stable":"(\d+(?:.\d+)+)"/i)
|
2020-12-19 22:26:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2024-10-24 22:19:18 -04:00
|
|
|
let(:c_no_checkable_urls) do
|
|
|
|
Cask::CaskLoader.load(+<<-RUBY)
|
|
|
|
cask "test_no_checkable_urls" do
|
|
|
|
version "1.2.3"
|
|
|
|
|
|
|
|
name "Test"
|
|
|
|
desc "Test cask with no checkable URLs"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2025-02-19 16:22:25 -05:00
|
|
|
describe "::livecheck_strategy_names" do
|
|
|
|
context "when provided with a strategy class" do
|
|
|
|
it "returns demodulized class name" do
|
|
|
|
# We run this twice with the same argument to exercise the caching logic
|
|
|
|
expect(livecheck.send(:livecheck_strategy_names, Homebrew::Livecheck::Strategy::PageMatch)).to eq("PageMatch")
|
|
|
|
expect(livecheck.send(:livecheck_strategy_names, Homebrew::Livecheck::Strategy::PageMatch)).to eq("PageMatch")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-19 11:21:29 -04:00
|
|
|
describe "::resolve_livecheck_reference" do
|
2024-12-02 10:06:14 -05:00
|
|
|
context "when a formula/cask has a `livecheck` block without formula/cask methods" do
|
2021-07-19 11:21:29 -04:00
|
|
|
it "returns [nil, []]" do
|
|
|
|
expect(livecheck.resolve_livecheck_reference(f)).to eq([nil, []])
|
|
|
|
expect(livecheck.resolve_livecheck_reference(c)).to eq([nil, []])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-23 03:15:57 +01:00
|
|
|
describe "::package_or_resource_name" do
|
|
|
|
it "returns the name of a formula" do
|
|
|
|
expect(livecheck.package_or_resource_name(f)).to eq("test")
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
|
2024-08-23 03:15:57 +01:00
|
|
|
it "returns the full name of a formula" do
|
|
|
|
expect(livecheck.package_or_resource_name(f, full_name: true)).to eq("test")
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
|
2024-08-23 03:15:57 +01:00
|
|
|
it "returns the token of a cask" do
|
|
|
|
expect(livecheck.package_or_resource_name(c)).to eq("test")
|
2020-09-02 12:24:21 -07:00
|
|
|
end
|
|
|
|
|
2024-08-23 03:15:57 +01:00
|
|
|
it "returns the full name of a cask" do
|
|
|
|
expect(livecheck.package_or_resource_name(c, full_name: true)).to eq("test")
|
2020-09-02 12:24:21 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
describe "::status_hash" do
|
2022-08-07 20:47:17 +02:00
|
|
|
it "returns a hash containing the livecheck status for a formula" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.status_hash(f, "error", ["Unable to get versions"]))
|
2020-08-08 07:10:48 +05:30
|
|
|
.to eq({
|
2021-02-11 13:24:19 +00:00
|
|
|
formula: "test",
|
|
|
|
status: "error",
|
|
|
|
messages: ["Unable to get versions"],
|
|
|
|
meta: {
|
livecheck: clarify livecheckable language
Formulae, casks, and resources have a `#livecheckable?` method that
indicates whether they contain a `livecheck` block. This is intended
to be read as "has a livecheckable?", not "is livecheckable?" (as
livecheck can find versions for some packages/resources without a
`livecheck` block). Unfortunately, correct understanding of this
method's behavior [outside of documentation] relies on historical
knowledge that few people possess, so this is often confusing to
anyone who hasn't been working on livecheck since 2020.
In the olden days, a "livecheckable" was a Ruby file containing a
`livecheck` block (originally a hash) with a filename that
corresponded to a related formula. The `livecheck` blocks in
livecheckable files were integrated into their respective formulae in
August 2020, so [first-party] livecheckables ceased to exist at that
time. From that point forward, we simply referred to these as
`livecheck` blocks.
With that in mind, this clarifies the situation by replacing
"livecheckable" language. This includes renaming `#livecheckable?` to
`#livecheck_defined?`, replacing usage of "livecheckable" as a noun
with "`livecheck` block", replacing "livecheckable" as a boolean with
"livecheck_defined", and replacing incorrect usage of "livecheckable"
as an adjective with "checkable".
2024-11-27 18:20:56 -05:00
|
|
|
livecheck_defined: true,
|
2021-02-11 13:24:19 +00:00
|
|
|
},
|
|
|
|
})
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
2022-08-07 21:49:16 +02:00
|
|
|
|
2022-08-07 20:47:17 +02:00
|
|
|
it "returns a hash containing the livecheck status for a resource" do
|
|
|
|
expect(livecheck.status_hash(r, "error", ["Unable to get versions"]))
|
|
|
|
.to eq({
|
2022-08-07 21:49:16 +02:00
|
|
|
resource: "foo",
|
2022-08-07 20:47:17 +02:00
|
|
|
status: "error",
|
|
|
|
messages: ["Unable to get versions"],
|
|
|
|
meta: {
|
livecheck: clarify livecheckable language
Formulae, casks, and resources have a `#livecheckable?` method that
indicates whether they contain a `livecheck` block. This is intended
to be read as "has a livecheckable?", not "is livecheckable?" (as
livecheck can find versions for some packages/resources without a
`livecheck` block). Unfortunately, correct understanding of this
method's behavior [outside of documentation] relies on historical
knowledge that few people possess, so this is often confusing to
anyone who hasn't been working on livecheck since 2020.
In the olden days, a "livecheckable" was a Ruby file containing a
`livecheck` block (originally a hash) with a filename that
corresponded to a related formula. The `livecheck` blocks in
livecheckable files were integrated into their respective formulae in
August 2020, so [first-party] livecheckables ceased to exist at that
time. From that point forward, we simply referred to these as
`livecheck` blocks.
With that in mind, this clarifies the situation by replacing
"livecheckable" language. This includes renaming `#livecheckable?` to
`#livecheck_defined?`, replacing usage of "livecheckable" as a noun
with "`livecheck` block", replacing "livecheckable" as a boolean with
"livecheck_defined", and replacing incorrect usage of "livecheckable"
as an adjective with "checkable".
2024-11-27 18:20:56 -05:00
|
|
|
livecheck_defined: true,
|
2022-08-07 20:47:17 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
|
2021-01-12 15:00:49 -05:00
|
|
|
describe "::livecheck_url_to_string" do
|
|
|
|
let(:f_livecheck_url) do
|
2022-08-24 23:52:40 +01:00
|
|
|
homepage_url_s = homepage_url
|
|
|
|
stable_url_s = stable_url
|
|
|
|
head_url_s = head_url
|
2022-09-25 02:06:23 +02:00
|
|
|
resource_url_s = resource_url
|
2022-08-24 23:52:40 +01:00
|
|
|
|
2022-08-07 20:52:46 +02:00
|
|
|
formula("test_livecheck_url") do
|
|
|
|
desc "Test Livecheck URL formula"
|
2022-08-24 23:52:40 +01:00
|
|
|
homepage homepage_url_s
|
|
|
|
url stable_url_s
|
|
|
|
head head_url_s
|
2022-08-07 21:30:56 +02:00
|
|
|
|
2022-08-07 20:52:46 +02:00
|
|
|
resource "foo" do
|
2022-09-25 02:06:23 +02:00
|
|
|
url resource_url_s
|
2022-08-07 20:52:46 +02:00
|
|
|
sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
|
|
|
|
|
|
|
livecheck do
|
|
|
|
url "https://brew.sh/test/releases"
|
|
|
|
regex(/foo[._-]v?(\d+(?:\.\d+)+)\.t/i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-07 21:49:16 +02:00
|
|
|
let(:r_livecheck_url) { f_livecheck_url.resources.first }
|
2022-08-07 20:52:46 +02:00
|
|
|
|
2021-01-12 15:00:49 -05:00
|
|
|
let(:c_livecheck_url) do
|
|
|
|
Cask::CaskLoader.load(+<<-RUBY)
|
|
|
|
cask "test_livecheck_url" do
|
|
|
|
version "0.0.1,2"
|
|
|
|
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://brew.sh/test-0.0.1.dmg"
|
2021-01-12 15:00:49 -05:00
|
|
|
name "Test"
|
|
|
|
desc "Test Livecheck URL cask"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2022-09-27 00:18:20 -04:00
|
|
|
it "returns a URL string when given a livecheck_url string for a formula" do
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(livecheck_url, f_livecheck_url)).to eq(livecheck_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
|
2022-09-27 00:18:20 -04:00
|
|
|
it "returns a URL string when given a livecheck_url string for a resource" do
|
2022-08-07 20:52:46 +02:00
|
|
|
expect(livecheck.livecheck_url_to_string(livecheck_url, r_livecheck_url)).to eq(livecheck_url)
|
|
|
|
end
|
|
|
|
|
2021-01-12 15:00:49 -05:00
|
|
|
it "returns a URL symbol when given a valid livecheck_url symbol" do
|
2022-08-24 23:52:40 +01:00
|
|
|
expect(livecheck.livecheck_url_to_string(:head, f_livecheck_url)).to eq(head_url)
|
|
|
|
expect(livecheck.livecheck_url_to_string(:homepage, f_livecheck_url)).to eq(homepage_url)
|
|
|
|
expect(livecheck.livecheck_url_to_string(:homepage, c_livecheck_url)).to eq(homepage_url)
|
|
|
|
expect(livecheck.livecheck_url_to_string(:stable, f_livecheck_url)).to eq(stable_url)
|
|
|
|
expect(livecheck.livecheck_url_to_string(:url, c_livecheck_url)).to eq(cask_url)
|
2022-09-25 02:06:23 +02:00
|
|
|
expect(livecheck.livecheck_url_to_string(:url, r_livecheck_url)).to eq(resource_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when not given a string or valid symbol" do
|
2024-10-24 09:00:18 -04:00
|
|
|
error_text = "`url :%<symbol>s` does not reference a checkable URL"
|
|
|
|
|
|
|
|
# Invalid symbol in any context
|
|
|
|
expect { livecheck.livecheck_url_to_string(:invalid_symbol, f_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:invalid_symbol, c_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:invalid_symbol, r_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol))
|
|
|
|
|
|
|
|
# Valid symbol in provided context but referenced URL is not present
|
|
|
|
expect { livecheck.livecheck_url_to_string(:head, f_stable_url_only) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :head))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:homepage, f_stable_url_only) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :homepage))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:homepage, c_no_checkable_urls) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :homepage))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:url, c_no_checkable_urls) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :url))
|
|
|
|
|
|
|
|
# Valid symbol but not in the provided context
|
|
|
|
expect { livecheck.livecheck_url_to_string(:head, c_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :head))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:homepage, r_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :homepage))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:stable, c_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :stable))
|
|
|
|
expect { livecheck.livecheck_url_to_string(:url, f_livecheck_url) }
|
|
|
|
.to raise_error(ArgumentError, format(error_text, symbol: :url))
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
describe "::checkable_urls" do
|
2022-08-07 21:49:16 +02:00
|
|
|
let(:resource_url) { "https://brew.sh/foo-1.0.tar.gz" }
|
|
|
|
let(:f_duplicate_urls) do
|
|
|
|
formula("test_duplicate_urls") do
|
|
|
|
desc "Test formula with a duplicate URL"
|
|
|
|
homepage "https://github.com/Homebrew/brew.git"
|
|
|
|
url "https://brew.sh/test-0.0.1.tgz"
|
|
|
|
head "https://github.com/Homebrew/brew.git"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
it "returns the list of URLs to check" do
|
2021-02-04 15:41:29 -05:00
|
|
|
expect(livecheck.checkable_urls(f)).to eq([stable_url, head_url, homepage_url])
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.checkable_urls(c)).to eq([cask_url, homepage_url])
|
2022-08-07 21:10:10 +02:00
|
|
|
expect(livecheck.checkable_urls(r)).to eq([resource_url])
|
2021-08-13 16:29:06 -04:00
|
|
|
expect(livecheck.checkable_urls(f_duplicate_urls)).to eq([stable_url, head_url])
|
2024-10-24 22:19:18 -04:00
|
|
|
expect(livecheck.checkable_urls(f_stable_url_only)).to eq([stable_url])
|
|
|
|
expect(livecheck.checkable_urls(c_no_checkable_urls)).to eq([])
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-23 23:22:41 -05:00
|
|
|
describe "::use_homebrew_curl?" do
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
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
|
2022-08-07 21:30:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
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"
|
2022-12-13 10:54:22 +00:00
|
|
|
regex(/"stable":"(\d+(?:.\d+)+)"/i)
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
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
|
2021-11-23 23:22:41 -05:00
|
|
|
expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false)
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
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)
|
2021-11-23 23:22:41 -05:00
|
|
|
expect(livecheck.use_homebrew_curl?(c, livecheck_url)).to be(false)
|
Livecheck: Use Homebrew curl based on root domain
At the moment, `#use_homebrew_curl?` can only be true for a
`homepage` or `stable`/cask `url` with `using: :homebrew_curl`. If
the checked URL differs from these URLs, livecheck won't use brewed
curl. This limitation prevents livecheck from using brewed curl for a
`livecheck` block URL that's a string literal (not a symbol for a
`#checkable_url` like `:stable`, `:head`, `:url`). `libzip` was the
original formula referenced in the related brew issue and it meets
this criterion, so it doesn't appear to be handled by the existing
`#use_homebrew_curl?` implementation.
Additionally, the existing behavior can cause livecheck to
unnecessarily use brewed curl for a completely different website
(e.g., `cubelib`, `otf2`). For example, if the `stable` URL has
`using: :homebrew_curl` and the `livecheck` block has `url
:homepage`, livecheck will use brewed curl when checking the
`homepage`. If these are completely different domains/servers, it's
unlikely that we would need to use brewed curl when checking the
`homepage`, so this particular behavior may not be beneficial.
This commit reimplements `use_homebrew_curl?` to apply brewed curl
when the checked URL's root domain is the same as the root domain of
an aforementioned formula/cask URL with `using: :homebrew_curl`. For
example, this looser approach would allow a `livecheck` block
checking `https://www.example.com/downloads/` to use brewed curl if
the `stable` URL was `https://downloads.example.com/example.zip` with
`using: :homebrew_curl`. These could be different servers but, based
on related formulae, this looseness is necessary for the moment.
This approach aims to resolve both issues, allowing brewed curl to be
applied to a slightly broader range of URLs (i.e., not limited to
just the `#checkable_urls`) while also helping to avoid unnecessarily
applying brewed curl when it's less likely to be useful (completely
different domains). Neither approach is perfect but this one may be
more useful in the interim time.
Depending on how this looser approach works in practice, we may want
to consider returning to a stricter approach once we have something
like `using: :homebrew_curl` in `livecheck` blocks (this is
forthcoming). Being explicit in a `livecheck` block is the most
reliable approach (i.e., only use brewed curl when needed), so we
could favor that and pare down the automated approach to only what's
needed to support implicit checks (i.e., with no `livecheck` block).
Of course, it's also possible to drop the automated approach entirely
and simply require a `livecheck` block in this scenario but we can
decide on how to handle this when the time comes.
2022-05-18 16:40:30 -04:00
|
|
|
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)
|
2021-11-23 23:22:41 -05:00
|
|
|
end
|
|
|
|
end
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|