Skip to content

Commit

Permalink
Migrate to Bzlmod (#478)
Browse files Browse the repository at this point in the history
* Migrate to bzlmod

* More polish

* Minor fix

* Simplify repo name

* Re-enable sauceconnect

* Fix bazelrc

* Minor fix

* rm resolved_deps.py

* Register scalca test toolchain

* Register scalca test toolchain

* Register scalca test toolchain

* Fix maven targets

* Fix junit

* Add scala deps

* Fix maven coords

* Fix maven coords

* Use the correct scala_test setup

* Fix windows build

* Update presubmit configs

* Fix windows

* Fix lockfile on windows

* Fix lockfile on windows

* Run buildifier

* Re-organize bazel_dep

* Implement version selection for brower dependencies

* Remove WORKSPACE

* Rename version to install
  • Loading branch information
meteorcloudy authored Dec 20, 2024
1 parent d8208bd commit 77428ec
Show file tree
Hide file tree
Showing 35 changed files with 587 additions and 959 deletions.
5 changes: 1 addition & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
---
platforms:
ubuntu1804:
ubuntu2204:
build_targets:
- "//..."
test_flags:
- "--test_tag_filters=-noci,-external,-native,-sauce"
- "--test_output=streamed"
test_targets:
- "//..."
macos:
sauce: false
build_targets:
- "//..."
test_flags:
- "--test_tag_filters=-noci,-sauce,-external,-native"
test_targets:
- "//..."
windows:
sauce: false
build_flags:
- "--enable_runfiles"
build_targets:
Expand Down
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
common --noenable_workspace

# For running sauce-based configs.
test --test_env=SAUCE_USERNAME
test --test_env=SAUCE_ACCESS_KEY
Expand Down
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bazel-*
*.pyc
.vs/*
user.bazelrc
MODULE.bazel.lock

.idea/
dist/
17 changes: 7 additions & 10 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
################################################################################
#
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load("@python_versions//3.11:defs.bzl", "compile_pip_requirements")

licenses(["notice"]) # Apache 2.0

Expand All @@ -26,13 +26,10 @@ gazelle(
prefix = "github.com/bazelbuild/rules_webtesting",
)

setup_scala_testing_toolchain(
name = "scalatest_toolchain",
scalatest_classpath = [
"@maven//:org_scalatest_scalatest_wordspec_2_12",
"@io_bazel_rules_scala_scalactic",
"@io_bazel_rules_scala_scalatest",
"@io_bazel_rules_scala_scalatest_compatible",
"@io_bazel_rules_scala_scalatest_core",
],
compile_pip_requirements(
name = "requirements",
requirements_in = "requirements.in",
requirements_txt = "requirements_lock.txt",
requirements_windows = "requirements_lock_windows.txt",
)

100 changes: 100 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module(
name = "rules_webtesting",
version = "0.4.0",
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")

##### Go dependencies #####
bazel_dep(name = "rules_go", version = "0.51.0-rc1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.40.0", repo_name = "bazel_gazelle")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

# All *direct* Go dependencies of the module have to be listed explicitly.
use_repo(
go_deps,
"com_github_gorilla_mux",
"com_github_tebeka_selenium",
)

##### Java dependencies #####
bazel_dep(name = "rules_jvm_external", version = "6.6")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
artifacts = [
"com.google.guava:guava:33.2.1-jre",
"org.seleniumhq.selenium:selenium-remote-driver:4.27.0",
"org.seleniumhq.selenium:selenium-api:4.27.0",
"junit:junit:4.13.2",
],
)
use_repo(maven, "maven")

##### Python dependencies #####
bazel_dep(name = "rules_python", version = "1.0.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = "3.11",
)
use_repo(python, "python_3_11", "python_versions")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "rules_webtesting_py_deps",
python_version = "3.11",
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "requirements_lock_windows.txt",
)
use_repo(pip, "rules_webtesting_py_deps")

##### Scala dependencies #####
bazel_dep(name = "rules_scala", repo_name = "io_bazel_rules_scala")

# TODO: Switch to a release version once it's available in BCR.
# Otherwise, the root module has to declare the same override.
git_override(
module_name = "rules_scala",
commit = "7fb52c7fc2ef8f7670feb73c0a9869715bdc40b8",
remote = "https://github.com/mbland/rules_scala",
)

scala_deps = use_extension(
"@io_bazel_rules_scala//scala/extensions:deps.bzl",
"scala_deps",
)
scala_deps.settings(
fetch_sources = True,
)
scala_deps.toolchains(
scalatest = True,
)

##### Browsers dependencies #####
browser_repositories = use_extension("//web:extension.bzl", "browser_repositories_extension")
browser_repositories.install(version = "0.3.3")
use_repo(
browser_repositories,
"com_saucelabs_sauce_connect_linux_x64",
"com_saucelabs_sauce_connect_macos_x64",
"com_saucelabs_sauce_connect_windows_x64",
"org_chromium_chromedriver_linux_x64",
"org_chromium_chromedriver_macos_arm64",
"org_chromium_chromedriver_macos_x64",
"org_chromium_chromedriver_windows_x64",
"org_chromium_chromium_linux_x64",
"org_chromium_chromium_macos_arm64", # Only available in 0.3.3
"org_chromium_chromium_macos_x64",
"org_chromium_chromium_windows_x64",
"org_mozilla_firefox_linux_x64",
"org_mozilla_firefox_macos_arm64",
"org_mozilla_firefox_macos_x64",
"org_mozilla_geckodriver_linux_x64",
"org_mozilla_geckodriver_macos_arm64",
"org_mozilla_geckodriver_macos_x64",
)
145 changes: 5 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,145 +7,10 @@ WebDriver.

## Configure your Bazel project

For all languages, you need to add the following to your WORKSPACE file:
For all languages, you need to add the following to your MODULE.bazel file:

```bzl
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_webtesting",
sha256 = "<version-specific-sha>",
urls = [
"https://github.com/bazelbuild/rules_webtesting/releases/download/<version>/rules_webtesting.tar.gz",
],
)

load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()
```

We maintain predefined versioned browsers in
`@io_bazel_rules_webtesting//web/versioned:browsers-<version>.bzl` that can be
referenced from `@io_bazel_rules_webtesting//browsers`. Note: these versions in
these files are not locked in until the corresponding release has been created.

To use, add the following to your WORKSPACE file:

```bzl
load("@io_bazel_rules_webtesting//web/versioned:browsers-<version>.bzl", "browser_repositories")

browser_repositories(chromium=True, firefox=True)
```

Then you should add the appropriate dependencies depending on what language you
are writing your tests in:

### Java

```bzl
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")

java_repositories()
```

#### Using `rules_jvm_external`?

If you're using `rules_jvm_external` to manage your dependencies, you can add
the required artifacts directly to your `maven_install` instead of using
`java_repositories`.

```bzl
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "RULES_WEBTESTING_ARTIFACTS")

maven_install(
artifacts = [
# Your artifacts
] + RULES_WEBTESTING_ARTIFACTS,
# Enabling compatability support is required.
generate_compat_repositories = True,
)
```

### Scala

```bzl
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")

java_repositories()

rule_scala_version = "e4560ac332e9da731c1e50a76af2579c55836a5c"

http_archive(
name = "io_bazel_rules_scala",
sha256 = "ccf19e8f966022eaaca64da559c6140b23409829cb315f2eff5dc3e757fb6ad8",
strip_prefix = "rules_scala-%s" % rules_scala_version,
type = "zip",
url = "https://github.com/bazelbuild/rules_scala/archive/%s.zip" % rules_scala_version,
)

# Stores Scala version and other configuration
# 2.12 is a default version, other versions can be use by passing them explicitly:
# scala_config(scala_version = "2.11.12")
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
scala_config()

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
scala_register_toolchains()

# optional: setup ScalaTest toolchain and dependencies
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
scalatest_repositories()
scalatest_toolchain()
```

### Python

```bzl
load("@io_bazel_rules_webtesting//web:py_repositories.bzl", "py_repositories")

py_repositories()
```

### Go

```bzl
http_archive(
name = "io_bazel_rules_go",
sha256 = "b7a62250a3a73277ade0ce306d22f122365b513f5402222403e507f2f997d421",
urls = [
"https://github.com/bazelbuild/rules_go/releases/download/0.16.3/rules_go-0.16.3.tar.gz",
],
)

http_archive(
name = "bazel_gazelle",
sha256 = "6e875ab4b6bf64a38c352887760f21203ab054676d9c1b274963907e0768740d",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.15.0/bazel-gazelle-0.15.0.tar.gz",
],
)

load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_repositories")

go_repositories()
bazel_dep(name = "rules_webtesting", version = "0.4.0")
```

## Write your tests
Expand Down Expand Up @@ -235,15 +100,15 @@ In your BUILD files, load the correct language specific build rule and create a
test target using it:

```bzl
load("@io_bazel_rules_webtesting//web:py.bzl", "py_web_test_suite")
load("@rules_webtesting//web:py.bzl", "py_web_test_suite")

py_web_test_suite(
name = "browser_test",
srcs = ["browser_test.py"],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
"@rules_webtesting//browsers:chromium-local",
],
local = True,
deps = ["@io_bazel_rules_webtesting//testing/web"],
deps = ["@rules_webtesting//testing/web"],
)
```
Loading

0 comments on commit 77428ec

Please sign in to comment.