From 0408151d567edccffb32edf99d3482042fc4faac Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:36:05 +0000 Subject: [PATCH 1/7] ci: add verify-cache-overwrite test job to ci.yaml --- .github/workflows/ci.yaml | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1ecc2e783a8d..536b7ec02dfb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -440,4 +440,79 @@ 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + 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 "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: 2. Build and Install Baseline Module to ~/.m2 + run: | + echo "============================================================" + echo "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 + ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" + echo "Baseline files in $ARTIFACT_DIR:" + find "$ARTIFACT_DIR" -type f -exec ls -la {} + + - 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) + cat < "$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"; +} +EOF + echo "Created source marker:" + cat "$MARKER_FILE" + echo "Recording pre-install artifact timestamps and checksums in ~/.m2..." + find "$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" -name "*.jar" -exec sha256sum {} + || true + + echo "Re-installing modified module..." + mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -B -ntp -T 1C + - name: 4. Verify & Print Overwrite in Runner .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" + echo "Files in $ARTIFACT_DIR after re-install:" + find "$ARTIFACT_DIR" -type f -exec ls -la {} + + + echo "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!" From 7d576518ab1566ab5c314b5efa675fa63e523235 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:38:19 +0000 Subject: [PATCH 2/7] ci: use approved actions/checkout SHA in verify-cache-overwrite --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 536b7ec02dfb..6fe653ddff91 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -444,7 +444,7 @@ jobs: name: verify-cache-overwrite runs-on: ubuntu-latest steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 with: persist-credentials: false - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0 From 55023cb134b2a58ce4cd956a0edb3c5a97839c23 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:38:44 +0000 Subject: [PATCH 3/7] ci: enable push trigger on test-ci-cache-overwrite branch --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6fe653ddff91..68a13099ef49 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,6 +20,7 @@ on: push: branches: - main + - test-ci-cache-overwrite pull_request: name: ci jobs: From bdb34f5990a30a9a283d9a1438090179466d7a5e Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:39:12 +0000 Subject: [PATCH 4/7] ci: trigger workflow run for verify-cache-overwrite From 14c84aa8c69c16fe4006fa34a3a779a242bc4fa1 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:39:52 +0000 Subject: [PATCH 5/7] ci: update verify-cache-overwrite job dependencies and echo format --- .github/workflows/ci.yaml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 68a13099ef49..4512c9c8a038 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -443,6 +443,8 @@ jobs: 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 @@ -483,14 +485,11 @@ jobs: 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_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"; -} -EOF + 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 "Recording pre-install artifact timestamps and checksums in ~/.m2..." From ed31cfe35b5793af0db7c831d71ffe0e1a84c5d3 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:49:07 +0000 Subject: [PATCH 6/7] ci: add explicit pre-existence check and SHA comparison assertions in verify-cache-overwrite --- .github/workflows/ci.yaml | 60 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4512c9c8a038..9ac8e6482eb3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -463,20 +463,33 @@ jobs: 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 + echo "Sample existing 3rd-party dependencies in ~/.m2/repository:" + find "$HOME/.m2/repository" -maxdepth 3 -type d 2>/dev/null | sed -n '1,20p' else echo "No existing ~/.m2/repository found (first cold run for this cache key)." fi - - name: 2. Build and Install Baseline Module to ~/.m2 + - name: 2. Build and Install Baseline Module to ~/.m2 & Assert File Absence run: | echo "============================================================" - echo "Building and installing java-common-protos to ~/.m2..." + 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" - echo "Baseline files in $ARTIFACT_DIR:" - find "$ARTIFACT_DIR" -type f -exec ls -la {} + + 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 "============================================================" @@ -492,27 +505,36 @@ jobs: echo "}" >> "$MARKER_FILE" echo "Created source marker:" cat "$MARKER_FILE" - echo "Recording pre-install artifact timestamps and checksums in ~/.m2..." - find "$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" -name "*.jar" -exec sha256sum {} + || true - echo "Re-installing modified module..." + 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 & Print Overwrite in Runner .m2 + - 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" - echo "Files in $ARTIFACT_DIR after re-install:" - find "$ARTIFACT_DIR" -type f -exec ls -la {} + + 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" - echo "New JAR SHA256 checksums in ~/.m2:" - find "$ARTIFACT_DIR" -name "*.jar" -exec sha256sum {} + + NEW_SHA=$(sha256sum "$NEW_JAR" | awk '{print $1}') + echo "Baseline SHA-256: $BASELINE_SHA" + echo "New JAR SHA-256: $NEW_SHA" - 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; } + 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: The local module was freshly compiled and overwritten in ~/.m2/repository!" + echo "SUCCESS: All assertions passed! Local modules overwrite cached artifacts in ~/.m2/repository upon rebuild." From 1e6588b8268667d2ee2e1b4dbb75187c21f6d2f4 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 12 Aug 2026 20:55:19 +0000 Subject: [PATCH 7/7] ci: print all cached JAR and POM dependencies in verify-cache-overwrite --- .github/workflows/ci.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ac8e6482eb3..cc72c22b4312 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -463,8 +463,12 @@ jobs: if [ -d "$HOME/.m2/repository" ]; then echo "Cache Restored! ~/.m2/repository directory size:" du -sh "$HOME/.m2/repository" || true - echo "Sample existing 3rd-party dependencies in ~/.m2/repository:" - find "$HOME/.m2/repository" -maxdepth 3 -type d 2>/dev/null | sed -n '1,20p' + 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