ci: add verify-cache-overwrite job in ci.yaml #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| name: test-cache-overwrite | ||
| on: | ||
| push: | ||
| branches: | ||
| - '**' | ||
| pull_request: | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| verify-cache-overwrite: | ||
| name: Verify Maven Cache & Local .m2 Overwrite | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up Java 17 with Maven Cache | ||
| uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0 | ||
| with: | ||
| distribution: temurin | ||
| java-version: 17 | ||
| cache: maven | ||
| - name: Inspect Initial Restored .m2 Cache | ||
| run: | | ||
| echo "============================================================" | ||
| echo "1. Checking initial state of ~/.m2/repository from cache..." | ||
| echo "============================================================" | ||
| if [ -d "$HOME/.m2/repository" ]; then | ||
| echo "Cache Restored! ~/.m2/repository directory size:" | ||
| du -sh "$HOME/.m2/repository" || true | ||
| echo "Sample existing dependencies in ~/.m2/repository:" | ||
| find "$HOME/.m2/repository" -maxdepth 3 -type d | head -n 20 || true | ||
| else | ||
| echo "No existing ~/.m2/repository found (first cold run for this cache key)." | ||
| fi | ||
| - name: Build and Install Module to .m2 (Baseline) | ||
| run: | | ||
| echo "============================================================" | ||
| echo "2. Building and installing java-common-protos to ~/.m2..." | ||
| echo "============================================================" | ||
| mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -am -B -ntp -T 1C | ||
| echo "Inspecting baseline installed artifact in ~/.m2/repository:" | ||
| ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" | ||
| find "$ARTIFACT_DIR" -type f -exec ls -la {} + | ||
| - name: Simulate Code Change in Module & Re-install to .m2 | ||
| run: | | ||
| echo "============================================================" | ||
| echo "3. Modifying source file in java-common-protos to create a new version..." | ||
| echo "============================================================" | ||
| MARKER_FILE="java-common-protos/proto-google-common-protos/src/main/java/com/google/type/CacheTestMarker.java" | ||
| mkdir -p "$(dirname "$MARKER_FILE")" | ||
| TIMESTAMP=$(date +%s) | ||
| cat <<MARKER > "$MARKER_FILE" | ||
| package com.google.type; | ||
| public class CacheTestMarker { | ||
| public static final String TIMESTAMP = "$TIMESTAMP"; | ||
| public static final String VERSION_MARKER = "TEST_CACHE_OVERWRITE_VERIFIED_$TIMESTAMP"; | ||
| } | ||
| MARKER | ||
| echo "Created source marker: $MARKER_FILE" | ||
| cat "$MARKER_FILE" | ||
| echo "Recording pre-install artifact timestamps and checksums in ~/.m2..." | ||
| PRE_SHA=$(find "$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" -name "*.jar" -exec sha256sum {} + || true) | ||
| echo "Pre-build JAR SHA256 in ~/.m2:" | ||
| echo "$PRE_SHA" | ||
| echo "Re-installing modified module..." | ||
| mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -B -ntp -T 1C | ||
| - name: Verify Overwrite in Runner .m2 | ||
| run: | | ||
| echo "============================================================" | ||
| echo "4. Verifying newly built version physically overwrote ~/.m2..." | ||
| echo "============================================================" | ||
| ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" | ||
| echo "Files in $ARTIFACT_DIR:" | ||
| find "$ARTIFACT_DIR" -type f -exec ls -la {} + | ||
| echo "Checking new JAR SHA256 checksums in ~/.m2:" | ||
| find "$ARTIFACT_DIR" -name "*.jar" -exec sha256sum {} + | ||
| echo "Extracting and verifying CacheTestMarker class inside ~/.m2 jar:" | ||
| JAR_FILE=$(find "$ARTIFACT_DIR" -name "proto-google-common-protos-*.jar" ! -name "*-sources.jar" ! -name "*-tests.jar" | head -n 1) | ||
| echo "Checking JAR: $JAR_FILE" | ||
| jar tf "$JAR_FILE" | grep "CacheTestMarker" || { echo "ERROR: Marker class not found in installed JAR!"; exit 1; } | ||
| echo "SUCCESS: The local module was freshly compiled and overwritten in ~/.m2/repository!" | ||