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: support throttle DSL #16918

Merged
merged 5 commits into from Mar 21, 2024
Merged

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Mar 19, 2024

  • 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?

Essentially, we need to figure out best way to combine autobump, livecheck, and throttle so that autobumps can properly handle this. Preferably avoiding code duplication across various parts (i.e. bump commands, livecheck logic, github action, etc.)

Some ideas:

  1. Throttle DSL - This approach
  2. Livecheck throttling - ~~e.g. Homebrew/homebrew-core@184767f
  3. Time-based throttling - would need to change version-based throttling to time-based (days between bump) in JSON, provide a way of detecting some datetime info (e.g. modulo current day of year, attempt during specific timeslot in a day).
    • Con: This functionality mainly works when on autobump, but is trickier when user bumping is allowed as cannot guarantee cadence here.

@cho-m cho-m changed the title livecheck: support throttle DSL [POC] livecheck: support throttle DSL Mar 19, 2024
@@ -810,6 +810,28 @@ def latest_version(
latest: Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(formula_or_cask, v) }),
}

if (throttle = livecheck.throttle || referenced_livecheck&.throttle)
match_version_map.delete_if { |_match, version| !version.patch.to_i.modulo(throttle).zero? }
Copy link
Member Author

Choose a reason for hiding this comment

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

Could even consider extending DSL to allow minor version and other fine control. Maybe like one of following styles:

throttle 10, :minor
throttle 10, :minor_version
throttle 10, :version_minor

@cho-m cho-m force-pushed the livecheck-throttle branch 3 times, most recently from d7ada6c to c863181 Compare March 19, 2024 16:10
@cho-m cho-m changed the title [POC] livecheck: support throttle DSL livecheck: support throttle DSL Mar 19, 2024
@cho-m cho-m marked this pull request as ready for review March 19, 2024 16:49
Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Seems sensible to me, but I think we want to deprecate the throttle JSON in favour of this so we don't have two different lists to carry around.

@cho-m
Copy link
Member Author

cho-m commented Mar 19, 2024

deprecate the throttle JSON in favour of this so we don't have two different lists to carry around.

That was my plan if we go this route. But may be a follow up so we can migrate homebrew/core usage and then deprecate support. I need to figure out how to handle renovate and vim since we don't collect sufficient version info.

@p-linnane p-linnane requested a review from samford March 19, 2024 19:03
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 good! There's a bunch of suboptimal type usage in existing code that would be nice to clean up but doesn't need to block this PR.

Library/Homebrew/dev-cmd/bump.rb Outdated Show resolved Hide resolved
livecheck_latest = livecheck_result(loaded_formula_or_cask)
livecheck_latest, livecheck_latest_throttled = livecheck_result(loaded_formula_or_cask)
# TODO: Pass down `livecheck_latest` info to print output for throttled formulae or casks
livecheck_latest = livecheck_latest_throttled if livecheck_latest_throttled

new_version_value = if (livecheck_latest.is_a?(Version) && livecheck_latest >= current_version_value) ||
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need cleaned up in this PR but: I hate that it's using different types here to indicate success/failure.

rate: T.nilable(Integer),
).returns(T.nilable(Integer))
}
def throttle(rate = T.unsafe(nil))
Copy link
Member

Choose a reason for hiding this comment

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

Would be nicer to avoid unsafe here if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this may relate to sig @reitermarkus suggested. If we type the parameter as T.nilable(Integer) then it is no longer T.unsafe.

On other hand, if we type it as Integer, then we need to make it T.unsafe.

Whichever we choose should be consistent with Livecheck code so can discuss in follow up.

Copy link
Member

Choose a reason for hiding this comment

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

Whichever we choose should be consistent with Livecheck code so can discuss in follow up.

Agreed.

Generally I favour (in descending order of preference):

  • non-nilable types
  • nilable types
  • use of unsafe
  • use of must

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.

From a quick review/test, we still need to add some throttle information to the debug and JSON output. Namely:

  • The JSON output is missing an (optional) latest_throttled field. The value is present in the data from #latest_version but we need to handle it in #run_checks.
  • We should print the throttle value in the debug output.
  • We should include the throttle value in the meta part of the JSON output.

These are simple changes and I worked them up while reviewing this, so I'll just go ahead and push a commit to take care of it (since I can't add suggestions to all the code here).


Past that, this seems reasonable to me. With these changes, livecheck continues to return the latest version and the latest throttled version is simply provided as supplemental information, which is how I would handle this. brew bump benefits from the extra information while livecheck continues to return the latest version 👍

Library/Homebrew/livecheck.rb Outdated Show resolved Hide resolved
@MikeMcQuaid
Copy link
Member

Past that, this seems reasonable to me.

@samford can you ✅ in future when you feel that way? Thanks 🙇🏻

@MikeMcQuaid
Copy link
Member

@cho-m Good to 🚢 once rebased and 🟢, thanks!

@samford
Copy link
Member

samford commented Mar 21, 2024

@samford can you ✅ in future when you feel that way? Thanks 🙇🏻

My wording was soft but I still wanted to see the throttle variable/method in the Livecheck DSL reordered before approving/merging. I should have been more explicit about that up front. I pushed a commit to take care of those changes, so I'll go ahead and approve.

I also rebased this and resolved the merge conflicts, so it should pass CI this time around.

@cho-m
Copy link
Member Author

cho-m commented Mar 21, 2024

@cho-m Good to 🚢 once rebased and 🟢, thanks!

I will do one more sweep through code. Mostly going to clean up some of my unused logic though I may defer some/all changes to follow up (along with tests and audits).

@cho-m
Copy link
Member Author

cho-m commented Mar 21, 2024

Going to have to figure out why test for ZSH completions is failing. I don't think it is related to this PR given we didn't modify description. Can't repro locally.

Error: Homebrew::Completions when generating completions .update_shell_completions! generates shell completions

Failure/Error: described_class.update_shell_completions!

NoMethodError:
  undefined method `split' for nil:NilClass

          cmd_parser.description.split(DESCRIPTION_SPLITTING_PATTERN).first
                                ^^^^^^

@MikeMcQuaid MikeMcQuaid merged commit 857838a into Homebrew:master Mar 21, 2024
25 checks passed
@cho-m cho-m deleted the livecheck-throttle branch March 21, 2024 14:33
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants