Skip to content

Commit 50ce2bd

Browse files
authored
Add bzlmod tests (#231)
1 parent c1a9911 commit 50ce2bd

File tree

18 files changed

+1442
-6
lines changed

18 files changed

+1442
-6
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples

.bcr/presubmit.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
# We should probably create a standalone test module, but for now we'll just run our in-repo tests.
21
bcr_test_module:
32
matrix:
43
platform: ["debian10", "macos", "ubuntu2004", "windows"]
54
tasks:
6-
run_tests:
7-
name: "Run tests"
5+
gazelle:
6+
working_directory: "examples/gazelle"
7+
name: "Gazelle"
8+
platform: ${{ platform }}
9+
run_targets:
10+
- "//:gazelle"
11+
test_targets:
12+
- "//..."
13+
tests_and_lints:
14+
working_directory: "examples/tests_and_lints"
15+
name: "Tests and lints"
816
platform: ${{ platform }}
917
test_targets:
1018
- "//..."

.github/workflows/ci.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,29 @@ jobs:
3838
env:
3939
# Bazelisk will download bazel to here, ensure it is cached between runs.
4040
XDG_CACHE_HOME: ~/.cache/bazel-repo
41-
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --config=jdk11 //...
41+
run: bazel --bazelrc=.github/workflows/ci.bazelrc test --config=jdk11 //...
4242

4343
- name: bazel test //... (Java 17)
4444
env:
4545
# Bazelisk will download bazel to here, ensure it is cached between runs.
4646
XDG_CACHE_HOME: ~/.cache/bazel-repo
47-
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
47+
run: bazel --bazelrc=.github/workflows/ci.bazelrc test //...
4848

4949
- name: bazel test //... (no bzlmod)
5050
env:
5151
# Bazelisk will download bazel to here, ensure it is cached between runs.
5252
XDG_CACHE_HOME: ~/.cache/bazel-repo
5353
# The docs targets are tagged as `manual` to prevent stardoc from running with bzlmod
54-
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --noenable_bzlmod //... //docs:all
54+
run: bazel --bazelrc=.github/workflows/ci.bazelrc test --noenable_bzlmod //... //docs:all
55+
56+
- name: bzlmod tests_and_lints
57+
env:
58+
# Bazelisk will download bazel to here, ensure it is cached between runs.
59+
XDG_CACHE_HOME: ~/.cache/bazel-repo
60+
run: (cd examples/tests_and_lints && bazel --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)
61+
62+
- name: bzlmod gazelle
63+
env:
64+
# Bazelisk will download bazel to here, ensure it is cached between runs.
65+
XDG_CACHE_HOME: ~/.cache/bazel-repo
66+
run: (cd examples/gazelle && bazel --bazelrc=../../.github/workflows/ci.bazelrc run --enable_bzlmod //:gazelle && bazel --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)

examples/gazelle/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bazel-*
2+
/MODULE.bazel.lock

examples/gazelle/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")
2+
3+
gazelle_binary(
4+
name = "gazelle_binary",
5+
languages = [
6+
"@gazelle//language/proto:go_default_library",
7+
"@contrib_rules_jvm//java/gazelle",
8+
],
9+
visibility = ["//visibility:private"],
10+
)
11+
12+
gazelle(
13+
name = "gazelle",
14+
gazelle = ":gazelle_binary",
15+
)

examples/gazelle/MODULE.bazel

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module(
2+
name = "gazelle_example",
3+
version = "0.0.0",
4+
)
5+
6+
bazel_dep(
7+
name = "contrib_rules_jvm",
8+
version = "0.0.0",
9+
)
10+
local_path_override(
11+
module_name = "contrib_rules_jvm",
12+
path = "../..",
13+
)
14+
15+
bazel_dep(
16+
name = "bazel_skylib",
17+
version = "1.5.0",
18+
)
19+
bazel_dep(
20+
name = "rules_jvm_external",
21+
version = "5.3",
22+
)
23+
24+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
25+
maven.install(
26+
name = "maven",
27+
artifacts = [
28+
"org.junit.jupiter:junit-jupiter-api:5.8.2",
29+
"org.junit.jupiter:junit-jupiter-engine:5.8.2",
30+
"org.junit.platform:junit-platform-launcher:1.8.2",
31+
"org.junit.platform:junit-platform-reporting:1.8.2",
32+
],
33+
lock_file = "//:maven_install.json",
34+
)
35+
use_repo(
36+
maven,
37+
"maven",
38+
"unpinned_maven",
39+
)
40+
41+
bazel_dep(
42+
name = "gazelle",
43+
version = "0.34.0",
44+
)

examples/gazelle/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example contains java files which don't have BUILD targets for them.
2+
3+
It requires running `bazel run :gazelle` to generate targets which can be built.
4+
5+
There is a test using `genquery` which asserts that the right targets are generated.

0 commit comments

Comments
 (0)