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 parent formula reference in resources #19040

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

nandahkrishna
Copy link
Member

  • 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 PR adds a new livecheck strategy, FormulaLatest. This will be used in formulae where the latest versions of the resources are identical to the latest version of the formula itself. For example, consider the resource presto-cli in prestodb:

  resource "presto-cli" do
    ...

    livecheck do
      strategy :formula_latest
    end
  end

This gives:

homebrew-core git:(master) ✗ brew lc -dvr --autobump prestodb
...

Resource:         presto-cli
livecheck block?: Yes

URL:              None
Strategies:       FormulaLatest
Strategy:         FormulaLatest
Cached?:          Yes

Matched Versions:
0.290 => #<Version:0x0000000103d81338 @version="0.290", @detected_from_url=false>

prestodb: 0.290 ==> 0.290
  presto-cli: 0.290 ==> 0.290

Once this is merged, I'll work on automatically updating such resources when brew bump is used.

@nandahkrishna nandahkrishna requested a review from samford January 5, 2025 19:42
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.

Before I dig into reviewing this, I'm not sure that a strategy is the best fit to address this scenario. Since this is basically a way of having a resource livecheck block reference the main formula check (without re-running it), something like formula :parent feels more conceptually appropriate.

We would have to tweak #formula to allow a symbol and do some special-casing in livecheck/livecheck.rb methods to handle the :parent argument for resources but I threw together a quick proof of concept and it's technically possible, at least.

If that approach makes sense to you, I can tinker with it some more tomorrow (it's a bit late over here) and provide some more commentary, code, etc. (though feel free to beat me to it in the interim time). Otherwise, if there's a compelling reason this should be a strategy, do let me know.

@nandahkrishna
Copy link
Member Author

something like formula :parent feels more conceptually appropriate.

Something like this is what I was thinking of, prior to going with the strategy approach for a couple of reasons:

  1. I assumed that references re-ran the livecheck, which we wouldn't want. We would just want to use the information in the formula_latest variable.
  2. I wanted to allow for an option to modify the version with a strategy block, if there are formulae where resource versions are formula versions plus some additional info.

I don't really think these are strong cases against the reference approach, which did indeed seem more conceptually appropriate to me as well. I'll go ahead and modify this PR, but we can revert to the strategy approach if we find compelling reasons to use it.

@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from f9d74fc to 138473f Compare January 6, 2025 07:26
@nandahkrishna
Copy link
Member Author

I've pushed a fairly hacky first implementation here and it seems to work. I'm going to work on polishing it later today, but please feel free to leave suggestions.

@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from 138473f to 981fc6f Compare January 6, 2025 07:29
@nandahkrishna nandahkrishna changed the title livecheck: add FormulaLatest strategy livecheck: allow parent formula reference in resources Jan 6, 2025
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.

Fine with me once @samford is 👍🏻

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.

This is pretty much what I was thinking (my proof of concept was more hacky 😆). There's probably still room for improvement but not without refactoring existing parts of livecheck/livecheck.rb (e.g., the urls = ["None"] approach feels kind of weird but I understand why it's necessary and the amount of work to avoid that is non-trivial). This should be good for now after some changes.

I can't add suggestions to areas that haven't been modified, so I've pushed commits in my fork that you can pull if you agree with the changes (https://github.com/samford/brew/commits/resource-livecheck-formula-latest/).

The first commit updates the Livecheck#formula DSL method comment to replace "String" on the second line with "String/Symbol" (bringing it in line with the parameter change).

The second updates the resource_version_info return data in #resource_version to include a references array with the parent formula name (when formula :parent is used) and to only include [:meta][:url] when url is not "None" (i.e., when formula :parent is not used). The former brings it more in line with how package references are handled and the latter makes sure that we don't end up with "url": { "original": "None" } in the JSON output.


Long term, we may be able to simplify this once we have a general caching implementation, so this doesn't need to be perfect. We can revisit this in the interim time if you run into enough livecheck blocks where you need a strategy block. If that ends up being the case, we will have to put in the work to implement proper package reference support for resources. [For what it's worth, I'm fine with the idea of using #formula/#cask along with other DSL methods (e.g., #regex, #strategy) to override parts of the referenced livecheck block, as I intentionally made sure that worked when I implemented the feature.]

We may want to eventually add reference support for resource livecheck blocks anyway (for the sake of feature parity between formulae/resources/casks) but I don't imagine it would be needed much (if at all). I've always wondered if we could reasonably merge #resource_version into #latest_version and handle the differences for resources using conditionals (or if that would be too much work), so I kind of wanted to explore whether that would be an easier path to bringing resource checks in line with formulae/cask checks (feel free to beat me to it if you want because it's not at the top of my to-do list).

Anyway, I'm working my way toward creating a PR for the last bit of foundation to enable caching (that work's done but I need to take a final pass through it) and I'll create a PR for the caching implementation after that. I have some other notable changes/features in the pipeline that I need to get out first, so it won't be in the immediate term but it'll happen sometime.

@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from 01386cb to da859b6 Compare January 6, 2025 20:17
@nandahkrishna
Copy link
Member Author

Aha, I just pushed a commit before I saw your review, but essentially:

  • I think it's fine to just have support for formula :parent at the moment. Handling proper formula references (or reference chains) doesn't seem necessary for now.
  • I've worked on some of the metadata and I'll incorporate other changes from your branch, but something funky so far is that we don't include the parent's strategy info in the resource_version_hash, I haven't done it here because we technically aren't using any strategy and just the existing latest version info – but we can revisit this if necessary.

We may want to eventually add reference support for resource livecheck blocks anyway (for the sake of feature parity between formulae/resources/casks) but I don't imagine it would be needed much (if at all).

Agreed.

I've always wondered if we could reasonably merge #resource_version into #latest_version

This is indeed one of my biggest gripes with the current implementation, so I'll try to get to it sometime soon.

@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from da859b6 to 32595d5 Compare January 6, 2025 20:38
@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from 32595d5 to f802099 Compare January 6, 2025 20:41
@nandahkrishna nandahkrishna force-pushed the resource-livecheck-formula-latest branch from f802099 to 053a334 Compare January 6, 2025 20:47
@nandahkrishna nandahkrishna requested a review from samford January 6, 2025 20:48
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.

Just a couple last things to discuss/consider and then this should be good to merge.

Library/Homebrew/livecheck/livecheck.rb Outdated Show resolved Hide resolved
Library/Homebrew/livecheck/livecheck.rb Outdated Show resolved Hide resolved
@nandahkrishna nandahkrishna requested a review from samford January 7, 2025 05:00
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.

I gave this a final test and everything looks good. Thanks, @nandahkrishna!

I think we'll have to wait until this is in the next brew release before we can use formula :parent in resources, since it relies on DSL changes.

@nandahkrishna nandahkrishna added this pull request to the merge queue Jan 7, 2025
Merged via the queue into master with commit 175cd9e Jan 7, 2025
28 checks passed
@nandahkrishna nandahkrishna deleted the resource-livecheck-formula-latest branch January 7, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants