Skip to content

Commit

Permalink
fix(ci): use --enable_workspace for bazel-in-bazel tests (#2237)
Browse files Browse the repository at this point in the history
The CI on `main` started failing and is affecting all PRs.

Most likely a fixup to #2184.
  • Loading branch information
aignas authored Sep 20, 2024
1 parent ade0b2b commit 1d7fd51
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.1.0
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ A brief description of the categories of changes:
* (toolchains) {obj}`py_cc_toolchain.libs` and {obj}`PyCcToolchainInfo.libs` is
optional. This is to support situations where only the Python headers are
available.
* (bazel) Minimum bazel 7 version that we test against has been bumped to `7.1`.

### Fixed
* (whl_library): Remove `--no-index` and add `--no-build-isolation` to the
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ bazel_binaries.local(
path = "tests/integration/bazel_from_env",
)
bazel_binaries.download(version = "6.4.0")
bazel_binaries.download(version = "7.3.1")
bazel_binaries.download(version = "rolling")
use_repo(
bazel_binaries,
Expand All @@ -124,6 +125,7 @@ use_repo(
# that should be use_repo()'d, so we add them as requested
"bazel_binaries_bazelisk",
"build_bazel_bazel_6_4_0",
"build_bazel_bazel_7_3_1",
"build_bazel_bazel_rolling",
"build_bazel_bazel_self",
)
Expand Down
24 changes: 23 additions & 1 deletion tests/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ load(":integration_test.bzl", "rules_python_integration_test")

licenses(["notice"])

_WORKSPACE_FLAGS = [
_LEGACY_WORKSPACE_FLAGS = [
"--noenable_bzlmod",
]

_WORKSPACE_FLAGS = _LEGACY_WORKSPACE_FLAGS + [
"--enable_workspace",
]

_WORKSPACE_GAZELLE_PLUGIN_FLAGS = [
"--override_repository=rules_python_gazelle_plugin=../../../rules_python_gazelle_plugin",
]
Expand All @@ -31,6 +35,24 @@ _GAZELLE_PLUGIN_FLAGS = [
"--override_module=rules_python_gazelle_plugin=../../../rules_python_gazelle_plugin",
]

default_test_runner(
name = "bazel_6_4_workspace_test_runner",
bazel_cmds = [
"info {}".format(" ".join(_LEGACY_WORKSPACE_FLAGS)),
"test {} //...".format(" ".join(_LEGACY_WORKSPACE_FLAGS)),
],
visibility = ["//visibility:public"],
)

default_test_runner(
name = "bazel_6_4_workspace_test_runner_gazelle_plugin",
bazel_cmds = [
"info {}".format(" ".join(_LEGACY_WORKSPACE_FLAGS + _WORKSPACE_GAZELLE_PLUGIN_FLAGS)),
"test {} //...".format(" ".join(_LEGACY_WORKSPACE_FLAGS + _WORKSPACE_GAZELLE_PLUGIN_FLAGS)),
],
visibility = ["//visibility:public"],
)

default_test_runner(
name = "workspace_test_runner",
bazel_cmds = [
Expand Down
107 changes: 62 additions & 45 deletions tests/integration/integration_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,40 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_tests",
"bazel_integration_test",
"integration_test_utils",
)
load("//python:py_test.bzl", "py_test")

def _test_runner(*, name, bazel_version, py_main, bzlmod, gazelle_plugin):
if py_main:
test_runner = "{}_bazel_{}_py_runner".format(name, bazel_version)
py_test(
name = test_runner,
srcs = [py_main],
main = py_main,
deps = [":runner_lib"],
# Hide from ... patterns; should only be run as part
# of the bazel integration test
tags = ["manual"],
)
return test_runner

if bazel_version.startswith("6") and not bzlmod:
if gazelle_plugin:
return "//tests/integration:bazel_6_4_workspace_test_runner_gazelle_plugin"
else:
return "//tests/integration:bazel_6_4_workspace_test_runner"

if bzlmod and gazelle_plugin:
return "//tests/integration:test_runner_gazelle_plugin"
elif bzlmod:
return "//tests/integration:test_runner"
elif gazelle_plugin:
return "//tests/integration:workspace_test_runner_gazelle_plugin"
else:
return "//tests/integration:workspace_test_runner"

def rules_python_integration_test(
name,
workspace_path = None,
Expand Down Expand Up @@ -48,26 +77,6 @@ def rules_python_integration_test(
**kwargs: Passed to the upstream `bazel_integration_tests` rule.
"""
workspace_path = workspace_path or name.removesuffix("_test")
if py_main:
test_runner = name + "_py_runner"
py_test(
name = test_runner,
srcs = [py_main],
main = py_main,
deps = [":runner_lib"],
# Hide from ... patterns; should only be run as part
# of the bazel integration test
tags = ["manual"],
)
elif bzlmod:
if gazelle_plugin:
test_runner = "//tests/integration:test_runner_gazelle_plugin"
else:
test_runner = "//tests/integration:test_runner"
elif gazelle_plugin:
test_runner = "//tests/integration:workspace_test_runner_gazelle_plugin"
else:
test_runner = "//tests/integration:workspace_test_runner"

# Because glob expansion happens at loading time, the bazel-* symlinks
# in the workspaces can recursively expand to tens-of-thousands of entries,
Expand All @@ -89,27 +98,35 @@ def rules_python_integration_test(
],
)
kwargs.setdefault("size", "enormous")
bazel_integration_tests(
name = name,
workspace_path = workspace_path,
test_runner = test_runner,
bazel_versions = bazel_versions or bazel_binaries.versions.all,
workspace_files = [name + "_workspace_files"],
# Override the tags so that the `manual` tag isn't applied.
tags = (tags or []) + [
# These tests are very heavy weight, so much so that only a couple
# can be run in parallel without harming their reliability,
# overall runtime, and the system's stability. Unfortunately,
# there doesn't appear to be a way to tell Bazel to limit their
# concurrency, only disable it entirely with exclusive.
"exclusive",
# The default_test_runner() assumes it can write to the user's home
# directory for caching purposes. Give it access.
"no-sandbox",
# The CI RBE setup can't successfully run these tests remotely.
"no-remote-exec",
# A special tag is used so CI can run them as a separate job.
"integration-test",
],
**kwargs
)
for bazel_version in bazel_versions or bazel_binaries.versions.all:
test_runner = _test_runner(
name = name,
bazel_version = bazel_version,
py_main = py_main,
bzlmod = bzlmod,
gazelle_plugin = gazelle_plugin,
)
bazel_integration_test(
name = "{}_bazel_{}".format(name, bazel_version),
workspace_path = workspace_path,
test_runner = test_runner,
bazel_version = bazel_version,
workspace_files = [name + "_workspace_files"],
# Override the tags so that the `manual` tag isn't applied.
tags = (tags or []) + [
# These tests are very heavy weight, so much so that only a couple
# can be run in parallel without harming their reliability,
# overall runtime, and the system's stability. Unfortunately,
# there doesn't appear to be a way to tell Bazel to limit their
# concurrency, only disable it entirely with exclusive.
"exclusive",
# The default_test_runner() assumes it can write to the user's home
# directory for caching purposes. Give it access.
"no-sandbox",
# The CI RBE setup can't successfully run these tests remotely.
"no-remote-exec",
# A special tag is used so CI can run them as a separate job.
"integration-test",
],
**kwargs
)
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# against.
# This version should be updated together with the version of Bazel
# in .bazelversion.
BAZEL_VERSION = "7.0.0"
BAZEL_VERSION = "7.1.0"

# NOTE: Keep in sync with .bazelci/presubmit.yml
# This is the minimum supported bazel version, that we have some tests for.
Expand Down

0 comments on commit 1d7fd51

Please sign in to comment.