Skip to content

Commit

Permalink
[rb] Update rules_ruby and run unit tests on RBE
Browse files Browse the repository at this point in the history
This commit upgrades Ruby ruleset for Bazel to the most recent version,
which notably provides a hermetic Bundle installation and allows to use
JRuby with RBE environment. Right now not all tests can be used with
RBE, so more commits are to land adding them one-by-one.
  • Loading branch information
p0deje committed Jan 17, 2024
1 parent 6127b5f commit 67490a3
Show file tree
Hide file tree
Showing 32 changed files with 203 additions and 54 deletions.
8 changes: 7 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ test --test_env=PYTHON_VERSION

test --test_env=RUBYOPT="-Irb/lib -w"

# Speed up JRuby startup.
# https://github.com/jruby/jruby/wiki/Improving-startup-time

build --action_env=JRUBY_OPTS="--dev"
test --test_env=JRUBY_OPTS="--dev"

# JRuby/TruffleRuby: https://github.com/jruby/jruby/issues/5661

build --action_env=HOME
Expand All @@ -76,7 +82,7 @@ test:windows --test_env=PROGRAMFILES(X86)="C:\\Program Files (x86)"
test --test_timeout=1800

test:node_debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results
test:ruby_debug --test_output=streamed --test_env=RUBY_DEBUG_FORK_MODE=parent --run_under="@bundle//:bin/rdbg --nonstop --open --command"
test:ruby_debug --test_output=streamed --test_env=RUBY_DEBUG_FORK_MODE=parent --run_under="@bundle//bin:rdbg --nonstop --open --command"

# The RBE to use
build:remote --bes_results_url=https://gypsum.cluster.engflow.com/invocation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
crates: rust/Cargo.Bazel.lock
npm: package-lock.json
pypi__pip: py/requirements_lock.txt
rules_ruby_dist: rb/ruby_version.bzl
ruby: rb/.ruby_version
repository-cache: true
- name: Setup Fluxbox and Xvfb
if: inputs.os == 'ubuntu' && inputs.browser != ''
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci-rbe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ jobs:
with:
name: Check format script run
cache-key: rbe
ruby-version: jruby-9.4.2.0
ruby-version: jruby-9.4.5.0
run: ./scripts/github-actions/check-format.sh

