-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
[WIP] diagnostic: check outdated mirrors and repositories #21383
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
base: main
Are you sure you want to change the base?
Conversation
0f7c6bd to
9795c77
Compare
Signed-off-by: botantony <antonsm21@gmail.com>
9795c77 to
12f224d
Compare
| HOMEBREW_CORE_DEFAULT_GIT_REMOTE, | ||
| "https://github.com/Homebrew/homebrew-cask", # There's no `HOMEBREW_CASK_DEFAULT_GIT_REMOTE` |
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.
These two can intentionally get outdated on a device without HOMEBREW_NO_INSTALL_FROM_API so may want to conditionally include these two.
(as demonstrated by the CI failures here)
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.
We have another doctor check telling people to untap them unless HOMEBREW_NO_INSTALL_FROM_API or HOMEBREW_DEVELOPER are set so agreed we should match that logic.
| You can solve this by setting the origin remote: | ||
| git -C "#{repository_path}" remote set-url origin #{Formatter.url(desired_origin)} | ||
| EOS | ||
| elsif (Time.now - last_commit_time) > Homebrew::API::DEFAULT_API_STALE_SECONDS |
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 using the default auto-update stale interval is too short for multiple reasons. Firstly, it might have just not got to auto-forcing an update yet if it has just passed - you want some leeway.
Secondly, there's also some things with slower update cadences, e.g: GitHub Actions images for example could be outdated by as much as a month. For end-users, this cadence might actually be more sporadic as not every command triggers an auto-update.
And thirdly since this also checks Homebrew/brew, people without developer mode enabled might not even have 1 update a week. We sometimes have made releases on 2-3 week intervals if something is baking in main. And it's worth having some extra leeway on top of that in case something major happens.
Overall point being: I don't think we want to make this too tight to simply be a "it's been a couple days, Homebrew might have an update" check and lean more towards a "Homebrew installation is obviously majorly outdated" check. The problems that inspired this check have all been cases where things have been outdated by several months.
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.
Agreed. This could be hardcoded to a month or more.
| cask_tap_migrations.jws.json | ||
| cask.jws.json | ||
| formula_tap_migrations.jws.json | ||
| formula.jws.json |
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.
Are these all correct under the new internal API?
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.
They won't be, no. We should use existing API methods for this rather than hardcoding filenames here. We only really need to check a single file here, not all.
| # These are popular mirrors with known problems | ||
| bad_mirrors = [ | ||
| %r{^https?://mirrors\.aliyun\.com/homebrew/.+}, # Last update was in May 2025 | ||
| ] | ||
| problems = [] |
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 seems annoying to maintain - any entry could spring to life at a moments notice and there could be others we're not aware of. It might even do the opposite of what we want and discourage mirrors from fixing their outdated ones in favour of just making a new URL (easier than requesting us to delist it from here). It's technically also incorrect as while the API mirror is outdated, the brew git mirror is not.
In any case, does this check matter if the other one is always going to trigger anyway (and already mentions mirrors)? You're going to get two warnings that effectively say the same thing. This can be an open question to other reviewers too.
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.
It's technically also incorrect as while the API mirror is outdated, the brew git mirror is not.
This feels like something we should check instead of some of these other checks.
Ultimately it doesn't matter if Homebrew/brew and Homebrew/homebrew-core are both outdated by the same amount. We should compare the timestamps in both and if they are mismatched by >1 month then that's the thing to warn about.
MikeMcQuaid
left a comment
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.
Thanks @botantony, appreciate the work here. I think there may be a bit of back and forth to get this ready, just as a warning. Nice work so far!
| end | ||
|
|
||
| sig { returns(String) } | ||
| def mirror_docs_url |
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.
probably makes more sense as a constant
| return if !Utils::Git.available? || !repository_path.git_repository? | ||
|
|
||
| current_origin = repository_path.origin_url | ||
| last_commit_time = Time.parse(T.must(repository_path.last_commit_date)) |
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.
What guarantees last_commit_date will be set?
| You can solve this by setting the origin remote: | ||
| git -C "#{repository_path}" remote set-url origin #{Formatter.url(desired_origin)} | ||
| EOS | ||
| elsif (Time.now - last_commit_time) > Homebrew::API::DEFAULT_API_STALE_SECONDS |
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.
Agreed. This could be hardcoded to a month or more.
| HOMEBREW_CORE_DEFAULT_GIT_REMOTE, | ||
| "https://github.com/Homebrew/homebrew-cask", # There's no `HOMEBREW_CASK_DEFAULT_GIT_REMOTE` |
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.
We have another doctor check telling people to untap them unless HOMEBREW_NO_INSTALL_FROM_API or HOMEBREW_DEVELOPER are set so agreed we should match that logic.
| Try to update Homebrew and repositories: | ||
| brew update | ||
| If it does not fix the problem, you might need to use a mirror: |
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.
We should not recommend using mirrors.
We should recommend brew update-reset if brew update is not sufficient.
| cask_tap_migrations.jws.json | ||
| cask.jws.json | ||
| formula_tap_migrations.jws.json | ||
| formula.jws.json |
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.
They won't be, no. We should use existing API methods for this rather than hardcoding filenames here. We only really need to check a single file here, not all.
| # These are popular mirrors with known problems | ||
| bad_mirrors = [ | ||
| %r{^https?://mirrors\.aliyun\.com/homebrew/.+}, # Last update was in May 2025 | ||
| ] | ||
| problems = [] |
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.
It's technically also incorrect as while the API mirror is outdated, the brew git mirror is not.
This feels like something we should check instead of some of these other checks.
Ultimately it doesn't matter if Homebrew/brew and Homebrew/homebrew-core are both outdated by the same amount. We should compare the timestamps in both and if they are mismatched by >1 month then that's the thing to warn about.
brew lgtm(style, typechecking and tests) with your changes locally?Draft PR, feel free to discuss and suggest changes (what checks should be added/removed, other mirrors with known problems, etc.)