136 Commits

Author SHA1 Message Date
Mike McQuaid
77c0d38c35
brew style --fix 2022-12-13 11:37:06 +00:00
Sam Ford
e56735a171
ElectronBuilder: Allow Date/Time deserialization
The `ElectronBuilder` strategy uses `YAML#safe_load` to parse YAML
content and this limits deserialization to appropriate classes. We
recently encountered a `Tried to load unspecified class: Time` error
when using the `ElectronBuilder` strategy on a `latest-mac.yml` file
containing `releaseDate: 2022-12-01T02:02:46.419Z`.

The electron-builder YAML files we usually encounter use single
quotes around the `releaseDate` value to ensure it's treated as a
string (e.g., `releaseDate: '2022-10-12T17:55:26.718Z'`) and this is
what we do in `electron_builder_spec.rb`. The aforementioned YAML
file doesn't use single quotes around the value, so it's treated as
a timestamp and apparently this makes Psych use `Time` (which
`#safe_load` doesn't allow by default).

Seeing as we can't control the YAML content and there's a chance we
may encounter other files like this in the future, this commit
modifies the related `#safe_load` call to allow `Time` (and `Date`
for good measure). This will resolve the aforementioned error and
allow the `ElectronBuilder` strategy to work as expected in this
scenario.
2022-12-05 21:45:18 -05:00
Tim Visher
fc31d5560c livecheck/strategy/sparkle.rb: Add macos to the candidate os values list
As can be seen by TextExpander's Sparkle Feed, `macos` is a possible
value.

```
$ date -u '+%FT%T%z' && xmlstarlet sel -t -v '//rss//channel//item//enclosure/@*[name()="url" or name()="sparkle:version" or name()="sparkle:shortVersionString" or name()="sparkle:os"]' <(curl --location --silent https://textexpander.com/appcast/TextExpander-macOS.xml)
2022-10-22T17:07:06+0000
https://cdn.textexpander.com/mac/731.2/TextExpander_7.3.1.dmg
731.2
7.3.1
macos
https://cdn.textexpander.com/mac/720.16/TextExpander_7.2.dmg
720.16
7.2
macos
https://cdn.textexpander.com/mac/710.6/TextExpander_7.1.dmg
710.6
7.1
macos
https://cdn.textexpander.com/mac/702.2/TextExpander_7.0.2.dmg
702.2
7.0.2
macos
https://cdn.textexpander.com/mac/701.2/TextExpander_7.0.1.dmg
701.2
7.0.1
macos
https://cdn.textexpander.com/mac/700.33/TextExpander_7.0.dmg
700.33
7.0
macos
https://cdn.textexpander.com/mac/685.6/TextExpander_6.8.5.zip
685.6
6.8.5
https://cdn.textexpander.com/mac/684.8/TextExpander_6.8.4.zip
684.8
6.8.4
https://cdn.textexpander.com/mac/683.2/TextExpander_6.8.3.zip
683.2
6.8.3
https://cdn.textexpander.com/mac/682.10/TextExpander_6.8.2.zip
682.10
6.8.2
https://cdn.textexpander.com/mac/681.3/TextExpander_6.8.1.zip
681.3
6.8.1
https://cdn.textexpander.com/mac/680.30/TextExpander_6.8.zip
680.30
6.8
https://cdn.textexpander.com/mac/TextExpander_6.5.6.zip
656.3
6.5.6
https://cdn.textexpander.com/mac/TextExpander_6.5.5.zip
655.0
6.5.5
https://cdn.textexpander.com/mac/TextExpander_6.5.4.zip
654.3
6.5.4
https://cdn.textexpander.com/mac/TextExpander_6.5.3.zip
653.3
6.5.3
https://cdn.textexpander.com/mac/TextExpander_6.5.2.zip
652.0
6.5.2
https://smilesoftware.com/downloads/test/TextExpander_6.5.1.zip
651.5
6.5.1
```

Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
2022-12-04 14:21:27 -05:00
Bo Anderson
eac32f0b20
Additional fixes for Ruby 3 compatibility 2022-10-18 01:54:59 +01:00
Issy Long
b7d997e80d
sorbet: Bump some files from typed: false to typed: true
- This was done with `brew typecheck --update --suggest-typed` which
  (as of the previous commit) uses Spoom, yet another gem. I thought I'd
  see how well it works. There are no Sorbet errors after these changes!
2022-10-11 01:09:03 +01:00
Sam Ford
d7a26cd6d3
ExtractPlist: Modify #find_versions url usage 2022-06-24 00:08:53 -04:00
Sam Ford
077fb350a5
ExtractPlist: Add url to #find_versions object 2022-06-24 00:08:53 -04:00
Bevan Kay
916c980676
livecheck: allow custom url in extract_plist strategy 2022-06-24 00:08:53 -04:00
Bo Anderson
f5dc7a571f
Fix Style/ObjectThen offences 2022-06-17 19:47:55 +01:00
Sam Ford
5930880920
Gnome: Update default regex and version filtering
The `Gnome` strategy's default regex uses the `+` form of the standard
regex for matching versions like 1.2.3. However, with the switch to
the new version scheme, some packages had a release that omits a
minor and patch (i.e., `40` instead of `40.0`). The default regex
fails to match versions like this but the looser `*` form will match
both. [When creating regexes, we generally start with the `+` form
and only switch to the looser `*` form when it's necessary and
contextually-appropriate.]

This also updates the default version filtering logic that's applied
to versions using the old GNOME version scheme (below version 40).
Outside of the refactoring changes, this also filters out versions
where the patch number is 90+, as these are also unstable.
2022-06-13 18:17:56 -04:00
Sam Ford
d600b662e2
Expand documentation comments 2022-06-10 18:25:25 -04:00
Sam Ford
590aabe9d7
livecheck: update default match_data
This updates these strategies to better align with the default
`match_data` value in other strategies.
2022-06-10 18:25:25 -04:00
Sam Ford
a909be581b
Merge pull request #13387 from samford/livecheck/git-use-system_command
Git: Use system_command instead of Open3.capture3
2022-06-07 14:14:53 -04:00
Sam Ford
64a7c1f821
Git: Remove tags_only_debian logic
The `tags_only_debian` code in livecheck's `Git` strategy was
originally introduced in Homebrew/homebrew-livecheck#131 when
livecheck was in a less mature state and relied more on internal
special-casing like this (i.e., while we worked to add appropriate
`livecheck` blocks). This logic only has the potential to be
beneficial when a formula/cask doesn't contain a `livecheck` block
but I would argue that we shouldn't be making assumptions in the
strategy around whether tags with a `debian/` prefix should be
matched or omitted. The answer depends upon the context of a given
formula/cask and should be handled with a `livecheck` block, as we
do with other situations like this.
2022-06-07 09:02:03 -04:00
Sam Ford
bdd35efed8
Git: Use system_command instead of Open3.capture3
In a past discussion, it was preferred that we use `system_command`
in livecheck's `Git` strategy instead of `Open3.capture3` but it
wasn't feasible at the time because we couldn't prevent
`#system_command` from printing certain output. I resolved the
`SystemCommand` shortcoming long ago in Homebrew/brew#10066, so this
finally migrates the `Git` strategy to `system_command`.
2022-06-06 12:14:40 -04:00
Sam Ford
c6907f911f
Sparkle: Provide channel information in Item
Making `channel` information available in the `Item` is necessary
to be able to filter out unstable items using a `strategy` block. If
an item doesn't specify a channel, then it uses the default channel
(this is what Sparkle itself uses for updates). Channels like `beta`
are something we want to avoid for stable casks and this allows for
that type of [cask-specific] filtering.

It's technically possible to automatically filter out items that
aren't using the default channel (i.e., `channel != nil`) in
`#items_from_content` but some casks use an unstable version, so we
can't do this internally. That is to say, we wouldn't be able to
override internal filtering in a `strategy` block, as any omitted
items wouldn't be provided to the block. Conversely, if we pass all
items to a `strategy` block, we can easily filter by channel there.
We haven't been filtering by channel internally and we've only found
one cask where this has been a problem, so it seems fine for now.
2022-06-02 10:35:00 -04:00
Sam Ford
b4cb47815f
Sparkle: Pass all items into strategy block
It's sometimes necessary to work with all the items in a Sparkle feed
to be able to correctly identify the newest version but livecheck's
`Sparkle` strategy only passes the `item` it views as newest into a
`strategy` block.

This updates the `Sparkle` strategy to optionally pass all items into
a `strategy` block, so we can manipulate them (e.g., filtering,
sorting). This is enabled by naming the first argument of the
strategy block `items` instead of `item`. `Sparkle` `strategy` blocks
where the first argument is `item` will continue to work as expected.

This necessarily updates `#item_from_content` (now
`items_from_content`) to return all items. I've decided to move the
sorting out of `#items_from_content`, so it simply returns the items
in the order they appear. If there is ever an exceptional situation
where we need the original order, this will technically allow for it.

The sorting has instead been moved into the `#versions_from_content`
method, to maintain the existing behavior. I thought about passing
the items into the `strategy` block in their original order but it
feels like sorting by default is the better approach for now (partly
from the perspective of maintaining existing behavior) and we can
always revisit this in the future if a cask ever requires the
original order.

Lastly, this expands the `Sparkle` tests to increase coverage. The
only untested parts are `#find_versions` (which currently
requires a network request) and a couple safeguard `raise` calls
when there's a `REXML::UndefinedNamespaceException` (which shouldn't
be encountered unless something is broken).
2022-06-01 18:29:37 -04:00
EricFromCanada
ed3042c37a
livecheck: use brewed curl if called for by download URL 2021-11-28 12:57:24 -05:00
Sam Ford
f8ded0a435
PageMatch: Enforce requirements in #find_versions
This aligns `PageMatch` with how cask strategies handle requirements
in their `#find_versions` methods. This moves related logic from
`Livecheck#latest_version` into the `PageMatch` strategy, which feels
a bit more appropriate.
2021-11-20 00:39:00 -05:00
Sam Ford
085827f605
Handle variable strategy block arguments
There are times where a regex isn't needed in a `strategy` block and
these changes explicitly handle that situation.

