From 3f976ec0c2f6c69e16e9b3429a4164a2b3b789ea Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 22 Dec 2024 00:14:28 +0000 Subject: [PATCH 1/6] dev-cmd/livecheck: Skip autobumped formulae - Skip formulae that are autobumped by BrewTestBot, to avoid useless effort spent by contributors who are checking for formulae to bump and then we close their PRs. --- Library/Homebrew/dev-cmd/livecheck.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index b811ad4fe6..3670c00602 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -14,7 +14,7 @@ module Homebrew Check for newer versions of formulae and/or casks from upstream. If no formula or cask argument is passed, the list of formulae and casks to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` or - `~/.homebrew/livecheck_watchlist.txt`. + `~/.homebrew/livecheck_watchlist.txt`, excluding autobumped formulae. EOS switch "--full-name", description: "Print formulae and casks with fully-qualified names." @@ -90,6 +90,19 @@ module Homebrew end end + # Skip formulae that are autobumped by BrewTestBot. + formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| + next false if formula_or_cask.respond_to?(:token) # Only formulae are autobumped. + + autobump_file = formula_or_cask.tap.path/".github/autobump.txt" + next false unless File.exist?(autobump_file) + + if File.read(autobump_file).include?(formula_or_cask.name) + odebug "Skipping #{formula_or_cask.name} as it is autobumped." + true + end + end + formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask| formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name end From b54b9dad2ae0b66d7b012b2ae5498b000f737763 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 22 Dec 2024 00:31:56 +0000 Subject: [PATCH 2/6] Oh the non-breaking space (option + space) got me again --- Library/Homebrew/dev-cmd/livecheck.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 3670c00602..9f57f56201 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -90,7 +90,7 @@ module Homebrew end end - # Skip formulae that are autobumped by BrewTestBot. + # Skip formulae that are autobumped by BrewTestBot. formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| next false if formula_or_cask.respond_to?(:token) # Only formulae are autobumped. From 4b94bbb4d4dfe776ca7073b579fb394a868e6eaf Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 22 Dec 2024 14:40:40 +0000 Subject: [PATCH 3/6] More efficient autobump file reads - and support Casks --- Library/Homebrew/dev-cmd/livecheck.rb | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 9f57f56201..2746145a23 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -90,16 +90,17 @@ module Homebrew end end - # Skip formulae that are autobumped by BrewTestBot. - formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| - next false if formula_or_cask.respond_to?(:token) # Only formulae are autobumped. + # Skip packages that are autobumped by BrewTestBot, if there are any. + if autobump_core_path.exist? && autobump_cask_path.exist? + autobump_core = File.read(autobump_core_path).lines.map(&:strip) + autobump_cask = File.read(autobump_cask_path).lines.map(&:strip) - autobump_file = formula_or_cask.tap.path/".github/autobump.txt" - next false unless File.exist?(autobump_file) - - if File.read(autobump_file).include?(formula_or_cask.name) - odebug "Skipping #{formula_or_cask.name} as it is autobumped." - true + formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| + name = formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name + if (autobump_core + autobump_cask).include?(name) + odebug "Skipping #{name} as it is autobumped." + true + end end end @@ -130,6 +131,16 @@ module Homebrew def watchlist_path @watchlist_path ||= T.let(File.expand_path(Homebrew::EnvConfig.livecheck_watchlist), T.nilable(String)) end + + sig { returns(Pathname) } + def autobump_core_path + @autobump_core_path ||= T.let(Tap.fetch("homebrew/core").path/".github/autobump.txt", T.nilable(Pathname)) + end + + sig { returns(Pathname) } + def autobump_cask_path + @autobump_cask_path ||= T.let(Tap.fetch("homebrew/cask").path/".github/autobump.txt", T.nilable(Pathname)) + end end end end From a71786a332e8f4b050af29f351348e1d8e0c3c05 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 2 Jan 2025 17:20:32 +0000 Subject: [PATCH 4/6] Flag and envvar to include autobumped formulae - This is useful for maintainers to check the full range of livecheck functionality. --- Library/Homebrew/dev-cmd/livecheck.rb | 14 +++++++++++--- Library/Homebrew/env_config.rb | 4 ++++ .../rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi | 4 +++- .../sorbet/rbi/dsl/homebrew/env_config.rbi | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 2746145a23..814415eb7e 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -14,7 +14,7 @@ module Homebrew Check for newer versions of formulae and/or casks from upstream. If no formula or cask argument is passed, the list of formulae and casks to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` or - `~/.homebrew/livecheck_watchlist.txt`, excluding autobumped formulae. + `~/.homebrew/livecheck_watchlist.txt`. EOS switch "--full-name", description: "Print formulae and casks with fully-qualified names." @@ -38,6 +38,8 @@ module Homebrew description: "Only check casks." switch "--extract-plist", description: "Enable checking multiple casks with ExtractPlist strategy." + switch "--autobump", + description: "Include packages that are autobumped by BrewTestBot. By default these are skipped." conflicts "--debug", "--json" conflicts "--tap=", "--eval-all", "--installed" @@ -90,8 +92,9 @@ module Homebrew end end - # Skip packages that are autobumped by BrewTestBot, if there are any. - if autobump_core_path.exist? && autobump_cask_path.exist? + # Skip packages that are autobumped by BrewTestBot, unless `--autobump` + # or `HOMEBREW_LIVECHECK_AUTOBUMP` are set. + if skip_autobump? && autobump_core_path.exist? && autobump_cask_path.exist? autobump_core = File.read(autobump_core_path).lines.map(&:strip) autobump_cask = File.read(autobump_cask_path).lines.map(&:strip) @@ -141,6 +144,11 @@ module Homebrew def autobump_cask_path @autobump_cask_path ||= T.let(Tap.fetch("homebrew/cask").path/".github/autobump.txt", T.nilable(Pathname)) end + + sig { returns(T::Boolean) } + def skip_autobump? + !(args.autobump? || Homebrew::EnvConfig.livecheck_autobump?) + end end end end diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index e201d22398..f781de80ce 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -303,6 +303,10 @@ module Homebrew "or `$HOME/.homebrew/livecheck_watchlist.txt` otherwise.", default: "#{ENV.fetch("HOMEBREW_USER_CONFIG_HOME")}/livecheck_watchlist.txt", }, + HOMEBREW_LIVECHECK_AUTOBUMP: { + description: "If set, `brew livecheck` will include data for packages that are autobumped by BrewTestBot.", + boolean: true, + }, HOMEBREW_LOCK_CONTEXT: { description: "If set, Homebrew will add this output as additional context for locking errors. " \ "This is useful when running `brew` in the background.", diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi index 0729c85370..18ead85de8 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi @@ -4,13 +4,15 @@ # This is an autogenerated file for dynamic methods in `Homebrew::DevCmd::LivecheckCmd`. # Please instead update this file by running `bin/tapioca dsl Homebrew::DevCmd::LivecheckCmd`. - class Homebrew::DevCmd::LivecheckCmd sig { returns(Homebrew::DevCmd::LivecheckCmd::Args) } def args; end end class Homebrew::DevCmd::LivecheckCmd::Args < Homebrew::CLI::Args + sig { returns(T::Boolean) } + def autobump?; end + sig { returns(T::Boolean) } def cask?; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index 31f11f8b65..c15fda7c20 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -196,6 +196,9 @@ module Homebrew::EnvConfig sig { returns(String) } def livecheck_watchlist; end + sig { returns(T::Boolean) } + def livecheck_autobump?; end + sig { returns(T.nilable(::String)) } def lock_context; end From 296c2b9f3fc4760cac5eb516394fa16b9c9bf0d6 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 2 Jan 2025 17:41:45 +0000 Subject: [PATCH 5/6] Be smarter about finding a tap's `autobump.txt` - Livecheck blocks can exist in taps other than Core and Cask. - And packages can have the same name in multiple taps. --- Library/Homebrew/dev-cmd/livecheck.rb | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 814415eb7e..2b62b037a5 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -92,16 +92,26 @@ module Homebrew end end - # Skip packages that are autobumped by BrewTestBot, unless `--autobump` - # or `HOMEBREW_LIVECHECK_AUTOBUMP` are set. - if skip_autobump? && autobump_core_path.exist? && autobump_cask_path.exist? - autobump_core = File.read(autobump_core_path).lines.map(&:strip) - autobump_cask = File.read(autobump_cask_path).lines.map(&:strip) + if skip_autobump? + autobump_files = {} + + formulae_and_casks_to_check.each do |formula_or_cask| + tap = formula_or_cask.tap + next if tap.nil? + + autobump_files[tap] ||= begin + autobump_path = tap.path/".github/autobump.txt" + autobump_path.exist? ? File.read(autobump_path).lines.map(&:strip) : [] + end + end formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| + tap = formula_or_cask.tap + next false if tap.nil? + name = formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name - if (autobump_core + autobump_cask).include?(name) - odebug "Skipping #{name} as it is autobumped." + if autobump_files[tap].include?(name) + odebug "Skipping #{name} as it is autobumped in #{tap}." true end end @@ -135,16 +145,6 @@ module Homebrew @watchlist_path ||= T.let(File.expand_path(Homebrew::EnvConfig.livecheck_watchlist), T.nilable(String)) end - sig { returns(Pathname) } - def autobump_core_path - @autobump_core_path ||= T.let(Tap.fetch("homebrew/core").path/".github/autobump.txt", T.nilable(Pathname)) - end - - sig { returns(Pathname) } - def autobump_cask_path - @autobump_cask_path ||= T.let(Tap.fetch("homebrew/cask").path/".github/autobump.txt", T.nilable(Pathname)) - end - sig { returns(T::Boolean) } def skip_autobump? !(args.autobump? || Homebrew::EnvConfig.livecheck_autobump?) From ce562c312bcc6d7c310332cdcc045431fe4a86e2 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 4 Jan 2025 14:17:01 +0000 Subject: [PATCH 6/6] Alphabetical envvars; better variable names; just the one loop --- Library/Homebrew/dev-cmd/livecheck.rb | 19 +++++++------------ Library/Homebrew/env_config.rb | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 2b62b037a5..04cb4d0f5a 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -93,24 +93,19 @@ module Homebrew end if skip_autobump? - autobump_files = {} - - formulae_and_casks_to_check.each do |formula_or_cask| - tap = formula_or_cask.tap - next if tap.nil? - - autobump_files[tap] ||= begin - autobump_path = tap.path/".github/autobump.txt" - autobump_path.exist? ? File.read(autobump_path).lines.map(&:strip) : [] - end - end + autobump_lists = {} formulae_and_casks_to_check = formulae_and_casks_to_check.reject do |formula_or_cask| tap = formula_or_cask.tap next false if tap.nil? + autobump_lists[tap] ||= begin + autobump_path = tap.path/".github/autobump.txt" + autobump_path.exist? ? autobump_path.readlines.map(&:strip) : [] + end + name = formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name - if autobump_files[tap].include?(name) + if autobump_lists[tap].include?(name) odebug "Skipping #{name} as it is autobumped in #{tap}." true end diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index f781de80ce..1ddc3823ae 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -296,6 +296,10 @@ module Homebrew default_text: 'The "Beer Mug" emoji.', default: "🍺", }, + HOMEBREW_LIVECHECK_AUTOBUMP: { + description: "If set, `brew livecheck` will include data for packages that are autobumped by BrewTestBot.", + boolean: true, + }, HOMEBREW_LIVECHECK_WATCHLIST: { description: "Consult this file for the list of formulae to check by default when no formula argument " \ "is passed to `brew livecheck`.", @@ -303,10 +307,6 @@ module Homebrew "or `$HOME/.homebrew/livecheck_watchlist.txt` otherwise.", default: "#{ENV.fetch("HOMEBREW_USER_CONFIG_HOME")}/livecheck_watchlist.txt", }, - HOMEBREW_LIVECHECK_AUTOBUMP: { - description: "If set, `brew livecheck` will include data for packages that are autobumped by BrewTestBot.", - boolean: true, - }, HOMEBREW_LOCK_CONTEXT: { description: "If set, Homebrew will add this output as additional context for locking errors. " \ "This is useful when running `brew` in the background.",