Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ permissions:
contents: read

jobs:
lint:
name: Lint
uses: ./.github/workflows/bazel.yml
with:
name: Lint
os: windows
run: ./go dotnet:lint

build:
name: Build
uses: ./.github/workflows/bazel.yml
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ jobs:
uses: ./.github/workflows/bazel.yml
with:
name: Check Format
run: ./scripts/github-actions/check-format.sh
run: |
# Run format - auto-fixes code style issues
./go format
# Fail if there were changes (triggers commit-fixes job)
if ! git diff --quiet; then
echo "Format made changes"
exit 1
fi
artifact-name: format-changes

fork-format-error:
Expand All @@ -61,7 +68,7 @@ jobs:
steps:
- name: Format instructions
run: |
echo "::error::Code needs formatting. Run ./scripts/format.sh locally and push changes."
echo "::error::Code needs formatting. Run './go format' locally and push changes."
exit 1

check-bot-commit:
Expand Down
29 changes: 1 addition & 28 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,12 @@ jobs:
run: |
bazel build //py:selenium-wheel //py:selenium-sdist

docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout source tree
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Generate docs
run: |
tox -c py/tox.ini
env:
TOXENV: docs

typing:
name: Type Checker
uses: ./.github/workflows/bazel.yml
with:
name: Type Checker
run: bazel run //py:mypy

lint:
name: Lint
uses: ./.github/workflows/bazel.yml
with:
name: Lint
run: bazel run //py:ruff-check
run: ./go py:lint

unit-tests:
name: Unit Tests
Expand Down
16 changes: 4 additions & 12 deletions .github/workflows/ci-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@ jobs:
name: Build
run: bazel build //rb:selenium-devtools //rb:selenium-webdriver

docs:
name: Documentation
lint:
name: Lint
needs: build
uses: ./.github/workflows/bazel.yml
with:
name: Documentation
run: bazel run //rb:docs

steep-check:
name: Type Check (Steep)
needs: build
uses: ./.github/workflows/bazel.yml
with:
name: Type Check (Steep)
run: bazel run //rb:steep
name: Lint
run: ./go rb:lint

unit-tests:
name: Unit Tests
Expand Down
81 changes: 36 additions & 45 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,49 +123,31 @@ task :release_updates, [:tag, :channel] do |_task, arguments|
Rake::Task["#{language}:changelogs"].invoke
end

desc 'Run linters for all languages (skip with: ./go lint -rb -rust)'
task :lint do |_task, arguments|
failures = []
values = arguments.to_a

unless values.delete('-rust')
puts 'Linting rust...'
begin
Rake::Task['rust:lint'].invoke
rescue StandardError => e
failures << "rust: #{e.message}"
end
end
desc 'Format code (auto-fix issues across project, skip with -<lang>)'
task :format do |_task, arguments|
args = arguments.to_a

begin
Rake::Task['all:lint'].invoke(*values)
rescue StandardError => e
failures << e.message
end
puts 'Formatting Bazel files...'
Bazel.execute('run', [], '//:buildifier')

puts 'Linting Bazel files...'
begin
Bazel.execute('run', [], '//:buildifier')
rescue StandardError => e
failures << "buildifier: #{e.message}"
end
puts 'Updating copyright headers...'
Bazel.execute('run', [], '//scripts:update_copyright')

puts 'Linting shell scripts and GitHub Actions...'
begin
shellcheck = Bazel.execute('build', [], '@multitool//tools/shellcheck')
Bazel.execute('run', ['--', '-shellcheck', shellcheck], '@multitool//tools/actionlint:cwd')
rescue StandardError => e
failures << "shellcheck/actionlint: #{e.message}"
unless args.delete('-rust')
puts 'Formatting rust...'
Rake::Task['rust:format'].invoke
end

puts 'Updating copyright headers...'
begin
Bazel.execute('run', [], '//scripts:update_copyright')
rescue StandardError => e
failures << "copyright: #{e.message}"
end
Rake::Task['all:format'].invoke(*args)
end

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

raise "Lint failed:\n#{failures.join("\n")}" unless failures.empty?
Rake::Task['all:lint'].invoke
end

# Legacy aliases - call namespaced tasks
Expand All @@ -180,6 +162,10 @@ task 'publish-maven-snapshot' do
end
task 'release-java' => 'java:release'

LANG_ALIASES = {
'python' => 'py', 'ruby' => 'rb', 'javascript' => 'node', 'js' => 'node'
}.freeze

