190 Commits

Author SHA1 Message Date
Sam Ford
55ec4c483c
Crate: Rework conditions
Co-authored-by: Douglas Eichelberger <dduugg@gmail.com>
Co-authored-by: Markus Reiter <me@reitermark.us>
2024-02-11 21:53:21 -05:00
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
Douglas Eichelberger
eb7c3e52a0 Require SystemInclude only where needed 2024-01-31 11:42:01 -08:00
Douglas Eichelberger
f99d39faf9 Vendor CompactBlank cop 2024-01-26 15:03:59 -08:00
Douglas Eichelberger
df140b329f brew style --fix 2024-01-22 10:52:43 -08:00
Douglas Eichelberger
2e21efff46 Add ActiveSupport String#exclude? to extend/ 2024-01-19 13:35:34 -08:00
Issy Long
f682147598
Fix RuboCop Style/RedundantFreeze offenses 2024-01-18 22:20:01 +00:00
Douglas Eichelberger
caf8259ae6 Code review changes 2023-12-27 15:29:33 -08:00
Douglas Eichelberger
3abbf4447e Some minor regexp match perf improvements 2023-12-27 13:16:36 -08:00
Sam Ford
9bfe423a5a
Xml: Add #element_text method
This refactors verbose code in the `Sparkle` strategy where we access
element text into a reusable `Xml#element_text` method, replacing
chained calls like `item.elements["title"]&.text&.strip&.presence`
with `Xml.element_text(item, "title")`.

`#element_text` is only used to retrieve the text of a child element
in the `Sparkle` strategy but it can also retrieve the text from the
provided element if the `child_path` argument is omitted (i.e.,
`Xml.element_text(item)`). This will allow us to also avoid similar
calls like `item.text.strip.presence` in the future.
2023-11-17 22:34:12 -05:00
Sam Ford
75ce7240fc
Sparkle: Refactor macOS os strings into constant 2023-11-16 12:05:25 -05:00
Sam Ford
bc2ce97e5d
Sparkle: Move sorting/filtering into methods
We need to be able to replicate the `Sparkle` strategy's sorting
and filtering behavior in a related cask audit, so this extracts
the logic into reusable methods.

This also stores `item.minimum_system_version` as a `MacOSVersion`
object (instead of a string), so we can do proper version comparison
(instead of naive string comparison) wherever needed.
2023-11-16 12:05:24 -05:00
Sam Ford
4f469234d0
Sparkle: Ensure empty strings become nil
Sometimes appcasts contain empty elements/attributes and the `Item`
values end up as an empty string because of how they're handled in
`#items_from_content`. It's reasonable to expect that empty values
would be `nil` instead, so this adds `#presence` calls to ensure this
is the case.
2023-11-16 12:05:24 -05:00
Sam Ford
86c702abcd
Sparkle: Surface more Item values
Historically, the `Sparkle` strategy's `Item` struct has only
included basic values from the appcast that are commonly useful.
Over time we've selectively added/surfaced more values as we've
encountered outliers that require use of different values in a
`strategy` block.

We now need to use `minimumSystemValue`, so this expands the `Item`
struct to include any appcast value that we could conceivably want
to use in the future. This will hopefully save us from having to make
more modifications to the struct (and related tests) before we can
use a previously-unused value in a `strategy` block.
2023-10-28 14:55:47 -04:00
Bo Anderson
26ea6b7f9e
Pull in REXML gem as it doesn't ship with Ruby 3 2023-10-27 20:24:10 +01:00
Eric Knibbe
931f762598
docs+rubydoc: various grammar/wording fixes 2023-09-11 02:26:37 -04:00
Patrick Linnane
c56669e9cd
various: fix miscellaneous typos 2023-07-18 08:52:49 -07:00
Bo Anderson
54a1f2005a
livecheck: fix implicit no-api handling 2023-07-10 14:50:53 +01:00
Sam Ford
ba7cf9df7a
Bitbucket: Fix tag match
The `Bitbucket` strategy currently matches versions from tag
tarball links on a project's `downloads/?tab=tags` page. It appears
that Bitbucket now uses a hash as the filename on this page instead
of the tag name, so the existing regex no longer matches.

