Skip to content

Commit 6cac827

Browse files
l46kokcopybara-github
authored andcommitted
Properly establish cross dependenies across maven artifacts
Fixes: #566 See also grpc/grpc-java#12640 PiperOrigin-RevId: 871541021
1 parent 8e5040d commit 6cac827

File tree

8 files changed

+256
-44
lines changed

8 files changed

+256
-44
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
# Copyright 2026 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o pipefail
17+
18+
TARGETS=(
19+
"//publish:cel"
20+
"//publish:cel_common"
21+
"//publish:cel_compiler"
22+
"//publish:cel_runtime"
23+
"//publish:cel_protobuf"
24+
"//publish:cel_v1alpha1"
25+
)
26+
27+
echo "------------------------------------------------"
28+
echo "Checking for duplicates..."
29+
echo "------------------------------------------------"
30+
31+
bazel build "${TARGETS[@]}" || { echo "Bazel build failed"; exit 1; }
32+
33+
34+
(
35+
for target in "${TARGETS[@]}"; do
36+
# Locate the jar
37+
jar_path=$(bazel cquery "$target" --output=files 2>/dev/null | grep '\-project.jar$')
38+
39+
if [[ -z "$jar_path" ]]; then
40+
echo "Error: Could not find -project.jar for target $target" >&2
41+
exit 1
42+
fi
43+
44+
# Fix relative paths if running from a subdir.
45+
if [[ ! -f "$jar_path" ]]; then
46+
if [[ -f "../../$jar_path" ]]; then
47+
jar_path="../../$jar_path"
48+
else
49+
echo "Error: File not found at $jar_path" >&2
50+
exit 1
51+
fi
52+
fi
53+
54+
echo "Inspecting: $target" >&2
55+
56+
# Extract classes and append the target name to the end of the line
57+
# Format: dev/cel/expr/Expr.class //publish:cel_compiler
58+
jar tf "$jar_path" | grep "\.class$" | awk -v tgt="$target" '{print $0, tgt}'
59+
done
60+
) | awk '
61+
# $1 is the Class Name, $2 is the Target Name
62+
seen[$1] {
63+
print "❌ DUPLICATE FOUND: " $1
64+
print " Present in: " seen[$1]
65+
print " And in: " $2
66+
dupe=1
67+
next
68+
}
69+
{ seen[$1] = $2 }
70+
71+
END { if (dupe) exit 1 }
72+
'
73+
74+
EXIT_CODE=$?
75+
76+
if [ $EXIT_CODE -eq 0 ]; then
77+
echo "✅ Success: No duplicate classes found."
78+
else
79+
echo "⛔ Failure: Duplicate classes (or missing jars) detected."
80+
fi
81+
82+
exit $EXIT_CODE
83+

.github/workflows/workflow.yml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18+
Static-Checks:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 30
21+
steps:
22+
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
23+
- run: echo "🐧 Job is running on a ${{ runner.os }} server!"
24+
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
25+
- name: Check out repository code
26+
uses: actions/checkout@v6
27+
- name: Setup Bazel
28+
uses: bazel-contrib/setup-bazel@0.18.0
29+
with:
30+
# Avoid downloading Bazel every time.
31+
bazelisk-cache: true
32+
# Store build cache per workflow.
33+
disk-cache: ${{ github.workflow }}
34+
# Share repository cache between workflows.
35+
repository-cache: true
36+
- name: Unwanted Dependencies
37+
run: .github/workflows/unwanted_deps.sh
38+
- name: Cross Artifact Duplicate Classes Check
39+
run: .github/workflows/cross_artifact_dependencies_check.sh
40+
- run: echo "🍏 This job's status is ${{ job.status }}."
1841
Bazel-Tests:
1942
runs-on: ubuntu-latest
2043
timeout-minutes: 30
@@ -25,7 +48,7 @@ jobs:
2548
- name: Check out repository code
2649
uses: actions/checkout@v6
2750
- name: Setup Bazel
28-
uses: bazel-contrib/setup-bazel@0.14.0
51+
uses: bazel-contrib/setup-bazel@0.18.0
2952
with:
3053
# Avoid downloading Bazel every time.
3154
bazelisk-cache: true
@@ -41,13 +64,33 @@ jobs:
4164
# Exclude codelab exercises as they are intentionally made to fail
4265
# Exclude maven conformance tests. They are only executed when there's version change.
4366
run: bazelisk test ... --deleted_packages=//codelab/src/test/codelab --test_output=errors --test_tag_filters=-conformance_maven --build_tag_filters=-conformance_maven
67+
- run: echo "🍏 This job's status is ${{ job.status }}."
4468

45-
# -- Start of Maven Conformance Tests (Ran only when there's version changes) --
46-
- name: Get changed file
69+
# -- Start of Maven Conformance Tests (Ran only when there's version changes) --
70+
Maven-Conformance:
71+
runs-on: ubuntu-latest
72+
timeout-minutes: 30
73+
steps:
74+
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
75+
- run: echo "🐧 Job is running on a ${{ runner.os }} server!"
76+
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
77+
- name: Check out repository code
78+
uses: actions/checkout@v6
79+
- name: Get changed files
4780
id: changed_file
4881
uses: tj-actions/changed-files@v46
4982
with:
5083
files: publish/cel_version.bzl
84+
- name: Setup Bazel
85+
if: steps.changed_file.outputs.any_changed == 'true'
86+
uses: bazel-contrib/setup-bazel@0.18.0
87+
with:
88+
# Avoid downloading Bazel every time.
89+
bazelisk-cache: true
90+
# Store build cache per workflow.
91+
disk-cache: ${{ github.workflow }}
92+
# Share repository cache between workflows.
93+
repository-cache: true
5194
- name: Verify Version Consistency
5295
if: steps.changed_file.outputs.any_changed == 'true'
5396
run: |
@@ -72,8 +115,4 @@ jobs:
72115
- name: Run Conformance Maven Test on Version Change
73116
if: steps.changed_file.outputs.any_changed == 'true'
74117
run: bazelisk test //conformance/src/test/java/dev/cel/conformance:conformance_maven --test_output=errors
75-
# -- End of Maven Conformance Tests --
76-
77-
- name: Unwanted Dependencies
78-
run: .github/workflows/unwanted_deps.sh
79118
- run: echo "🍏 This job's status is ${{ job.status }}."

common/src/main/java/dev/cel/common/internal/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package(
77
],
88
default_visibility = [
99
"//common/internal:__pkg__",
10+
"//publish:__pkg__",
1011
],
1112
)
1213

common/src/main/java/dev/cel/common/types/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package(
77
],
88
default_visibility = [
99
"//common/types:__pkg__",
10+
"//publish:__pkg__",
1011
],
1112
)
1213

common/src/main/java/dev/cel/common/values/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package(
77
],
88
default_visibility = [
99
"//common/values:__pkg__",
10+
"//publish:__pkg__",
1011
],
1112
)
1213

0 commit comments

Comments
 (0)