This allows the Symbol Proc format used in some `Sparkle` `livecheck`
blocks (e.g., `strategy :sparkle, &:version`) to continue working
instead of failing with a "wrong number of arguments (given 1,
expected 0)" error. This error would occur because a Symbol Proc only
only expects one argument (e.g., an `Item`, not an `Item` and a
regex/nil).

There's an argument to be made for avoiding the Symbol Proc format
for `strategy` blocks but I haven't found a way of selectively
disabling the Style/SymbolProc cop only for a `strategy` DSL method
call. That is to say, if we don't use the Symbol Proc format, `brew
style` will give a "Pass &:version as an argument to strategy instead
of a block." offense.

Besides that, this also replaces the `block` type signatures in
livecheck strategies with `T.untyped`. Sorbet doesn't know how to
handle a `Proc` with a variable number of arguments and can't be
taught how (i.e., `T.any` with a `Proc` signature for each variation
doesn't work). The aforementioned changes cause Sorbet to complain
about there being both too many and too few arguments, so the only
way to win is not to play the game. Hopefully we can restore the
`block` type signatures in the future (if upstream resolves this
years-old issue) but `T.untyped` seems to be our only option for now.
2021-11-19 23:58:55 -05:00
Sam Ford
9e8900fb6e
Allow regex to be passed into all strategy blocks
This modifies cask-related livecheck strategies to allow passing a
regex into a `strategy` block, when appropriate. These strategies
were outliers that explicitly rejected a regex even if a `strategy`
block was used, forcing any regex to be inlined in the `strategy`
block (instead of being defined using `#regex`).

