|
3 | 3 | require 'json' |
4 | 4 | require 'set' |
5 | 5 |
|
6 | | -# Dirs that affect all bindings - changes here trigger "run all tests" |
7 | | -HIGH_IMPACT_DIRS = %w[common rust/src javascript/atoms javascript/webdriver/atoms].freeze |
8 | | -HIGH_IMPACT_PATTERN = %r{\A(?:#{HIGH_IMPACT_DIRS.map { |d| Regexp.escape(d) }.join('|')})(?:/|$)} |
| 6 | +# Paths that affect every binding - changes here trigger "run all tests" |
| 7 | +HIGH_IMPACT_PATHS = %w[common rust/src javascript/atoms javascript/webdriver/atoms MODULE.bazel].freeze |
| 8 | +HIGH_IMPACT_PATTERN = %r{\A(?:#{HIGH_IMPACT_PATHS.map { |p| Regexp.escape(p) }.join('|')})(?:/|$)} |
| 9 | + |
| 10 | +# Binding overrides for files the index can't reach (workspace dep files, root configs) |
| 11 | +TARGET_OVERRIDES = { |
| 12 | + 'dotnet/paket.lock' => 'dotnet', |
| 13 | + 'java/maven_install.json' => 'java', |
| 14 | + 'py/requirements_lock.txt' => 'py', |
| 15 | + 'rb/Gemfile.lock' => 'rb', |
| 16 | + 'javascript/selenium-webdriver/package.json' => 'javascript' |
| 17 | +}.freeze |
9 | 18 |
|
10 | 19 | # ./go bazel:affected_targets --> HEAD^..HEAD with default index |
11 | 20 | # ./go bazel:affected_targets abc123..def456 --> explicit range |
@@ -34,7 +43,10 @@ task :affected_targets do |_task, args| |
34 | 43 | targets = if changed_files.any? { |f| f.match?(HIGH_IMPACT_PATTERN) } |
35 | 44 | BINDING_TARGETS.values |
36 | 45 | elsif File.exist?(index_file) |
37 | | - affected_targets_with_index(changed_files, index_file) |
| 46 | + override_targets = changed_files.filter_map { |f| BINDING_TARGETS[TARGET_OVERRIDES[f]] } |
| 47 | + covered_pattern = Regexp.union(override_targets.map { |t| %r{\A#{Regexp.escape(t.delete_suffix('/...'))}[:/]} }) |
| 48 | + index_targets = affected_targets_with_index(changed_files, index_file).grep_v(covered_pattern) |
| 49 | + (override_targets + index_targets).uniq |
38 | 50 | else |
39 | 51 | puts 'No index found, using directory-based fallback' |
40 | 52 | affected_targets_by_directory(changed_files) |
@@ -98,8 +110,8 @@ def query_test_deps(test) |
98 | 110 | deps = out.lines.map(&:strip).select { |l| l.start_with?('//') } |
99 | 111 | end |
100 | 112 | deps.reject do |d| |
101 | | - # Skip high-impact dirs and root package targets (generated files, LICENSE, etc) |
102 | | - HIGH_IMPACT_DIRS.any? { |dir| d.start_with?("//#{dir}") } || d.start_with?('//:') |
| 113 | + # Skip high-impact paths and root package targets (generated files, LICENSE, etc) |
| 114 | + HIGH_IMPACT_PATHS.any? { |path| d.start_with?("//#{path}") } || d.start_with?('//:') |
103 | 115 | end |
104 | 116 | rescue StandardError => e |
105 | 117 | puts " Warning: Failed to query deps for #{test}: #{e.message}" |
|
0 commit comments