Skip to content

Commit 5b06cc0

Browse files
l46kokcopybara-github
authored andcommitted
Run conformance tests against published maven JARs
PiperOrigin-RevId: 793822235
1 parent 4f62dee commit 5b06cc0

File tree

6 files changed

+126
-31
lines changed

6 files changed

+126
-31
lines changed

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
common --enable_bzlmod
2-
common --enable_workspace
32
build --java_runtime_version=remotejdk_11
43
build --java_language_version=11
54

.github/workflows/workflow.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,44 @@ jobs:
3636
- name: Bazel Output Version
3737
run: bazelisk --version
3838
- name: Java 8 Build
39-
run: bazel build ... --java_language_version=8 --java_runtime_version=8
39+
run: bazel build ... --java_language_version=8 --java_runtime_version=8 --build_tag_filters=-conformance_maven
4040
- name: Bazel Test
4141
# Exclude codelab exercises as they are intentionally made to fail
42-
run: bazelisk test ... --deleted_packages=//codelab/src/test/codelab --test_output=errors
42+
# Exclude maven conformance tests. They are only executed when there's version change.
43+
run: bazelisk test ... --deleted_packages=//codelab/src/test/codelab --test_output=errors --test_tag_filters=-conformance_maven --build_tag_filters=-conformance_maven
44+
45+
# -- Start of Maven Conformance Tests (Ran only when there's version changes) --
46+
- name: Get changed file
47+
id: changed_file
48+
uses: tj-actions/changed-files@v44
49+
with:
50+
files: publish/cel_version.bzl
51+
- name: Verify Version Consistency
52+
if: steps.changed_file.outputs.any_changed == 'true'
53+
run: |
54+
CEL_VERSION=$(grep 'CEL_VERSION =' publish/cel_version.bzl | cut -d '"' -f 2)
55+
56+
MODULE_VERSION=$(grep 'dev.cel:cel' MODULE.bazel | cut -d '"' -f 2 | cut -d ':' -f 3)
57+
58+
if [ -z "$CEL_VERSION" ] || [ -z "$MODULE_VERSION" ]; then
59+
echo "❌ Error: Could not extract one or both version strings."
60+
exit 1
61+
fi
62+
63+
echo "Version in publish/cel_version.bzl: ${CEL_VERSION}"
64+
echo "Version in MODULE.bazel: ${MODULE_VERSION}"
65+
66+
if [ "$CEL_VERSION" != "$MODULE_VERSION" ]; then
67+
echo "❌ Error: Version mismatch between files!"
68+
exit 1
69+
fi
70+
71+
echo "✅ Versions match."
72+
- name: Run Conformance Maven Test on Version Change
73+
if: steps.changed_file.outputs.any_changed == 'true'
74+
run: bazelisk test //conformance/src/test/java/dev/cel/conformance:conformance_maven --test_output=errors
75+
# -- End of Maven Conformance Tests --
76+
4377
- name: Unwanted Dependencies
4478
run: .github/workflows/unwanted_deps.sh
4579
- run: echo "🍏 This job's status is ${{ job.status }}."

MODULE.bazel

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ module(
1818

1919
bazel_dep(name = "bazel_skylib", version = "1.7.1")
2020
bazel_dep(name = "rules_jvm_external", version = "6.7")
21-
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
21+
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
2222
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
2323
bazel_dep(name = "rules_pkg", version = "1.0.1")
2424
bazel_dep(name = "rules_license", version = "1.0.0")
2525
bazel_dep(name = "rules_proto", version = "7.1.0")
2626
bazel_dep(name = "rules_java", version = "8.12.0")
2727
bazel_dep(name = "rules_android", version = "0.6.4")
28+
bazel_dep(name = "rules_shell", version = "0.5.1")
2829
bazel_dep(name = "googleapis-java", version = "1.0.0")
29-
bazel_dep(name = "cel-spec", repo_name = "cel_spec", version = "0.24.0")
30+
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
3031

3132
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
3233
switched_rules.use_languages(java = True)
@@ -35,14 +36,15 @@ use_repo(switched_rules, "com_google_googleapis_imports")
3536
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
3637

3738
GUAVA_VERSION = "33.4.8"
39+
3840
TRUTH_VERSION = "1.4.4"
3941

4042
# Compile only artifacts
4143
[
4244
maven.artifact(
43-
neverlink = True,
4445
artifact = artifact,
4546
group = group,
47+
neverlink = True,
4648
version = version,
4749
)
4850
for group, artifact, version in [coord.split(":") for coord in [
@@ -68,7 +70,6 @@ TRUTH_VERSION = "1.4.4"
6870
"com.google.truth.extensions:truth-proto-extension:" + TRUTH_VERSION,
6971
"com.google.truth.extensions:truth-liteproto-extension:" + TRUTH_VERSION,
7072
"com.google.truth:truth:" + TRUTH_VERSION,
71-
7273
]]
7374
]
7475

@@ -94,7 +95,6 @@ maven.install(
9495
"https://repo1.maven.org/maven2",
9596
],
9697
)
97-
9898
maven.install(
9999
name = "maven_android",
100100
# keep sorted
@@ -108,7 +108,18 @@ maven.install(
108108
],
109109
)
110110