With these changes, all `strategy` blocks will be able to accept a
regex, further simplifying the mental model. This also helps to
better align the various `find_versions` and `versions_from_*`
methods across strategies.
2021-11-19 23:58:54 -05:00
Sam Ford
94bf67b5df
Merge pull request #12314 from samford/livecheck/apache-support-dlcdn-urls
Apache: Support additional mirror/backup URLs
2021-11-03 11:55:54 -04:00
Mike McQuaid
d43555dd75
brew style --fix 2021-11-02 11:16:10 +00:00
Sam Ford
a1277ee1b0
Apache: Support additional mirror/backup URLs 2021-11-01 15:58:04 -04:00
Sam Ford
8ce6059544
Gnu: Update generated URL to use HTTPS 2021-10-21 09:28:54 -04:00
Sam Ford
e709917cd5
Apache: Extend URL_MATCH_REGEX
Some Apache URLs use a `filename` query string parameter instead of
`path` and the `Apache` strategy isn't applied. The parameter value
is the same as `path` (i.e., a path to a file), so this updates the
strategy's `URL_MATCH_REGEX` to handle this URL format as well.
2021-10-20 10:52:49 -04:00
Sam Ford
e65c9d02ab
PageMatch: Expand #find_versions tests 2021-08-19 16:07:53 -04:00
Sam Ford
b4adf2a42e
PageMatch#find_versions: Fix return conditions 2021-08-19 09:01:11 -04:00
Sam Ford
26821301e7
livecheck: move url/regex generation into methods 2021-08-17 18:03:40 -04:00
Sam Ford
13b349b4ae
Refactor #find_versions parameters in strategies 2021-08-16 12:01:32 -04:00
Sam Ford
c59d5db631
Remove unnecessary require statements 2021-08-11 19:06:00 -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
83f261b6f2
HeaderMatch: Refactor default header logic 2021-08-02 18:33:59 -04:00
Sam Ford
af2c45b297
Git: compact, uniq array from strategy block 2021-08-02 18:33:59 -04:00
Sam Ford
a970780851
livecheck: allow nil return from strategy blocks 2021-08-02 18:33:34 -04:00
Bevan Kay
c28db0424d
livecheck: allow query parameter in electron_builder strategy url
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
2021-07-28 13:20:15 +10:00
Sam Ford
7b864e0aaa
Sourceforge: Do not modify RSS URLs
This allows a `livecheck` block to check the RSS feed for a given
path in a SourceForge project. For example:
https://sourceforge.net/projects/example/rss?path=/directory
2021-07-19 15:15:27 -04:00
Sam Ford
87564b6ccb
Sparkle: Use OS::Mac::Version#prerelease? 2021-06-28 16:54:53 -04:00
Sam Ford
4433f4a985
Sparkle: Update minimumSystemVersion condition 2021-06-28 15:48:35 -04:00
Michael Cho
823dc28c21
livecheck/strategy/sparkle: check minimumSystemVersion for compatibility 2021-06-28 15:39:19 -04:00
Sam Ford
2c4a7ae2cb
Sparkle: Replace Nokogiri with REXML 2021-06-25 17:45:25 -04:00
Sam Ford
23f8cb9f4a
Sparkle: Handle ArgumentError from Time#parse 2021-06-22 10:02:57 -04:00
Sam Ford
a5768de0c3
Sparkle: Account for empty pubDate 2021-06-22 09:23:56 -04:00
Sam Ford
e7d3b2cb31
Sparkle: Move default pub_date value 2021-06-22 09:14:56 -04:00
hyuraku
6720f8bd1e
repair pub-date in livecheck 2021-06-22 09:14:55 -04:00
Sam Ford
ccfd01ba38
Strategy: Replace open-uri with curl 2021-06-04 16:16:05 -04:00
Nanda H Krishna
b920949693
Improve Gnome strategy explanatory comment
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
2021-05-31 19:47:08 +05:30
Nanda H Krishna
471ce1541d
Modify Gnome strategy and update comments
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
2021-05-31 16:07:56 +05:30