Skip to content

Commit

Permalink
Add bzlmod tests (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Jan 8, 2024
1 parent c1a9911 commit 50ce2bd
Show file tree
Hide file tree
Showing 18 changed files with 1,442 additions and 6 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
14 changes: 11 additions & 3 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# We should probably create a standalone test module, but for now we'll just run our in-repo tests.
bcr_test_module:
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
tasks:
run_tests:
name: "Run tests"
gazelle:
working_directory: "examples/gazelle"
name: "Gazelle"
platform: ${{ platform }}
run_targets:
- "//:gazelle"
test_targets:
- "//..."
tests_and_lints:
working_directory: "examples/tests_and_lints"
name: "Tests and lints"
platform: ${{ platform }}
test_targets:
- "//..."
18 changes: 15 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,29 @@ jobs:
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --config=jdk11 //...
run: bazel --bazelrc=.github/workflows/ci.bazelrc test --config=jdk11 //...

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

- name: bazel test //... (no bzlmod)
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
# The docs targets are tagged as `manual` to prevent stardoc from running with bzlmod
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --noenable_bzlmod //... //docs:all
run: bazel --bazelrc=.github/workflows/ci.bazelrc test --noenable_bzlmod //... //docs:all

- name: bzlmod tests_and_lints
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: (cd examples/tests_and_lints && bazel --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)

- name: bzlmod gazelle
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: (cd examples/gazelle && bazel --bazelrc=../../.github/workflows/ci.bazelrc run --enable_bzlmod //:gazelle && bazel --bazelrc=../../.github/workflows/ci.bazelrc test --enable_bzlmod //...)
2 changes: 2 additions & 0 deletions examples/gazelle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bazel-*
/MODULE.bazel.lock
15 changes: 15 additions & 0 deletions examples/gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")

gazelle_binary(
name = "gazelle_binary",
languages = [
"@gazelle//language/proto:go_default_library",
"@contrib_rules_jvm//java/gazelle",
],
visibility = ["//visibility:private"],
)

gazelle(
name = "gazelle",
gazelle = ":gazelle_binary",
)
44 changes: 44 additions & 0 deletions examples/gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module(
name = "gazelle_example",
version = "0.0.0",
)

bazel_dep(
name = "contrib_rules_jvm",
version = "0.0.0",
)
local_path_override(
module_name = "contrib_rules_jvm",
path = "../..",
)

bazel_dep(
name = "bazel_skylib",
version = "1.5.0",
)
bazel_dep(
name = "rules_jvm_external",
version = "5.3",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "maven",
artifacts = [
"org.junit.jupiter:junit-jupiter-api:5.8.2",
"org.junit.jupiter:junit-jupiter-engine:5.8.2",
"org.junit.platform:junit-platform-launcher:1.8.2",
"org.junit.platform:junit-platform-reporting:1.8.2",
],
lock_file = "//:maven_install.json",
)
use_repo(
maven,
"maven",
"unpinned_maven",
)

bazel_dep(
name = "gazelle",
version = "0.34.0",
)
5 changes: 5 additions & 0 deletions examples/gazelle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This example contains java files which don't have BUILD targets for them.

It requires running `bazel run :gazelle` to generate targets which can be built.

There is a test using `genquery` which asserts that the right targets are generated.
Loading

0 comments on commit 50ce2bd

Please sign in to comment.