48 Commits

Author SHA1 Message Date
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
Markus Reiter
c306577575
Skip Sparkle strategy only if URL is not specified explicitly. 2020-12-19 19:34:24 -05:00
Markus Reiter
605c33c70c
Improve matching of Sparkle strategy. 2020-12-19 19:34:21 -05:00
Markus Reiter
347a58f164
Don't skip Sparkle strategy if explicitly specified. 2020-12-19 19:34:20 -05:00
Markus Reiter
cf40f7b8f6
Rename FollowRedirection to HeaderMatch. 2020-12-19 19:34:20 -05:00
Markus Reiter
8b7f38faf0
Fix code style. 2020-12-19 19:34:19 -05:00
Markus Reiter
b9741dd1e6
Try getting headers with both user agents. 2020-12-19 19:34:19 -05:00
Markus Reiter
0fe3bf7c7f
Only use Sparkle strategy if URL is specified explicitly. 2020-12-19 19:34:19 -05:00
Markus Reiter
10b5548eac
Fix page_headers method for multiple headers. 2020-12-19 19:34:17 -05:00
Markus Reiter
c24af82a25
Add Sparkle livecheck strategy. 2020-12-19 19:34:17 -05:00
Markus Reiter
b293acc89b
Add FollowRedirection livecheck strategy. 2020-12-19 19:34:16 -05:00
Markus Reiter
f5d311490c
Add page_headers and page_contents helpers. 2020-12-19 19:34:16 -05:00
Dario Vladovic
1f30f27c2d
livecheck: CPAN strategy 2020-12-11 17:43:09 -05:00
Sam Ford
524272aed0
Livecheck: Rework non-positive PRIORITY handling 2020-12-05 11:49:47 -05:00
nandahkrishna
f96b8e7138
livecheck: add GithubLatest strategy 2020-12-05 20:37:27 +05:30
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
nandahkrishna
f520301180
livecheck migration: add strategies
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
Co-authored-by: Thierry Moisan <thierry.moisan@gmail.com>
Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
Co-authored-by: Maxim Belkin <maxim.belkin@gmail.com>
Co-authored-by: Issy Long <me@issyl0.co.uk>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Co-authored-by: Seeker <meaningseeking@protonmail.com>
2020-08-27 20:00:30 +05:30