Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livecheck: allow custom url in extract_plist strategy #13346

Merged
merged 4 commits into from
Jun 24, 2022

Conversation

bevanjkay
Copy link
Member

@bevanjkay bevanjkay commented May 30, 2022

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This allows a custom url to be passed to livecheck when using the :extract_plist strategy.

This is useful in edge cases that meet a couple of criteria:

  • There is no version information available utilising the other livecheck methods
  • There is an unversioned download link that points to the latest version
  • There is a versioned download link available that we can use for download

At the moment in these cases we are limited to using the unversioned url OR using the versioned url and skipping the livecheck.

An example of a cask that is currently not functioning as intended is the speedify cask.

@BrewTestBot
Copy link
Member

Review period will end on 2022-05-31 at 06:46:29 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label May 30, 2022
@bevanjkay bevanjkay added the cask Homebrew Cask label May 30, 2022
@bevanjkay bevanjkay force-pushed the extract-plist branch 2 times, most recently from c8e6004 to 7b85717 Compare May 30, 2022 07:47
@bevanjkay
Copy link
Member Author

I'm getting a typecheck error, I'd appreciate some direction on how to get it sorted.

brew typecheck   
livecheck/strategy/extract_plist.rb:104: Method url does not exist on T.class_of(Homebrew::Livecheck::Strategy::ExtractPlist) https://srb.help/7003
     104 |              url url.to_s
                        ^^^

@MikeMcQuaid MikeMcQuaid requested a review from samford May 30, 2022 08:33
Copy link
Member

@samford samford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the idea behind this PR makes sense to me. Checking a versioned url with ExtractPlist would be a waste of effort (as it would simply give the current version) and, as you mentioned, it's necessary to check an unversioned url in cases like speedify to identify the latest version 👍


I'm getting a typecheck error, I'd appreciate some direction on how to get it sorted.

brew typecheck   
livecheck/strategy/extract_plist.rb:104: Method url does not exist on T.class_of(Homebrew::Livecheck::Strategy::ExtractPlist) https://srb.help/7003
     104 |              url url.to_s
                        ^^^

I tinkered with this and the only way I found to avoid the typecheck error was to use Cask::CaskLoader.load with a string, like we do in tests (e.g., livecheck/livecheck_spec.rb). For example, the existing code would be like this:

Cask::CaskLoader.load(+<<-RUBY, config: cask.config)
  cask "livecheck-url-cask" do
    url "#{url}"
  end
RUBY

That said, we can simplify this and avoid the UnversionedCaskChecker changes if we can create a copy of the cask with a substitute url (instead of passing in a supplementary livecheck_url cask to use for UnversionedCaskChecker#installer). It would be ideal if we could simply replace the underlying cask.url URL::DSL object but Cask::DSL#set_unique_stanza won't allow this (e.g., cask.url { url } produces a Cask::CaskInvalidError (Cask 'speedify' definition is invalid: 'url' stanza may only appear once.) error).

However, if there aren't any objections to using #instance_variable_set in this context, we can sidestep the issue by directly replacing the @url instance variable (in the Cask::DSL object). I've added a suggestion below that demonstrates this approach but it shouldn't be committed unless/until the approach is approved.

Library/Homebrew/livecheck/strategy/extract_plist.rb Outdated Show resolved Hide resolved
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label May 31, 2022
@BrewTestBot
Copy link
Member

Review period ended.

@samford
Copy link
Member

samford commented Jun 12, 2022

In the interest of merging this, I rebased the branch and pushed a couple commits. The first commit adds a missing documentation comment and adds url to the #find_versions return hash (to align it with other strategies). The second commit reworks how we handle the new url argument (and reverts the UnversionedCaskChecker changes) per the previous suggestion.

@samford samford requested a review from MikeMcQuaid June 12, 2022 19:37
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need new API for this.

bevanjkay and others added 4 commits June 24, 2022 00:08
`ExtractPlist` doesn't require a URL like other strategies (it takes
a `Cask` instead) but we've had to provide one in existing
`livecheck` blocks to get past this requirement in livecheck. This
commit makes it so this requirement is only enforced when a
strategy's `#find_versions` method has a required `url` parameter
(not an optional one, as in `ExtractPlist`).
@samford
Copy link
Member

samford commented Jun 24, 2022

I've rebased this and incorporated the previously-discussed allow_reassignment approach in Cask, so it's ready for review.

Past that, I added a commit to ensure that livecheck only requires a URL when a livecheck block specifies a strategy and the strategy's #find_versions method has a required url parameter. Up to this point, we've had to add a url to livecheck blocks using strategy :extract_plist, even though ExtractPlist#find_versions checks a cask instead of a URL. Now that ExtractPlist supports an optional URL, it would be clearer to only include a URL in related livecheck blocks when it's intended to override the cask url.

[Regarding disabling the Metrics/CyclomaticComplexity RuboCop for Livecheck#latest_version: I have some ideas on how to refactor the Livecheck module (and this method) to resolve the existing offenses. There are a few other things that I want to get finished first but I'm hoping to take care of this in the not too distant future.]

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, nice work @samford!

@samford
Copy link
Member

samford commented Jun 24, 2022

Thanks, everyone!

@samford samford merged commit 770af2d into Homebrew:master Jun 24, 2022
@github-actions github-actions bot added the outdated PR was locked due to age label Jul 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cask Homebrew Cask outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants