-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Conversation
There was a problem hiding this 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.
Something like this is what I was thinking of, prior to going with the strategy approach for a couple of reasons:
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. |
f9d74fc
to
138473f
Compare
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. |
138473f
to
981fc6f
Compare
FormulaLatest
strategyThere was a problem hiding this 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 👍🏻
There was a problem hiding this 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.
01386cb
to
da859b6
Compare
Aha, I just pushed a commit before I saw your review, but essentially:
Agreed.
This is indeed one of my biggest gripes with the current implementation, so I'll try to get to it sometime soon. |
da859b6
to
32595d5
Compare
Co-authored-by: Sam Ford <[email protected]>
32595d5
to
f802099
Compare
Co-authored-by: Sam Ford <[email protected]>
f802099
to
053a334
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
brew style
with your changes locally?brew typecheck
with your changes locally?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 resourcepresto-cli
inprestodb
:This gives:
Once this is merged, I'll work on automatically updating such resources when
brew bump
is used.