67 Commits

Author SHA1 Message Date
Sam Ford
98f3258ff4
Livecheck: Add Crate strategy
We discussed the idea of adding a livecheck strategy to check crate
versions years ago but decided to put it off because it would have
only applied to one formula at the time (and it wasn't clear that a
crate was necessary in that case). We now have a few formulae that
use a crate in the `stable` URL (`cargo-llvm-cov`, `pngquant`,
`oakc`) and another formula with a crate resource (`deno`), so
there's some value to the idea now.

I established a standard approach for checking crate versions in a
somewhat recent `pngquant` `livecheck` block update and this commit
reworks it into a strategy, so we won't have to duplicate that
`livecheck` block in these cases. With this strategy, we usually
won't even need a `livecheck` block at all.

Under normal circumstances, a regex and/or strategy block shouldn't
be necessary but the strategy supports them when needed. The response
from the crates.io API is a JSON object, so this uses
`Json#versions_from_content` internally and a `strategy` block will
receive the parsed `json` object and a regex (the strategy default or
the regex from the `livecheck` block).
2024-02-11 21:53:21 -05:00
Issy Long
f682147598
Fix RuboCop Style/RedundantFreeze offenses 2024-01-18 22:20:01 +00:00
Sam Ford
104d30d231
Finish renaming GithubRelease to GithubReleases 2023-05-16 16:08:18 -04:00
Sean Molenaar
5139b9b468
feat: add github_release strategy 2023-05-16 14:18:22 -04:00
Sam Ford
bcddf99838
Strategy: Pass --max-redirs to #curl_headers
The default curl args in `#curl_headers` cover most of
`Livecheck::Strategy::DEFAULT_CURL_ARGS` but `--max-redirs` was
overlooked. This adds an explicit `--max-redirs` argument in
the `#page_headers` `#curl_headers` call but it's worth mentioning
that this approach wouldn't benefit from any changes in
`DEFAULT_CURL_ARGS` and would need to be manually kept in parity.
2023-05-15 13:14:13 -04:00
Markus Reiter
e493d0cb04
Rescue ErrorDuringExecution instead of changing curl_headers return type. 2023-05-09 07:25:00 +02:00
Sam Ford
16f3a05e45
Strategy#page_headers: Update for #curl_headers
`#curl_headers` was recently introduced into `Strategy#page_headers`
but only the call was modified and the method wasn't updated to
correctly work with the new return value, so all `HeaderMatch` checks
immediately started failing with an error.

This commit includes changes that return `#page_headers` to a working
state. I've removed the `result.assert_success!` call because it
prevents a few checks from being retried with `GET` (`firefox-cn`,
`krisp`, `prepros`).
2023-05-08 23:08:05 -04:00
Markus Reiter
353818f508
Rename curl_head to curl_headers. 2023-05-06 03:41:35 +02:00
Markus Reiter
545a332fef
Use curl_head and curl_output for Livecheck strategies. 2023-05-06 03:40:09 +02:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Douglas Eichelberger
6397229f68 Enable types in extensions, etc. 2023-04-01 18:56:42 -07:00
Mike McQuaid
ec15acf7dc
Revert "Remove --request GET workaround for HEAD requests." 2023-03-31 09:07:02 +01:00
Markus Reiter
c876530eff
Remove --request GET workaround for HEAD requests. 2023-03-30 05:02:51 +02:00
Douglas Eichelberger
544960b4fc Replace String#underscore with util 2023-03-07 10:13:38 -08:00
Sam Ford
33268e4fb0
livecheck: Add Yaml strategy
This adds a generic `Yaml` strategy to livecheck that requires a
`strategy` block to operate. The YAML-parsing code is taken from the
existing approach in the `ElectronBuilder` strategy.

We don't currently have any `strategy` blocks in first-party taps
that manually parse YAML. However, creating a generic `Yaml` strategy
allows us to simplify `ElectronBuilder` (and any future strategy
that works with YAML) while making it easy to create custom `Yaml`
`strategy` blocks in formulae/casks as needed.
2023-03-02 16:20:39 -05:00
Sam Ford
7d9e1a50e8
livecheck: Add Xml strategy
This adds a generic `Xml` strategy to livecheck that requires a
`strategy` block to operate. The XML-parsing code is taken from the
existing approach in the `Sparkle` strategy. As such, `Sparkle` has
been updated to use the `Xml#parse_xml` method instead.

Unlike the `Json` strategy, we don't currently have any `strategy`
blocks in first-party taps that manually parse XML. However, we had a
user request support for something like this and I was already working
on an `Xml` strategy (as a way of extracting the XML-parsing code
from `Sparkle` into something general-purpose), so here we are.