111-
use_repo(maven, "maven", "maven_android")
111+
# Conformance test only
112+
113+
maven.install(
114+
name = "maven_conformance",
115+
artifacts = ["dev.cel:cel:0.11.0-SNAPSHOT"],
116+
repositories = [
117+
"https://maven.google.com",
118+
"https://repo1.maven.org/maven2",
119+
"https://central.sonatype.com/repository/maven-snapshots/",
120+
],
121+
)
122+
use_repo(maven, "maven", "maven_android", "maven_conformance")
112123

113124
non_module_dependencies = use_extension("//:repositories.bzl", "non_module_dependencies")
114125
use_repo(non_module_dependencies, "antlr4_jar")

conformance/src/test/java/dev/cel/conformance/BUILD.bazel

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@rules_java//java:defs.bzl", "java_library")
2-
load("//conformance/src/test/java/dev/cel/conformance:conformance_test.bzl", "conformance_test")
2+
load("//conformance/src/test/java/dev/cel/conformance:conformance_test.bzl", "MODE", "conformance_test")
33

44
package(default_applicable_licenses = [
55
"//:license",
@@ -40,6 +40,27 @@ java_library(
4040
],
4141
)
4242

43+
MAVEN_JAR_DEPS = ["@maven_conformance//:dev_cel_cel"]
44+
45+
java_library(
46+
name = "run_maven_jar",
47+
testonly = True,
48+
srcs = glob(["*.java"]),
49+
tags = ["conformance_maven"],
50+
deps = MAVEN_JAR_DEPS + [
51+
"//:java_truth",
52+
"//testing:expr_value_utils",
53+
"@cel_spec//proto/cel/expr:expr_java_proto",
54+
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
55+
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
56+
"@cel_spec//proto/cel/expr/conformance/test:simple_java_proto",
57+
"@maven//:com_google_guava_guava",
58+
"@maven//:com_google_protobuf_protobuf_java",
59+
"@maven//:com_google_truth_extensions_truth_proto_extension",
60+
"@maven//:junit_junit",
61+
],
62+
)
63+
4364
_ALL_TESTS = [
4465
"@cel_spec//tests/simple:testdata/basic.textproto",
4566
"@cel_spec//tests/simple:testdata/bindings_ext.textproto",
@@ -131,13 +152,19 @@ _TESTS_TO_SKIP = [
131152

132153
conformance_test(
133154
name = "conformance",
134-
dashboard = False,
135155
data = _ALL_TESTS,
136156
skip_tests = _TESTS_TO_SKIP,
137157
)
138158

159+
conformance_test(
160+
name = "conformance_maven",
161+
data = _ALL_TESTS,
162+
mode = MODE.MAVEN_TEST,
163+
skip_tests = _TESTS_TO_SKIP,
164+
)
165+
139166
conformance_test(
140167
name = "conformance_dashboard",
141-
dashboard = True,
142168
data = _ALL_TESTS,
169+
mode = MODE.DASHBOARD,
143170
)

conformance/src/test/java/dev/cel/conformance/ConformanceTest.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,6 @@ public final class ConformanceTest extends Statement {
6161
.enableQuotedIdentifierSyntax(true)
6262
.build();
6363

64-
private static final CelParser PARSER_WITH_MACROS =
65-
CelParserFactory.standardCelParserBuilder()
66-
.setOptions(OPTIONS)
67-
.addLibraries(
68-
CelExtensions.bindings(),
69-
CelExtensions.encoders(),
70-
CelExtensions.math(OPTIONS),
71-
CelExtensions.protos(),
72-
CelExtensions.sets(OPTIONS),
73-
CelExtensions.strings(),
74-
CelOptionalLibrary.INSTANCE)
75-
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
76-
.build();
77-
7864
private static final CelParser PARSER_WITHOUT_MACROS =
7965
CelParserFactory.standardCelParserBuilder()
8066
.setOptions(OPTIONS)
@@ -86,11 +72,15 @@ public final class ConformanceTest extends Statement {
8672
CelExtensions.sets(OPTIONS),
8773
CelExtensions.strings(),
8874
CelOptionalLibrary.INSTANCE)
89-
.setStandardMacros()
9075
.build();
9176

9277
private static CelParser getParser(SimpleTest test) {
93-
return test.getDisableMacros() ? PARSER_WITHOUT_MACROS : PARSER_WITH_MACROS;
78+
return test.getDisableMacros()
79+
? PARSER_WITHOUT_MACROS
80+
: PARSER_WITHOUT_MACROS
81+
.toParserBuilder()
82+
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
83+
.build();
9484
}
9585

9686
private static CelChecker getChecker(SimpleTest test) throws Exception {

conformance/src/test/java/dev/cel/conformance/conformance_test.bzl

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,29 @@ def _conformance_test_args(data, skip_tests):
4343
args.append("-Ddev.cel.conformance.ConformanceTests.tests={}".format(",".join(["$(location " + test + ")" for test in data])))
4444
return args
4545

46-
def conformance_test(name, data, dashboard, skip_tests = []):
47-
if dashboard:
46+
MODE = struct(
47+
# Standard test execution against HEAD
48+
TEST = "test",
49+
# Executes conformance test against published jar in maven central
50+
MAVEN_TEST = "maven_test",
51+
# Dashboard mode
52+
DASHBOARD = "dashboard",
53+
)
54+
55+
def conformance_test(name, data, mode = MODE.TEST, skip_tests = []):
56+
"""Executes conformance tests
57+
58+
Args:
59+
name: unique label for the java_test
60+
data: A list of test data files
61+
mode: An enum that determines the test configuration.
62+
- `MODE.TEST` (default): Runs the conformance tests
63+
- `MODE.DASHBOARD`: Runs the conformance tests for displaying on dashboard.
64+
- `MODE.MAVEN_TEST`: Runs the conformance tests against published JAR in maven central.
65+
skip_tests: A list of strings, where each string is the name of a test file to
66+
exclude from the run.
67+
"""
68+
if mode == MODE.DASHBOARD:
4869
java_test(
4970
name = "_" + name,
5071
jvm_flags = _conformance_test_args(data, skip_tests),
@@ -57,6 +78,7 @@ def conformance_test(name, data, dashboard, skip_tests = []):
5778
"notap",
5879
],
5980
)
81+
6082
native.sh_test(
6183
name = name,
6284
size = "small",
@@ -69,7 +91,7 @@ def conformance_test(name, data, dashboard, skip_tests = []):
6991
"notap",
7092
],
7193
)
72-
else:
94+
elif mode == MODE.TEST:
7395
java_test(
7496
name = name,
7597
jvm_flags = _conformance_test_args(data, skip_tests),
@@ -78,3 +100,15 @@ def conformance_test(name, data, dashboard, skip_tests = []):
78100
test_class = "dev.cel.conformance.ConformanceTests",
79101
runtime_deps = ["//conformance/src/test/java/dev/cel/conformance:run"],
80102
)
103+
elif mode == MODE.MAVEN_TEST:
104+
java_test(
105+
name = name,
106+
jvm_flags = _conformance_test_args(data, skip_tests),
107+
data = data,
108+
size = "small",
109+
test_class = "dev.cel.conformance.ConformanceTests",
110+
tags = ["conformance_maven"],
111+
runtime_deps = ["//conformance/src/test/java/dev/cel/conformance:run_maven_jar"],
112+
)
113+
else:
114+
fail("Unknown mode specified: %s." % mode)

0 commit comments

Comments
 (0)