test:
name: Test
uses: ./.github/workflows/bazel.yml
with:
# TODO: experiment with turning off caches
name: All RBE tests
cache-key: rbe
ruby-version: jruby-9.4.2.0
ruby-version: jruby-9.4.5.0
run: ./scripts/github-actions/ci-build.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Useful command line options:
In addition to the [Common Options Examples](#common-options-examples), here are some additional Ruby specific ones:
* `--test_arg "-tfocus"` - test only [focused specs](https://relishapp.com/rspec/rspec-core/v/3-12/docs/filtering/inclusion-filters)
* `--test_arg "-eTimeouts"` - test only specs which name include "Timeouts"
* `--test_arg "<any other RSpec argument>"` - pass any extra RSpec arguments (see `bazel run @bundle//:bin/rspec -- --help`)
* `--test_arg "<any other RSpec argument>"` - pass any extra RSpec arguments (see `bazel run @bundle//bin:rspec -- --help`)

Supported environment variables for use with `--test_env`:

Expand Down
15 changes: 9 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,22 @@ pin_browsers()

http_archive(
name = "rules_ruby",
sha256 = "e3495d0129222572654cc5dd5c72c6c997513d65fb8649f43a860ab15334a1c2",
strip_prefix = "rules_ruby-0.4.1",
url = "https://github.com/bazel-contrib/rules_ruby/releases/download/v0.4.1/rules_ruby-v0.4.1.tar.gz",
sha256 = "9bfab76e1272dae72355c65cc858ede68b659716381485baa4c8e7a70ddc38a6",
strip_prefix = "rules_ruby-0.5.0",
url = "https://github.com/bazel-contrib/rules_ruby/releases/download/v0.5.0/rules_ruby-v0.5.0.tar.gz",
)

load(
"@rules_ruby//ruby:deps.bzl",
"rb_bundle",
"rb_bundle_fetch",
"rb_register_toolchains",
)

rb_register_toolchains(version_file = "//:rb/.ruby-version")
rb_register_toolchains(
version_file = "//:rb/.ruby-version",
)

rb_bundle(
rb_bundle_fetch(
name = "bundle",
srcs = [
"//:rb/lib/selenium/devtools/version.rb",
Expand All @@ -353,6 +355,7 @@ rb_bundle(
"//:rb/selenium-webdriver.gemspec",
],
gemfile = "//:rb/Gemfile",
gemfile_lock = "//:rb/Gemfile.lock",
)

http_archive(
Expand Down
6 changes: 3 additions & 3 deletions rb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ rb_binary(
"--readme=rb/README.md",
"rb/",
],
main = "@bundle//:bin/yard",
main = "@bundle//bin:yard",
deps = [
":selenium-devtools",
":selenium-webdriver",
Expand All @@ -180,7 +180,7 @@ rb_test(
"rb/",
],
data = [".rubocop.yml"],
main = "@bundle//:bin/rubocop",
main = "@bundle//bin:rubocop",
tags = ["no-sandbox"],
deps = [
":selenium-devtools",
Expand All @@ -199,7 +199,7 @@ rb_binary(
"-rselenium/devtools",
"-Irb/lib",
],
main = "@bundle//:bin/irb",
main = "@bundle//bin:irb",
deps = [
":selenium-devtools",
":selenium-webdriver",
Expand Down
2 changes: 0 additions & 2 deletions rb/selenium-devtools.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

root = File.realpath(File.dirname(__FILE__))
raise "cwd must be #{root} when reading gemspec" if root != Dir.pwd

$LOAD_PATH.push(File.expand_path('lib', root))
require 'selenium/devtools/version'

Expand Down
2 changes: 0 additions & 2 deletions rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

root = File.expand_path(File.dirname(__FILE__))
raise "cwd must be #{root} when reading gemspec" if root != Dir.pwd

$LOAD_PATH.push(File.expand_path('lib', root))
require 'selenium/webdriver/version'

Expand Down
9 changes: 8 additions & 1 deletion rb/spec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
load("@rules_ruby//ruby:defs.bzl", "rb_library")

rb_library(
name = "rspec_matchers",
testonly = True,
srcs = ["rspec_matchers.rb"],
visibility = ["//rb/spec:__subpackages__"],
)

# List of dependencies can be gathered by running:
# bazel query 'kind("rb_.* rule", //rb/spec/...) except //rb/spec:spec' | xargs -I{} echo '"{}",'

rb_library(
name = "spec",
testonly = True,
srcs = ["rspec_matchers.rb"],
visibility = ["//rb:__pkg__"],
deps = [
":rspec_matchers",
"//rb/spec/integration/selenium/webdriver:action_builder",
"//rb/spec/integration/selenium/webdriver:bidi",
"//rb/spec/integration/selenium/webdriver:devtools",
Expand Down
34 changes: 25 additions & 9 deletions rb/spec/integration/selenium/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ package(default_visibility = ["//rb:__subpackages__"])
rb_library(
name = "spec_helper",
testonly = True,
srcs = glob([
srcs = [
"spec_helper.rb",
"spec_support.rb",
"spec_support/**/*",
]),
] + glob(["spec_support/**/*"]),
data = [
"//rb:manager-linux",
"//rb:manager-macos",
Expand All @@ -19,7 +18,24 @@ rb_library(
"//rb/spec/integration:remote": ["//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar"],
"//conditions:default": [],
}),
deps = ["@bundle"],
deps = [
"//rb/lib:selenium-webdriver",
"//rb/lib/selenium:devtools",
"//rb/lib/selenium:server",
"//rb/lib/selenium:webdriver",
"//rb/lib/selenium/webdriver:atoms",
"//rb/lib/selenium/webdriver:common",
"//rb/lib/selenium/webdriver:remote",
"//rb/spec:rspec_matchers",
"@bundle",
] + select({
"//rb/spec/integration:edge": ["//rb/lib/selenium/webdriver:edge"],
"//rb/spec/integration:firefox": ["//rb/lib/selenium/webdriver:firefox"],
"//rb/spec/integration:ie": ["//rb/lib/selenium/webdriver:ie"],
"//rb/spec/integration:safari": ["//rb/lib/selenium/webdriver:safari"],
"//rb/spec/integration:safari-preview": ["//rb/lib/selenium/webdriver:safari"],
"//conditions:default": ["//rb/lib/selenium/webdriver:chrome"],
}),
)

[
Expand All @@ -29,7 +45,7 @@ rb_library(
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
":spec_helper",
Expand All @@ -53,7 +69,7 @@ rb_test(
srcs = ["bidi_spec.rb"],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS + ["exclusive-if-local"],
deps = [
":spec_helper",
Expand All @@ -68,7 +84,7 @@ rb_test(
srcs = ["devtools_spec.rb"],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS + ["exclusive-if-local"],
deps = [
":spec_helper",
Expand All @@ -83,7 +99,7 @@ rb_test(
srcs = ["driver_spec.rb"],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
":spec_helper",
Expand All @@ -102,7 +118,7 @@ rb_test(
srcs = ["element_spec.rb"],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
":spec_helper",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS + ["exclusive-if-local"],
deps = [
"//rb/lib/selenium/devtools",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
"//rb/lib/selenium/webdriver:chrome",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/edge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
"//rb/lib/selenium/webdriver:edge",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
"//rb/lib/selenium/webdriver:firefox",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/remote/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
"//rb/lib/selenium/webdriver:remote",
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/safari/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package(default_visibility = ["//rb:__subpackages__"])
srcs = [file],
args = ["rb/spec/"],
env = ENV,
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = TAGS,
deps = [
"//rb/lib/selenium/webdriver:safari",
Expand Down
13 changes: 11 additions & 2 deletions rb/spec/unit/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ rb_test(
size = "small",
srcs = ["devtools_spec.rb"],
args = ["rb/spec/"],
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = ["no-sandbox"],
deps = [
"//rb/lib:selenium-webdriver",
"//rb/lib/selenium:devtools",
"//rb/lib/selenium:webdriver",
"//rb/lib/selenium/webdriver:atoms",
"//rb/lib/selenium/webdriver:common",
"@bundle",
],
)
Expand All @@ -20,10 +24,15 @@ rb_test(
size = "small",
srcs = ["server_spec.rb"],
args = ["rb/spec/"],
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = ["no-sandbox"],
deps = [
"//rb/lib:selenium-webdriver",
"//rb/lib/selenium:devtools",
"//rb/lib/selenium:server",
"//rb/lib/selenium:webdriver",
"//rb/lib/selenium/webdriver:atoms",
"//rb/lib/selenium/webdriver:common",
"@bundle",
],
)
6 changes: 5 additions & 1 deletion rb/spec/unit/selenium/devtools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ rb_test(
size = "small",
srcs = ["cdp_client_generator_spec.rb"],
args = ["rb/spec/"],
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = ["no-sandbox"],
deps = [
"//rb/lib:selenium-webdriver",
"//rb/lib/selenium:webdriver",
"//rb/lib/selenium/devtools:cdp-generate",
"//rb/lib/selenium/webdriver:atoms",
"//rb/lib/selenium/webdriver:common",
"@bundle",
],
)
29 changes: 26 additions & 3 deletions rb/spec/unit/selenium/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ rb_library(
name = "spec_helper",
testonly = True,
srcs = ["spec_helper.rb"],
deps = ["@bundle"],
deps = [
"//rb/lib:selenium-webdriver",
"//rb/lib/selenium:webdriver",
"//rb/lib/selenium/webdriver:atoms",
"//rb/spec:rspec_matchers",
"@bundle",
],
)

rb_test(
name = "search_context",
size = "small",
srcs = ["search_context_spec.rb"],
args = ["rb/spec/"],
main = "@bundle//bin:rspec",
tags = ["no-sandbox"],
deps = [
":spec_helper",
"//rb/lib/selenium/webdriver:common",
"//rb/lib/selenium/webdriver:remote",
],
)

[
Expand All @@ -15,12 +35,15 @@ rb_library(
size = "small",
srcs = [file],
args = ["rb/spec/"],
main = "@bundle//:bin/rspec",
main = "@bundle//bin:rspec",
tags = ["no-sandbox"],
deps = [
":spec_helper",
"//rb/lib/selenium/webdriver:common",
],
)
for file in glob(["*_spec.rb"])
for file in glob(
["*_spec.rb"],
exclude = ["search_context_spec.rb"],
)
]
Loading

0 comments on commit 67490a3

Please sign in to comment.