This adds an alternative regex to match versions from the tag name
element (e.g., `<td class="name">example-1.2.3</td>`), which will fix
version matching in this scenario.
2023-05-19 10:55:28 -04:00
Sam Ford
104d30d231
Finish renaming GithubRelease to GithubReleases 2023-05-16 16:08:18 -04:00
Sean Molenaar
940b63cad3
chore: rename GitHubRelease to GitHubReleases 2023-05-16 14:19:01 -04:00
Sam Ford
a2fb2b00fd
GithubRelease: Simplify block handling
The `#versions_from_content` method requires a regex and this will be
enforced by the type signature, so we don't have to check for the
presence of a regex when handling a `strategy` block.
2023-05-16 14:18:23 -04:00
Sam Ford
263f486806
GithubRelease: Add #generate_input_values method
Keeping the logic for generating the API URL in a method makes it
testable, aligns with other strategies, and will help to enable some
future work.
2023-05-16 14:18:23 -04:00
Sam Ford
701f7c5051
GithubRelease: Update type signature 2023-05-16 14:18:23 -04:00
Sam Ford
8a0f63e728
GithubRelease: Omit unnecessary prefix 2023-05-16 14:18:22 -04:00
Sam Ford
a29b5c34d2
GithubRelease: Rework documentation comments
The initial documentation comments contained some remaining text
referring to `GithubLatest` and hadn't been updated to incorporate
the recent changes to the aforementioned strategy. This also reworks
some of the language to better explain the strategy's function,
application, etc.
2023-05-16 14:18:22 -04:00
Sam Ford
1dd7556c74
GithubLatest: Tweak documentation comments 2023-05-16 14:18:22 -04:00
Sean Molenaar
5139b9b468
feat: add github_release strategy 2023-05-16 14:18:22 -04:00
Markus Reiter
8274920217
Rename OS::Mac::Version to MacOSVersion. 2023-05-09 05:08:38 +02:00
Sam Ford
efccc5d4bb
GithubLatest: Update documentation 2023-05-08 17:21:19 +02:00
Sam Ford
303ac147a9
GithubLatest: Include URL in match_data
It's standard for the `match_data` to include the URL (e.g., as in
`PageMatch`). This uses the provided URL by default, switching to the
generated URL when available.
2023-05-07 10:21:48 +02:00
Sam Ford
cfba45fb56
GithubLatest: Use API URL as generated value
The generated URL should reflect what we're actually checking, which
is now the `/releases/latest` API URL.
2023-05-07 10:21:48 +02:00
Sam Ford
34e2779150
GithubLatest: Move #generate_input_values
`#generate_input_values` is called before `#versions_from_content`
(in `#find_versions`), so it makes sense to move it above the latter.
2023-05-07 10:21:48 +02:00
Sean Molenaar
573d87cdfa
feat: use API for GitHub latest release strategy 2023-05-07 10:21:48 +02:00
Sam Ford
a2e966c186
Xml: Move require outside of #parse_xml
Since we use `REXML::Document` in the type signature for `#parse_xml`,
we can encounter an `uninitialized constant
Homebrew::Livecheck::Strategy::Xml::REXML` error in strategies like
`Sparkle` that use `Xml#parse_xml` internally when the Sorbet runtime
is used. Moving the related require outside of the `#parse_xml` method
and into the `Xml` strategy proper resolves this issue.
2023-04-29 10:16:47 -04:00
Sam Ford
6597ee6fd3
Sparkle: Account for nil content value
`content` can be `nil` when a request doesn't succeed but
`#versions_from_content` expects a `String` value, so we need to
guard against a `nil` value like we do in other strategies.
2023-04-29 10:16:47 -04:00
Sam Ford
1c03018b6a
Launchpad: Use DEFAULT_REGEX as default regex arg
Using `DEFAULT_REGEX` as the default value of the `#find_versions`
`regex` parameter allows us to tighten the type.
2023-04-29 10:16:46 -04:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Douglas Eichelberger
47ffcd5cb7 Add types to block params 2023-04-04 22:42:27 -07:00
Douglas Eichelberger
f3a8241e69 Remove useless T.unsafe wrappers 2023-04-03 17:34:39 -07:00
Mike McQuaid
066a8afe61
Merge pull request #14868 from samford/livecheck/add-yaml-strategy
livecheck: Add Yaml strategy
2023-03-04 00:06:11 +00:00
Sam Ford
74370fe604
ElectronBuilder: Update to use Yaml#find_versions
This updates `ElectronBuilder` to use `Yaml#find_versions`, as the
only code unique to that strategy is to restrict regex usage and
use default version-finding logic when a `strategy` block isn't
provided. This is similar to how we have various strategies that
use `PageMatch#find_versions` internally.

This allows us to remove `ElectronBuilder#versions_from_content`
entirely, along with the related tests. I've added support for
`provided_content` to `ElectronBuilder#find_versions` as a way of
adding tests and maintaining code coverage.
2023-03-02 16:23:32 -05: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
7f0a735828
Json: Fix a whitespace oversight in comment 2023-03-01 17:27:33 -05:00
Sam Ford
cebb951baf
Json: Add #parse_json method
This setup mimics the `#parse_xml` method that was implemented in the
`Xml` strategy. Isolating the parsing code means that other strategies
can take only what they need from `Json` (i.e., it's not required for
them to use `Json#find_versions`).
2023-03-01 17:27:33 -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
Douglas Eichelberger
f9f73f3ef6 Tidy up 2023-02-27 21:42:47 -08:00
Douglas Eichelberger
1ab278f74c Fix style/type violations 2023-02-27 20:34:07 -08:00
Douglas Eichelberger
0eccc0e987 git grep -l Utils::Inflection | xargs gsed -i 's|Utils::Inflection|Utils|g' 2023-02-27 20:18:27 -08:00
Douglas Eichelberger
cfdb0c2e4b Fix type error 2023-02-27 20:18:10 -08:00