Skip to content
Closed
101 changes: 101 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:
push:
branches:
- main
- test-ci-cache-overwrite
pull_request:
name: ci
jobs:
Expand Down Expand Up @@ -440,4 +441,104 @@ jobs:
uses: googleapis/java-cloud-bom/tests/validate-bom@377c8d1fac6b1521dc52a10f4d02e5d371a0de67 # v26.79.0
with:
bom-path: gapic-libraries-bom/pom.xml
test-cache-overwrite:
name: verify-cache-overwrite
needs: bulk-filter
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0
with:
distribution: temurin
java-version: 17
cache: maven
- name: 1. Inspect Initial Restored .m2 Cache State
run: |
echo "============================================================"
echo "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 ""
echo "Total number of files in restored cache:"
find "$HOME/.m2/repository" -type f | wc -l
echo ""
echo "All cached JAR and POM artifacts in ~/.m2/repository:"
find "$HOME/.m2/repository" \( -name "*.jar" -o -name "*.pom" \) | sed "s|$HOME/.m2/repository/||" | sort
else
echo "No existing ~/.m2/repository found (first cold run for this cache key)."
fi
- name: 2. Build and Install Baseline Module to ~/.m2 & Assert File Absence
run: |
echo "============================================================"
echo "Building and installing baseline 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
ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos"
BASELINE_JAR=$(find "$ARTIFACT_DIR" -name "proto-google-common-protos-*.jar" ! -name "*-sources.jar" ! -name "*-tests.jar" | head -n 1)
echo "Baseline JAR Path: $BASELINE_JAR"

BASELINE_SHA=$(sha256sum "$BASELINE_JAR" | awk '{print $1}')
echo "Baseline JAR SHA-256: $BASELINE_SHA"
echo "BASELINE_SHA=$BASELINE_SHA" >> "$GITHUB_ENV"
echo "BASELINE_JAR=$BASELINE_JAR" >> "$GITHUB_ENV"

echo "Verifying CacheTestMarker class DOES NOT exist in baseline JAR..."
if jar tf "$BASELINE_JAR" | grep -q "CacheTestMarker"; then
echo "ERROR: CacheTestMarker already exists in baseline JAR before code changes!"
exit 1
else
echo "ASSERTION PASSED: CacheTestMarker is not in the baseline JAR."
fi
- name: 3. Simulate Code Change in Module & Re-install
run: |
echo "============================================================"
echo "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)
echo "package com.google.type;" > "$MARKER_FILE"
echo "public class CacheTestMarker {" >> "$MARKER_FILE"
echo " public static final String TIMESTAMP = \"$TIMESTAMP\";" >> "$MARKER_FILE"
echo " public static final String VERSION_MARKER = \"TEST_CACHE_OVERWRITE_VERIFIED_$TIMESTAMP\";" >> "$MARKER_FILE"
echo "}" >> "$MARKER_FILE"
echo "Created source marker:"
cat "$MARKER_FILE"

echo "Re-installing modified module with mvn install..."
mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -B -ntp -T 1C
- name: 4. Verify & Assert Overwrite, SHA Change, and New Class in ~/.m2
run: |
echo "============================================================"
echo "Verifying newly built version physically overwrote ~/.m2..."
echo "============================================================"
ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos"
NEW_JAR=$(find "$ARTIFACT_DIR" -name "proto-google-common-protos-*.jar" ! -name "*-sources.jar" ! -name "*-tests.jar" | head -n 1)
echo "New JAR Path: $NEW_JAR"

NEW_SHA=$(sha256sum "$NEW_JAR" | awk '{print $1}')
echo "Baseline SHA-256: $BASELINE_SHA"
echo "New JAR SHA-256: $NEW_SHA"

if [ "$BASELINE_SHA" = "$NEW_SHA" ]; then
echo "ERROR: SHA-256 did not change! The artifact was not overwritten."
exit 1
fi
echo "ASSERTION PASSED: SHA-256 changed ($BASELINE_SHA -> $NEW_SHA), proving file was recompiled and overwritten."

echo "Verifying CacheTestMarker class NOW EXISTS inside the updated ~/.m2 jar..."
if jar tf "$NEW_JAR" | grep -q "CacheTestMarker"; then
jar tf "$NEW_JAR" | grep "CacheTestMarker"
echo "ASSERTION PASSED: CacheTestMarker.class is now present in the newly installed JAR."
else
echo "ERROR: CacheTestMarker class not found in installed JAR!"
exit 1
fi

echo "SUCCESS: All assertions passed! Local modules overwrite cached artifacts in ~/.m2/repository upon rebuild."

Loading