namespace :all do
desc 'Pin dependencies for all language bindings'
task :pin do
Expand Down Expand Up @@ -255,16 +241,21 @@ namespace :all do
Rake::Task['node:release'].invoke(*args)
end

desc 'Run linters for all language bindings (skip with: ./go all:lint -rb)'
task :lint do |_task, arguments|
all_langs = %w[java py rb node]
skip = arguments.to_a.select { |a| a.start_with?('-') }.map { |a| a.delete_prefix('-') }
invalid = skip - all_langs
raise "Unknown languages: #{invalid.join(', ')}. Valid: #{all_langs.join(', ')}" if invalid.any?
desc 'Format code for all language bindings (skip with -java -py -rb -dotnet -node)'
task :format do |_task, arguments|
all_langs = %w[java py rb dotnet node]
skip = arguments.to_a.map { |a| LANG_ALIASES.fetch(a.delete_prefix('-'), a.delete_prefix('-')) }
(all_langs - skip).each do |lang|
puts "Formatting #{lang}..."
Rake::Task["#{lang}:format"].invoke
end
Comment thread
titusfortner marked this conversation as resolved.
end

langs = all_langs - skip
desc 'Run linters for all language bindings'
task :lint do
all_langs = %w[java py rb dotnet node]
failures = []
langs.each do |lang|
all_langs.each do |lang|
puts "Linting #{lang}..."
Rake::Task["#{lang}:lint"].invoke
rescue StandardError => e
Expand Down
8 changes: 7 additions & 1 deletion rake_tasks/bazel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def self.windows?
(RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) != nil
end

def self.format_cmd(cmd, verbose: false, max_args: 6)
return cmd.join(' ') if verbose || cmd.length <= max_args

"#{cmd[0...max_args].join(' ')} ... (#{cmd.length - max_args} more args)"
end

def self.execute(kind, args, target, &block)
verbose = Rake::FileUtilsExt.verbose_flag

Expand All @@ -23,14 +29,14 @@ def self.execute(kind, args, target, &block)
cmd_out = ''
cmd_exit_code = 0

puts "Executing: #{format_cmd(cmd, verbose: verbose)}"
if windows?
cmd += ['2>&1']
cmd_line = cmd.join(' ')
cmd_out = `#{cmd_line}`.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
puts cmd_out if verbose
cmd_exit_code = $CHILD_STATUS
else
puts "Executing: #{cmd.join(' ')}"
Open3.popen2e(*cmd) do |stdin, stdouts, wait|
is_running = true
stdin.close
Expand Down
32 changes: 23 additions & 9 deletions rake_tasks/dotnet.rake
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ task :verify do
SeleniumRake.verify_package_published("https://api.nuget.org/v3/registration5-semver1/selenium.support/#{dotnet_version}.json")
end

desc 'Generate .NET documentation'
desc 'Generate and stage .NET documentation'
task :docs do |_task, arguments|
if dotnet_version.include?('nightly') && !arguments.to_a.include?('force')
abort('Aborting documentation update: nightly versions should not update docs.')
end

Rake::Task['dotnet:docs_generate'].invoke
Comment thread
titusfortner marked this conversation as resolved.
end
Comment thread
titusfortner marked this conversation as resolved.

desc 'Generate .NET documentation without staging'
task :docs_generate do
puts 'Generating .NET documentation'
FileUtils.rm_rf('build/docs/api/dotnet/')
Bazel.execute('run', [], '//dotnet:docs')
Expand Down Expand Up @@ -113,16 +118,25 @@ task :pin do
'@rules_dotnet//tools/paket2bazel:paket2bazel')
end

desc 'Run .NET formatter (whitespace only)'
task :format do |_task, arguments|
raise ArgumentError, 'arguments not supported for this task' unless arguments.to_a.empty?

desc 'Format .NET code (whitespace and style)'
task :format do
# style needs to run before whitespace
puts ' Running dotnet format style...'
Bazel.execute('run', ['--', 'style', '--severity', 'warn'], '//dotnet:format')
puts ' Running dotnet format whitespace...'
Bazel.execute('run', ['--', 'whitespace'], '//dotnet:format')
end

desc 'Run .NET linter (format + style + analyzers)'
task :lint do |_task, arguments|
puts ' Running dotnet format...'
Bazel.execute('run', ['--'] + arguments.to_a, '//dotnet:format')
desc 'Run .NET linter (dotnet format analyzers, docs)'
task :lint do
puts ' Running dotnet format analyzers...'
Bazel.execute('run', ['--', 'analyzers', '--verify-no-changes'], '//dotnet:format')
Rake::Task['dotnet:docs_generate'].invoke