Future strategies that parse simple XML data can potentially use the
`Xml#find_versions` method (similar to how we have strategies that
leverage `PageMatch#find_versions`) instead of having to implement
something bespoke like `Sparkle`.
2023-02-28 14:58:11 -05:00
Sam Ford
ec7fd75934
Strategy#from_url: Replace #from_symbol call
Passing the strategy symbol into the `#from_url` `select` block
means that we can also get rid of a `#from_symbol` call in a
different conditional branch, as we can directly compare the
`livecheck_strategy` symbol to `strategy_symbol`.
2023-02-27 18:58:15 -05:00
Sam Ford
03823b5698
Strategy#from_url: Amend conditions for Json
When the `Json` strategy was introduced, I forgot to also ensure
that it's only treated as usable (in `Strategy#from_url`) if a
`livecheck` block uses `strategy :json`. As a result, `Json` is
incorrectly treated as a usable strategy for all formulae/casks that
contain a `strategy` block.

Since all of these `livecheck` blocks specify a strategy, this bug
doesn't meaningfully impact livecheck's behavior (i.e., these checks
continue to use their explicitly-specified strategy). The only
practical difference is that `Json` incorrectly appears in the list
of usable strategies in livecheck's verbose JSON output.

This commit modifies `Strategy#from_url` to address this issue. The
easiest way to enforce this rule involved passing in the
`@strategies` key (a symbol) into the `select` block, so we can
compare it to `livecheck_strategy` (the strategy symbol specified in
the `livecheck` block).
2023-02-27 18:58:13 -05:00
Sam Ford
7735036c56
livecheck: Add Json strategy
This adds a generic `Json` strategy to livecheck that requires a
`strategy` block to operate. This is primarily intended as a
replacement for existing `strategy` blocks in formulae/casks that
use `JSON#parse`, as it allows us to internalize/standardize that
boilerplate while improving error-handling.

Additionally, future strategies that parse JSON data can use the
`Json#find_versions` method instead of having to reinvent the wheel
(similar to how we currently have a number of strategies that
leverage `PageMatch#find_versions`).
2023-02-23 13:17:35 -05:00
Sam Ford
ef5d8ed8b0
Strategy: Add --max-redirs to DEFAULT_CURL_ARGS
The default redirection maximum for `curl` is 50 but we should use
something more reasonable in livecheck. It's rare but a misconfigured
server with an endless redirection loop will hit the 50 redirection
limit. Unfortunately, we've encountered this in the wild (e.g., the
server for `getmail` and `memtester` endlessly redirects), so it's
not an idle concern. This commit basically adds `--max-redirs 5` to
`Livecheck::Strategy::DEFAULT_CURL_ARGS` to enforce a more reasonable
redirection maximum.

