diff --git a/.github/workflows/test_java.yml b/.github/workflows/test_java.yml index d713d1c3a9..89c487fe97 100644 --- a/.github/workflows/test_java.yml +++ b/.github/workflows/test_java.yml @@ -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 diff --git a/java/BUILD.bazel b/java/BUILD.bazel index 2c6582ce95..fa6d8ba74f 100644 --- a/java/BUILD.bazel +++ b/java/BUILD.bazel @@ -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 = [ diff --git a/java/linkage_monitor.sh b/java/linkage_monitor.sh new file mode 100755 index 0000000000..3adae2b58d --- /dev/null +++ b/java/linkage_monitor.sh @@ -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"