Class: Homebrew::TestBot::FormulaeDependents Private
- Inherits:
-
TestFormulae
- Object
- Test
- TestFormulae
- Homebrew::TestBot::FormulaeDependents
- Defined in:
- test_bot/formulae_dependents.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.
Instance Attribute Summary collapse
- #tested_formulae ⇒ Array<String> writeonly private
- #testing_formulae ⇒ Array<String> writeonly private
Attributes inherited from TestFormulae
#artifact_cache, #downloaded_artifacts, #skipped_or_failed_formulae
Attributes inherited from Test
Instance Method Summary collapse
- #dependents_for_shard(dependents, shard) ⇒ Array<DependentWithDependencies> private
- #initialize(tap:, git:, dry_run:, fail_fast:, verbose:) ⇒ void constructor private
- #run!(args:) ⇒ void private
- #split_source_dependents(dependents, max = MAX_DEPENDENTS_FROM_SOURCE) ⇒ Array<(Array<DependentWithDependencies>, Array<DependentWithDependencies>)> private
Methods inherited from TestFormulae
#cleanup_package_manager_caches, #download_artifacts_from_previous_run!
Methods included from OS::Linux::TestBot::TestFormulae
#previous_run_artifact_specifier
Methods included from OS::Mac::TestBot::TestFormulae
#previous_run_artifact_specifier
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_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(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.
28 29 30 31 32 33 34 35 36 |
# File 'test_bot/formulae_dependents.rb', line 28 def initialize(tap:, git:, dry_run:, fail_fast:, verbose:) super @testing_formulae_with_tested_dependents = T.let([], T::Array[String]) @tested_dependents_list = T.let(nil, T.nilable(Pathname)) @dependent_testing_formulae = T.let([], T::Array[String]) @tested_dependents = T.let([], T::Array[String]) @formulae_dependents_filter = T.let(nil, T.nilable(T::Array[String])) @dependent_pairs_by_formula = T.let({}, T::Hash[String, T::Array[DependentWithDependencies]]) end |
Instance Attribute Details
#tested_formulae=(value) ⇒ Array<String> (writeonly)
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.
17 18 19 |
# File 'test_bot/formulae_dependents.rb', line 17 def tested_formulae=(value) @tested_formulae = value end |
#testing_formulae=(value) ⇒ Array<String> (writeonly)
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.
14 15 16 |
# File 'test_bot/formulae_dependents.rb', line 14 def testing_formulae=(value) @testing_formulae = value end |
Instance Method Details
#dependents_for_shard(dependents, shard) ⇒ Array<DependentWithDependencies>
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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'test_bot/formulae_dependents.rb', line 103 def dependents_for_shard(dependents, shard) unless shard.match?(%r{\A[1-9]\d*/[1-9]\d*\z}) raise UsageError, "`--formulae-dependents-shard` must use the format <SHARD/TOTAL>." end shard_parts = shard.split("/", 2) shard_index = shard_parts.fetch(0).to_i shard_count = shard_parts.fetch(1).to_i if shard_index > shard_count raise UsageError, "`--formulae-dependents-shard` must not be greater than the total shard count." end return dependents if shard_count == 1 dependents_by_name = dependents.to_h { |dependent, deps| [dependent.full_name, [dependent, deps]] } edges = dependents.to_h { |dependent, _| [dependent.full_name, T.let([], T::Array[String])] } dependents.each do |dependent, deps| deps.each do |dep| dep_name = dep.to_formula.full_name next unless edges.key?(dep_name) edges.fetch(dependent.full_name) << dep_name edges.fetch(dep_name) << dependent.full_name end end seen = T.let(Set.new, T::Set[String]) groups = T.let([], T::Array[T::Array[DependentWithDependencies]]) max_group_size = (dependents.size + shard_count - 1) / shard_count dependents.map(&:first).each do |dependent| next if seen.include?(dependent.full_name) group = T.let([], T::Array[DependentWithDependencies]) queue = T.let([dependent.full_name], T::Array[String]) until queue.empty? name = queue.fetch(0) queue.shift next if seen.include?(name) seen << name group << dependents_by_name.fetch(name) break if group.size >= max_group_size queue.concat(edges.fetch(name).reject { |edge| seen.include?(edge) }) end groups << group end shards = Array.new(shard_count) { T.let([], T::Array[DependentWithDependencies]) } groups.sort_by { |group| [-group.count, group.map { |dependent, _| dependent.full_name }.min.to_s] } .each do |group| group_shard_index = 0 shards.each_with_index do |current_shard, index| group_shard_index = index if current_shard.count < shards.fetch(group_shard_index).count end shards.fetch(group_shard_index).concat(group) end shards.fetch(shard_index - 1).sort_by { |dependent, _| dependent.full_name } end |
#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.
39 40 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'test_bot/formulae_dependents.rb', line 39 def run!(args:) if args.formulae_dependents_shard.present? && !args.only_formulae_dependents? raise UsageError, "`--formulae-dependents-shard` requires `--only-formulae-dependents`." end test "brew", "untap", "--force", "homebrew/cask" if !tap&.core_cask_tap? && CoreCaskTap.instance.installed? installable_bottles = @tested_formulae - @skipped_or_failed_formulae unneeded_formulae = @tested_formulae - @testing_formulae @skipped_or_failed_formulae += unneeded_formulae info_header "Skipped or failed formulae:" puts skipped_or_failed_formulae @testing_formulae_with_tested_dependents = [] @tested_dependents_list = Pathname("tested-dependents-#{Utils::Bottles.tag}.txt") @dependent_testing_formulae = sorted_formulae - skipped_or_failed_formulae install_formulae_if_needed_from_bottles!(installable_bottles, args:) download_artifacts_from_previous_run!("dependents{,_#{previous_run_artifact_specifier}*}", dry_run: args.dry_run?) @skip_candidates = T.let( if (tested_dependents_cache = artifact_cache/@tested_dependents_list).exist? tested_dependents_cache.read.split("\n") else [] end, T.nilable(T::Array[String]), ) if args.formulae_dependents_shard.present? dependent_pairs = @dependent_testing_formulae.flat_map do |formula_name| dependent_pairs_for_formula(formula_name, args:) end dependent_pairs.uniq! { |dependent, _| dependent.full_name } @formulae_dependents_filter = dependents_for_shard(dependent_pairs, args.formulae_dependents_shard.to_s) .map { |dependent, _| dependent.full_name } end @dependent_testing_formulae.each do |formula_name| cleanup_package_manager_caches dependent_formulae!(formula_name, args:) puts end return unless GitHub::Actions.env_set? # Remove `bash` after it is tested, since leaving a broken `bash` # installation in the environment can cause issues with subsequent # GitHub Actions steps. return unless @dependent_testing_formulae.include?("bash") test "brew", "uninstall", "--formula", "--force", "bash" end |
#split_source_dependents(dependents, max = MAX_DEPENDENTS_FROM_SOURCE) ⇒ Array<(Array<DependentWithDependencies>, Array<DependentWithDependencies>)>
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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'test_bot/formulae_dependents.rb', line 174 def split_source_dependents(dependents, max = MAX_DEPENDENTS_FROM_SOURCE) source_dependents, dependents = dependents.partition do |dependent, deps| next false unless build_dependent_from_source?(dependent) deps.all? do |d| bottled_or_built?(d.to_formula, @dependent_testing_formulae) end end return [source_dependents, dependents] if source_dependents.count <= max ohai "Only source building #{max} of #{source_dependents.count} dependents" @formula_install_ranks ||= T.let(begin analytics = begin require "api/analytics" Homebrew::API::Analytics.fetch "install", 90 rescue ArgumentError {} end analytics["items"].to_a.each_with_object({}) do |item, hash| formula = item["formula"] number = item["number"] next if formula.blank? || number.blank? hash[formula.to_s] = number.to_i end end, T.nilable(T::Hash[String, Integer])) if @formula_install_ranks.present? last = @formula_install_ranks.each_value.max.to_i + 1 source_dependents.sort_by! do |dependent, _| [@formula_install_ranks.fetch(dependent.full_name, last), dependent.full_name] end end dependents.concat(source_dependents.slice!(max..).to_a) [source_dependents, dependents] end |