Skip to content

Commit c779dcd

Browse files
authored
[build] aggregate all lint errors instead of failing fast (#17637)
* [build] aggregate all lint errors instead of failing fast * [build] remove counts from error message
1 parent c474d76 commit c779dcd

5 files changed

Lines changed: 50 additions & 41 deletions

File tree

Rakefile

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,17 @@ task :format do |_task, arguments|
143143
Rake::Task['all:format'].invoke(*args)
144144
end
145145

146-
desc 'Run linters (may auto-fix some issues; stricter checks than :format)'
147-
task :lint do
148-
puts 'Linting shell scripts and GitHub Actions...'
146+
def lint_actions
149147
shellcheck = Bazel.execute('build', [], '@multitool//tools/shellcheck')
150148
Bazel.execute('run', ['--', '-shellcheck', shellcheck], '@multitool//tools/actionlint:cwd')
149+
end
151150

152-
Rake::Task['all:lint'].invoke
151+
desc 'Run linters (may auto-fix some issues; stricter checks than :format)'
152+
task :lint do
153+
SeleniumRake.aggregate_errors(
154+
shellcheck_and_actionlint: -> { lint_actions },
155+
all: -> { Rake::Task['all:lint'].invoke }
156+
)
153157
end
154158

155159
# Legacy aliases - call namespaced tasks
@@ -215,24 +219,18 @@ namespace :all do
215219
desc 'Validate release credentials for all languages'
216220
task :check_credentials do |_task, arguments|
217221
args = arguments.to_a
218-
failures = []
219-
%w[java py rb dotnet node].each do |lang|
220-
Rake::Task["#{lang}:check_credentials"].invoke(*args)
221-
rescue StandardError => e
222-
failures << "#{lang}: #{e.message}"
222+
steps = %w[java py rb dotnet node].to_h do |lang|
223+
[lang.to_sym, -> { Rake::Task["#{lang}:check_credentials"].invoke(*args) }]
223224
end
224-
raise "Credential check failed:\n#{failures.join("\n")}" unless failures.empty?
225+
SeleniumRake.aggregate_errors(**steps)
225226
end
226227

227228
desc 'Verify all packages are published to their registries'
228229
task :verify do
229-
failures = []
230-
%w[java py rb dotnet node].each do |lang|
231-
Rake::Task["#{lang}:verify"].invoke
232-
rescue StandardError => e
233-
failures << "#{lang}: #{e.message}"
230+
steps = %w[java py rb dotnet node].to_h do |lang|
231+
[lang.to_sym, -> { Rake::Task["#{lang}:verify"].invoke }]
234232
end
235-
raise "Verification failed:\n#{failures.join("\n")}" unless failures.empty?
233+
SeleniumRake.aggregate_errors(**steps)
236234
end
237235

238236
desc 'Release all artifacts for all language bindings'
@@ -257,15 +255,10 @@ namespace :all do
257255

258256
desc 'Run linters for all language bindings'
259257
task :lint do
260-
all_langs = %w[java py rb dotnet node]
261-
failures = []
262-
all_langs.each do |lang|
263-
puts "Linting #{lang}..."
264-
Rake::Task["#{lang}:lint"].invoke
265-
rescue StandardError => e
266-
failures << "#{lang}: #{e.message}"
258+
steps = %w[java py rb dotnet node].to_h do |lang|
259+
[lang.to_sym, -> { Rake::Task["#{lang}:lint"].invoke }]
267260
end
268-
raise "Lint failed:\n#{failures.join("\n")}" unless failures.empty?
261+
SeleniumRake.aggregate_errors(**steps)
269262
end
270263

271264
desc 'Update versions for all language bindings'

rake_tasks/common.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ def self.update_changelog(version, language, path, changelog, header)
107107
File.write(changelog, "#{header}\n#{entries}\n\n#{content}")
108108
end
109109

110+
def self.aggregate_errors(**steps)
111+
failures = steps.filter_map do |name, closure|
112+
label = name.to_s.tr('_', ' ')
113+
puts "Running #{label}..." unless name == :all
114+
closure.call
115+
nil
116+
rescue StandardError => e
117+
"#{label}: #{e.message}"
118+
end
119+
return if failures.empty?
120+
121+
raise failures.join("\n\n")
122+
end
123+
110124
def self.verify_package_published(url)
111125
puts "Verifying #{url}..."
112126
uri = URI(url)

rake_tasks/dotnet.rake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ end
127127

128128
desc 'Run .NET linter (dotnet format analyzers, docs)'
129129
task :lint do
130-
puts ' Running dotnet format analyzers...'
131-
Bazel.execute('run', ['--', 'analyzers', '--verify-no-changes'], '//dotnet:format')
132-
Rake::Task['dotnet:docs_generate'].invoke
130+
steps = {
131+
dotnet_format_analyzers: -> { Bazel.execute('run', ['--', 'analyzers', '--verify-no-changes'], '//dotnet:format') },
132+
dotnet_docs: -> { Rake::Task['dotnet:docs_generate'].invoke }
133+
}
133134

134-
# TODO: Identify specific diagnostics that we want to enforce but can't be auto-corrected (e.g., 'IDE0060'):
135135
enforced_diagnostics = []
136-
next if enforced_diagnostics.empty?
136+
if enforced_diagnostics&.any?
137+
arguments = %w[-- style --severity info --verify-no-changes --diagnostics] + enforced_diagnostics
138+
steps[:dotnet_format_style] = -> { Bazel.execute('run', arguments, '//dotnet:format') }
139+
end
137140

138-
arguments = %w[-- style --severity info --verify-no-changes --diagnostics] + enforced_diagnostics
139-
Bazel.execute('run', arguments, '//dotnet:format')
141+
SeleniumRake.aggregate_errors(**steps)
140142
end

rake_tasks/python.rake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ end
172172

173173
desc 'Run Python linters (ruff check --no-fix, mypy, docs)'
174174
task :lint do
175-
puts ' Running ruff check (verify)...'
176-
Bazel.execute('run', ['--', '--no-fix'], '//py:ruff-check')
177-
puts ' Running mypy...'
178-
Bazel.execute('run', [], '//py:mypy')
179-
Rake::Task['py:docs_generate'].invoke
175+
SeleniumRake.aggregate_errors(
176+
ruff_check: -> { Bazel.execute('run', ['--', '--no-fix'], '//py:ruff-check') },
177+
mypy: -> { Bazel.execute('run', [], '//py:mypy') },
178+
python_docs: -> { Rake::Task['py:docs_generate'].invoke }
179+
)
180180
end

rake_tasks/ruby.rake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ end
163163
desc 'Run Ruby linters (rubocop, steep, docs)'
164164
task :lint do |_task, arguments|
165165
flag = arguments.to_a.include?('-A') ? '-A' : '-a'
166-
puts ' Running rubocop...'
167-
Bazel.execute('run', ['--', flag], '//rb:rubocop')
168-
puts ' Running steep type checker...'
169-
Bazel.execute('run', [], '//rb:steep')
170-
Rake::Task['rb:docs_generate'].invoke
166+
SeleniumRake.aggregate_errors(
167+
rubocop: -> { Bazel.execute('run', ['--', flag], '//rb:rubocop') },
168+
steep_type_checker: -> { Bazel.execute('run', [], '//rb:steep') },
169+
ruby_docs: -> { Rake::Task['rb:docs_generate'].invoke }
170+
)
171171
end
172172

173173
desc 'Sync gem checksums from Gemfile.lock to MODULE.bazel (use force to re-download all)'

0 commit comments

Comments
 (0)