Class: Homebrew::TestBot::PackagesDetect Private
- Defined in:
- test_bot/packages_detect.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Constant Summary collapse
- DEFAULT_TEST_FORMULAE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Formulae must have GitHub homepages and stable URLs, no dependencies, one executable and one library between them.
%w[termbox bats-core].freeze
Instance Attribute Summary collapse
- #added_casks ⇒ Array<String> readonly private
- #added_formulae ⇒ Array<String> readonly private
- #deleted_casks ⇒ Array<String> readonly private
- #deleted_formulae ⇒ Array<String> readonly private
- #testing_casks ⇒ Array<String> readonly private
- #testing_formulae ⇒ Array<String> readonly private
Attributes inherited from Test
Class Method Summary collapse
-
.changed_packages(tap, revisions, check_cask_paths: false) ⇒ Hash{Symbol => Array<(Array<String>, Array<String>, Array<String>)>}
private
Returns the added, modified and deleted package names in a Git revision range.
Instance Method Summary collapse
- #initialize(argument, tap:, git:, dry_run:, fail_fast:, verbose:) ⇒ void constructor private
- #run!(args:) ⇒ void private
Methods inherited from Test
#failed_steps, #ignored_steps, #test
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(argument, tap:, git:, dry_run:, fail_fast:, verbose:) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'test_bot/packages_detect.rb', line 27 def initialize(argument, tap:, git:, dry_run:, fail_fast:, verbose:) super(tap:, git:, dry_run:, fail_fast:, verbose:) @testing_casks = T.let([], T::Array[String]) @added_casks = T.let([], T::Array[String]) @deleted_casks = T.let([], T::Array[String]) @argument = argument @added_formulae = T.let([], T::Array[String]) @deleted_formulae = T.let([], T::Array[String]) @formulae_to_fetch = T.let([], T::Array[String]) @testing_formulae = T.let([], T::Array[String]) end |
Instance Attribute Details
#added_casks ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def added_casks @added_casks end |
#added_formulae ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def added_formulae @added_formulae end |
#deleted_casks ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def deleted_casks @deleted_casks end |
#deleted_formulae ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def deleted_formulae @deleted_formulae end |
#testing_casks ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def testing_casks @testing_casks end |
#testing_formulae ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
15 16 17 |
# File 'test_bot/packages_detect.rb', line 15 def testing_formulae @testing_formulae end |
Class Method Details
.changed_packages(tap, revisions, check_cask_paths: false) ⇒ Hash{Symbol => Array<(Array<String>, Array<String>, Array<String>)>}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns the added, modified and deleted package names in a Git revision range.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'test_bot/packages_detect.rb', line 79 def self.changed_packages(tap, revisions, check_cask_paths: false) changes = Utils.safe_popen_read( Utils::Git.git, "-C", tap.path, "diff", "--no-renames", "--name-status", "-z", "--diff-filter=AMD", revisions, "--", "*.rb" ) packages = T.let({ formula: {}, cask: {} }, T::Hash[Symbol, T::Hash[String, T::Array[String]]]) misplaced = [] changes.split("\0").each_slice(2) do |entry| status = entry.fetch(0) file = entry.fetch(1) if tap.cask_file?(file) by_status = packages.fetch(:cask) elsif check_cask_paths && status != "D" && !file.start_with?("cmd/", ".github/actions/") misplaced << file next elsif tap.formula_file?(file) by_status = packages.fetch(:formula) else next end (by_status[status] ||= []) << tap.formula_file_to_name(Pathname(file)) end if misplaced.any? misplaced.each { |file| puts "::error file=#{file}::File is in wrong directory." } raise "Found Ruby files in wrong directory:\n#{misplaced.join("\n")}" end # Moving a package between subdirectories changes its path but keeps its name. packages.transform_values do |by_status| added = by_status.fetch("A", []) deleted = by_status.fetch("D", []) [added - deleted, by_status.fetch("M", []) | (added & deleted), deleted - added] end end |
Instance Method Details
#run!(args:) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'test_bot/packages_detect.rb', line 41 def run!(args:) name = @argument if name == "HEAD" detect_packages!(args:) else only = :formula unless args.only_packages_detect? package = CLI::NamedArgs.new(name, parent: args, without_api: true).to_formulae_and_casks(only:).fetch(0) case package when Formula if package.tap&.core_tap? ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1" CoreTap.instance.ensure_installed! end @testing_formulae = [package.full_name] @testing_formulae |= DEFAULT_TEST_FORMULAE if args.test_default_formula? when Cask::Cask @testing_casks = [package.full_name] end end return unless GitHub::Actions.env_set? File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f| f.puts "testing_casks=#{@testing_casks.join(",")}" f.puts "added_casks=#{@added_casks.join(",")}" f.puts "deleted_casks=#{@deleted_casks.join(",")}" f.puts "testing_formulae=#{@testing_formulae.join(",")}" f.puts "added_formulae=#{@added_formulae.join(",")}" f.puts "deleted_formulae=#{@deleted_formulae.join(",")}" f.puts "formulae_to_fetch=#{@formulae_to_fetch.join(",")}" end end |