Move linkage monitor check as part of Bazel build (#12980)

Fixes https://github.com/protocolbuffers/protobuf/issues/12912

Moving the Linkage Monitor check to Bazel, so that the result is cached.

Closes #12980

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12980 from suztomo:bazelize_linkage_monitor 51c00949ba
PiperOrigin-RevId: 539681611
pull/13028/head
Tomo Suzuki 2 years ago committed by Copybara-Service
parent aa8fadc5cc
commit 2fd29b0b73
  1. 22
      .github/workflows/test_java.yml
  2. 29
      java/BUILD.bazel
  3. 38
      java/linkage_monitor.sh

@ -57,25 +57,13 @@ jobs:
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ inputs.safe-checkout }}
- name: Build protoc
id: build-protoc
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v1
- name: Run Linkage Monitor test
uses: protocolbuffers/protobuf-ci/bazel-docker@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-6361b3a6e5c97e9951d03a4de28542fc45f1adab
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:8-03a376b5d6ef66f827fc307716e3b841cc26b709
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-x86_64
- name: Move protoc into place and clean up
run: |
mv ${{ steps.build-protoc.outputs.protoc }} protoc
sudo rm -rf _build
- name: Install snapshot version locally
run: |
cd java
mvn -e -B -Dhttps.protocols=TLSv1.2 install -Dmaven.test.skip=true
- name: Download Linkage Monitor
run: curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/linkage-monitor-latest-all-deps.jar"
- name: Fails if there's new linkage errors compared with baseline
run: java -Xmx2048m -jar linkage-monitor-latest-all-deps.jar com.google.cloud:libraries-bom
bazel-cache: java_linux/8
bazel: test --test_output=all //java:linkage_monitor --spawn_strategy=standalone
protobuf-bom:
name: Protobuf Maven BOM

@ -1,5 +1,34 @@
load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
# Run Linkage Monitor
sh_test(
name = "linkage_monitor",
size = "large",
tags = [
# Exclude this target from wildcard expansion (//...) because it may
# take unnecessary time.
"manual",
],
srcs = [
":linkage_monitor.sh",
],
data = [
# Making the Maven modules available in the sandbox
":core",
":kotlin",
":kotlin-lite",
":lite",
":util",
"//:protoc",
# Making this test depends on the code change in core and util
"//java/core:dist_files",
"//java/util",
] + glob([
"pom.xml",
"*/pom.xml",
]),
)
test_suite(
name = "tests",
tests = [

@ -0,0 +1,38 @@
#!/bin/bash
set -e
echo "Running Linkage Monitor check"
echo "Maven command: $(which mvn)"
mvn --version
# This script runs within the Bazel's sandbox directory and uses protoc
# generated within the Bazel project.
protoc_location=$(realpath "${RUNFILES_DIR}/com_google_protobuf/protoc")
if [ ! -x "${protoc_location}" ]; then
echo "${protoc_location} is not found or not executable"
exit 1
fi
cd java
# Linkage Monitor requires the artifacts to be available in local Maven
# repository.
mvn --projects "bom,core,util" -e -B -Dhttps.protocols=TLSv1.2 clean generate-sources install \
-Dmaven.test.skip=true \
-Dprotobuf.basedir="../.." \
-Dprotoc="${protoc_location}"
echo "Installed the artifacts to local Maven repository"
curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/linkage-monitor-latest-all-deps.jar"
echo "Running linkage-monitor-latest-all-deps.jar."
# The generated libraries in google-cloud-shared-dependencies would detect
# incompatible changes via Linkage Monitor
# https://github.com/googleapis/sdk-platform-java/tree/main/java-shared-dependencies
java -Xmx2048m -jar linkage-monitor-latest-all-deps.jar com.google.cloud:google-cloud-shared-dependencies
echo "Finished running Linkage Monitor check"
Loading…
Cancel
Save