To be clear, the `max_iterations` logic in `#parse_curl_output`
(which was previously found in `Strategy#page_content`) doesn't
restrict the number of redirections that `curl` follows. At the point
the `curl` output is being parsed, the requests have already been
made and `max_iterations` simply restricts the number of responses
`#parse_curl_output` is willing to parse. If we use `--max-redirs`
and properly set `max_iterations` to `max-redirs + 1`, we shouldn't
encounter the "Too many redirects" error in `#parse_curl_output`.
2022-04-22 13:39:02 -04:00
Sam Ford
1c4faaa5d5
Strategy: Use Curl output parsing methods 2022-04-20 23:49:18 -04:00
Nanda H Krishna
4ff88385f8
brew typecheck --fix 2022-01-27 12:23:40 -05:00
Sam Ford
cb537eae52
Strategy: Add --silent flag to DEFAULT_CURL_ARGS
Currently, only `Livecheck::Strategy::PAGE_HEADERS_CURL_ARGS` uses
the `--silent` option and `PAGE_CONTENT_CURL_ARGS` does not (though
there's no intention behind this omission). However, the
`#page_content` method should also use the `--silent` flag, to
prevent progress bar text (`#=#=#`, etc.) from appearing in output.

This is an issue because the regex that's used to identify `curl`
error messages in `stderr` (`^curl:.+$/`) will fail if leading
progress bar text is present. This leads to an ambiguous "cURL
failed without a detectable error" message instead of the actual
error message(s) from `curl`.

This commit addresses the issue by adding `--silent` to
`Livecheck::Strategy::DEFAULT_CURL_ARGS`, which both
`PAGE_HEADERS_CURL_ARGS` and `PAGE_CONTENT_CURL_ARGS` inherit.
2022-01-10 11:59:07 -05:00
Rylan Polster
2e6b6ab3a2
Fix style 2021-12-24 21:15:21 -05:00
EricFromCanada
ed3042c37a
livecheck: use brewed curl if called for by download URL 2021-11-28 12:57:24 -05:00
Sam Ford
f88966a8a5
Use curl options where appropriate 2021-09-07 14:13:19 -04:00
Sam Ford
d44979fa67
Curl#curl_args: Fix and refactor options 2021-09-07 14:13:17 -04:00
Sam Ford
6b66ec9e62
Strategy: Improve curl error message finding
The existing regex wasn't able to match errors like:
  curl: option --something: is unknown

Additionally, the existing approach wouldn't capture multi-line
errors, whereas this captures all the `curl:` lines from `stderr`.
2021-09-07 00:15:08 -04:00
Sam Ford
8940d198fe
Make tarball extension regex explicit 2021-08-17 19:15:07 -04:00
Sam Ford
26821301e7
livecheck: move url/regex generation into methods 2021-08-17 18:03:40 -04:00
Sam Ford
c936a9420e
Improve documentation comments 2021-08-11 19:05:59 -04:00
Sam Ford
f2bd39ccef
Add additional method signatures to strategies 2021-08-11 19:05:59 -04:00
Sam Ford
56dd89114d
Standardize valid strategy block return types
Valid `strategy` block return types currently vary between
strategies. Some only accept a string whereas others accept a string
or array of strings. [`strategy` blocks also accept a `nil` return
(to simplify early returns) but this was already standardized across
strategies.]

While some strategies only identify one version by default (where a
string is an appropriate return type), it could be that a strategy
block identifies more than one version. In this situation, the
strategy would need to be modified to accept (and work with) an
array from a `strategy` block.

Rather than waiting for this to become a problem, this modifies all
strategies to standardize on allowing `strategy` blocks to return a
string or array of strings (even if only one of these is currently
used in practice). Standardizing valid return types helps to further
simplify the mental model for `strategy` blocks and reduce cognitive
load.

This commit extracts related logic from `#find_versions` into
methods like `#versions_from_content`, which is conceptually similar
to `PageMatch#page_matches` (renamed to `#versions_from_content`
for consistency). This allows us to write tests for the related code
without having to make network requests (or stub them) at this point.
In general, this also helps to better align the structure of
strategies and how the various `#find_versions` methods work with
versions.

There's still more planned work to be done here but this is a step
in the right direction.
2021-08-11 19:05:57 -04:00
Sam Ford
cf79ced740
Rework how strategy constants are identified
Up to this point, we've had to rely on making `Strategy` constants
private to ensure that the only available constants are strategies.
With the current setup, the existence of a constant that's not a
strategy would break `Strategy#strategies` and
`Livecheck#livecheck_strategy_names`.

Instead, we can achieve the same goal by skipping over constants
that aren't a class. Other than saving us from having to make these
constants private, this is necessary to be able to create a
`Strategy` constant that can be used in all strategies.
2021-08-11 18:25:34 -04:00
nthumann
e6a18803ea
Try getting page content with both headers 2021-06-10 00:12:26 +02:00
Sam Ford
a6769ae7cd
Strategy: Better align curl usage in methods 2021-06-04 16:16:06 -04:00
Sam Ford
793ea17749
Strategy: Create constant for HTTP separator 2021-06-04 16:16:06 -04:00
Sam Ford
ccfd01ba38
Strategy: Replace open-uri with curl 2021-06-04 16:16:05 -04:00
Markus Reiter
a210b1a04e
Add extract_plist strategy. 2021-04-07 04:58:31 +02:00
nandahkrishna
f422b6cdc4
livecheck/strategy: add ElectronBuilder strategy 2021-03-20 15:23:09 +05:30
Seeker
b9854bd4cf rubocops: add unless_multiple_conditions 2021-01-08 10:33:54 -08:00
Markus Reiter
bf7efb369c Fix Sparkle strategy. 2020-12-24 03:33:14 +01:00
Sam Ford
12afb272bb
Strategy: Manually handle redirections 2020-12-23 00:35:27 -05:00
Sam Ford
ac459f8e76
Strategy: Temporarily remove response caching
The simple approach here caches all header or body content from
responses, so memory usage continually grows with each fetch. This
becomes more of a notable issue with long livecheck runs (e.g.,
`--tap homebrew/core`).

Instead, we should only cache the header/body for URLs that we know
will be fetched more than once in a given run. Being able to
determine which URLs will be fetched more than once requires
structural changes within livecheck strategies, so this will take a
bit of work to implement.

I've been working on this off and on and I'll introduce a more
sophisticated method of livecheck-wide caching in a later PR. In the
interim time, it's best to remove this caching behavior until I've
finished working on an approach that provides benefits (reducing
duplicate fetches) while minimizing detriments (increased memory
usage).
2020-12-20 12:42:51 -05:00
Markus Reiter
91ee5e0a65 Simplify assignment of curl result. 2020-12-20 02:23:30 +01:00
Sam Ford
f299d3ea6e
Strategy#page_headers: Disable debug in curl 2020-12-19 19:34:28 -05:00
Sam Ford
7f40198506
Make Strategy#page_headers more general purpose 2020-12-19 19:34:26 -05:00
Sam Ford
1bd2be5e04
Rename page_contents to page_content 2020-12-19 19:34:25 -05:00
Sam Ford
a55686a0e2
Enforce strategy url requirement in latest_version 2020-12-19 19:34:25 -05:00
Markus Reiter
0fd0b1dad0
Actually cache headers. 2020-12-19 19:34:25 -05:00