# TODO: Identify specific diagnostics that we want to enforce but can't be auto-corrected (e.g., 'IDE0060'):
enforced_diagnostics = []
next if enforced_diagnostics.empty?

arguments = %w[-- style --severity info --verify-no-changes --diagnostics] + enforced_diagnostics
Comment thread
titusfortner marked this conversation as resolved.
Bazel.execute('run', arguments, '//dotnet:format')
Comment thread
titusfortner marked this conversation as resolved.
end
33 changes: 23 additions & 10 deletions rake_tasks/java.rake
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,14 @@ task :install do
end
end

desc 'Generate Java documentation'
task docs: %i[//java/src/org/openqa/selenium/grid:all-javadocs] do |_task, arguments|
desc 'Generate and stage Java documentation'
task :docs do |_task, arguments|
if java_version.include?('SNAPSHOT') && !arguments.to_a.include?('force')
abort('Aborting documentation update: snapshot versions should not update docs.')
end

puts 'Generating Java documentation'
Rake::Task['java:docs_generate'].invoke

FileUtils.rm_rf('build/docs/api/java')
FileUtils.mkdir_p('build/docs/api/java')
out = 'bazel-bin/java/src/org/openqa/selenium/grid/all-javadocs.jar'
Expand All @@ -333,6 +334,12 @@ task docs: %i[//java/src/org/openqa/selenium/grid:all-javadocs] do |_task, argum
end
end

desc 'Generate Java documentation without staging'
task :docs_generate do
puts 'Generating Java documentation'
Bazel.execute('build', [], '//java/src/org/openqa/selenium/grid:all-javadocs')
end

desc 'Update Maven dependencies'
task :update do
puts 'Updating Maven dependencies'
Expand Down Expand Up @@ -383,12 +390,18 @@ task :version, [:version] do |_task, arguments|
File.open(file, 'w') { |f| f.puts text }
end

desc 'Run Java formatter (google-java-format)'
task :lint do
desc 'Format Java code with google-java-format'
task :format do
puts ' Running google-java-format...'
formatter = nil
Bazel.execute('run', ['--run_under=echo'], '//scripts:google-java-format') do |output|
formatter = output.lines.last.strip
end
sh formatter, '--replace', *Dir.glob('java/**/*.java')
java_files = Dir.glob(File.join(Dir.pwd, 'java', '**', '*.java'))
return if java_files.empty?

args = ['--', '--replace'] + java_files
Bazel.execute('run', args, '//scripts:google-java-format')
end

# ErrorProne runs at build time, SpotBugs runs as test targets in RBE
desc 'Run Java linter (docs only, other linting happens during build/test)'
task :lint do
Rake::Task['java:docs_generate'].invoke
end
20 changes: 15 additions & 5 deletions rake_tasks/node.rake
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ end
desc 'Alias for node:release'
task deploy: :release

desc 'Generate Node documentation'
desc 'Generate and stage Node documentation'
task :docs do |_task, arguments|
if node_version.include?('nightly') && !arguments.to_a.include?('force')
abort('Aborting documentation update: nightly versions should not update docs.')
end

Rake::Task['node:docs_generate'].invoke
Comment thread
titusfortner marked this conversation as resolved.
end
Comment thread
titusfortner marked this conversation as resolved.

desc 'Generate Node documentation without staging'
task :docs_generate do
puts 'Generating Node documentation'
FileUtils.rm_rf('build/docs/api/javascript/')
Bazel.execute('run', [], '//javascript/selenium-webdriver:docs')
Expand Down Expand Up @@ -150,12 +155,17 @@ task :version, [:version] do |_task, arguments|
end
end

desc 'Run Node linter (prettier)'
task :lint do |_task, arguments|
args = arguments.to_a
desc 'Format JavaScript code with prettier'
task :format do
node_dir = File.expand_path('javascript/selenium-webdriver')
prettier_config = File.join(node_dir, '.prettierrc')
puts ' Running prettier...'
Bazel.execute('run', args + ['--', node_dir, '--write', "--config=#{prettier_config}", '--log-level=warn'],
Bazel.execute('run', ['--', node_dir, '--write', "--config=#{prettier_config}", '--log-level=warn'],
'//javascript:prettier')
end

desc 'Run JavaScript linter (docs only for now, eslint needs bazel integration work)'
task :lint do
# TODO: Add eslint once bazel target properly resolves workspace modules
Rake::Task['node:docs_generate'].invoke
end
Loading
Loading