Skip to content

Commit 2521f41

Browse files
committed
ci: add test-cache-overwrite workflow to verify local .m2 cache overwrite
- Adds standalone test workflow that checks restored ~/.m2 cache - Compiles baseline module, modifies source code with dynamic version marker, and re-installs - Verifies and prints that the modified artifact physically overwrites ~/.m2/repository in the runner
1 parent be65643 commit 2521f41

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: test-cache-overwrite
16+
17+
on:
18+
push:
19+
branches:
20+
- '**'
21+
pull_request:
22+
workflow_dispatch:
23+
24+
permissions:
25+
contents: read
26+
27+
jobs:
28+
verify-cache-overwrite:
29+
name: Verify Maven Cache & Local .m2 Overwrite
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
34+
with:
35+
persist-credentials: false
36+
37+
- name: Set up Java 17 with Maven Cache
38+
uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0
39+
with:
40+
distribution: temurin
41+
java-version: 17
42+
cache: maven
43+
44+
- name: Inspect Initial Restored .m2 Cache
45+
run: |
46+
echo "============================================================"
47+
echo "1. Checking initial state of ~/.m2/repository from cache..."
48+
echo "============================================================"
49+
if [ -d "$HOME/.m2/repository" ]; then
50+
echo "Cache Restored! ~/.m2/repository directory size:"
51+
du -sh "$HOME/.m2/repository" || true
52+
echo "Sample existing dependencies in ~/.m2/repository:"
53+
find "$HOME/.m2/repository" -maxdepth 3 -type d | head -n 20 || true
54+
else
55+
echo "No existing ~/.m2/repository found (first cold run for this cache key)."
56+
fi
57+
58+
- name: Build and Install Module to .m2 (Baseline)
59+
run: |
60+
echo "============================================================"
61+
echo "2. Building and installing java-common-protos to ~/.m2..."
62+
echo "============================================================"
63+
mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -am -B -ntp -T 1C
64+
65+
echo "Inspecting baseline installed artifact in ~/.m2/repository:"
66+
ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos"
67+
find "$ARTIFACT_DIR" -type f -exec ls -la {} +
68+
69+
- name: Simulate Code Change in Module & Re-install to .m2
70+
run: |
71+
echo "============================================================"
72+
echo "3. Modifying source file in java-common-protos to create a new version..."
73+
echo "============================================================"
74+
MARKER_FILE="java-common-protos/proto-google-common-protos/src/main/java/com/google/type/CacheTestMarker.java"
75+
mkdir -p "$(dirname "$MARKER_FILE")"
76+
TIMESTAMP=$(date +%s)
77+
cat <<MARKER > "$MARKER_FILE"
78+
package com.google.type;
79+
80+
public class CacheTestMarker {
81+
public static final String TIMESTAMP = "$TIMESTAMP";
82+
public static final String VERSION_MARKER = "TEST_CACHE_OVERWRITE_VERIFIED_$TIMESTAMP";
83+
}
84+
MARKER
85+
86+
echo "Created source marker: $MARKER_FILE"
87+
cat "$MARKER_FILE"
88+
89+
echo "Recording pre-install artifact timestamps and checksums in ~/.m2..."
90+
PRE_SHA=$(find "$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos" -name "*.jar" -exec sha256sum {} + || true)
91+
echo "Pre-build JAR SHA256 in ~/.m2:"
92+
echo "$PRE_SHA"
93+
94+
echo "Re-installing modified module..."
95+
mvn install -Pquick-build -DskipTests=true -pl java-common-protos/proto-google-common-protos -B -ntp -T 1C
96+
97+
- name: Verify Overwrite in Runner .m2
98+
run: |
99+
echo "============================================================"
100+
echo "4. Verifying newly built version physically overwrote ~/.m2..."
101+
echo "============================================================"
102+
ARTIFACT_DIR="$HOME/.m2/repository/com/google/api/grpc/proto-google-common-protos"
103+
echo "Files in $ARTIFACT_DIR:"
104+
find "$ARTIFACT_DIR" -type f -exec ls -la {} +
105+
106+
echo "Checking new JAR SHA256 checksums in ~/.m2:"
107+
find "$ARTIFACT_DIR" -name "*.jar" -exec sha256sum {} +
108+
109+
echo "Extracting and verifying CacheTestMarker class inside ~/.m2 jar:"
110+
JAR_FILE=$(find "$ARTIFACT_DIR" -name "proto-google-common-protos-*.jar" ! -name "*-sources.jar" ! -name "*-tests.jar" | head -n 1)
111+
echo "Checking JAR: $JAR_FILE"
112+
jar tf "$JAR_FILE" | grep "CacheTestMarker" || { echo "ERROR: Marker class not found in installed JAR!"; exit 1; }
113+
114+
echo "SUCCESS: The local module was freshly compiled and overwritten in ~/.m2/repository!"

0 commit comments

Comments
 (0)