Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/prime-maven-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Prime Maven Cache'
description: 'Pre-populates Maven dependencies into ~/.m2/repository and GitHub Actions Cache'

runs:
using: 'composite'
steps:
# JDK version does not impact priming or matching the Maven cache, as cache keys are derived
# from ${{ runner.os }} and SHA-256 hashes of pom.xml files, not the JDK version.
# We default to the latest LTS version (25) to run the pre-population step.
# Furthermore, GitHub Actions Cache entries are immutable by primary key: downstream jobs
# restoring this cache can run 'mvn install' or add SNAPSHOT JARs locally without ever
# polluting or overwriting the remote cache.
- uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
id: setup-java
with:
java-version: 25
distribution: 'temurin'
cache: 'maven'
Comment on lines +9 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are two improvements needed here:

  1. Java Version: The latest LTS version of Java is currently 21. Java 25 is not yet released as a General Availability (GA) LTS version, so specifying 25 may cause setup failures or use unstable early-access builds.
  2. Documentation Clarification: In accordance with the project's general rules, we should clarify in the documentation that mvn install is used for building snapshot artifacts to the local ~/.m2 repository.
    # We default to the latest LTS version (21) to run the pre-population step.
    # Furthermore, GitHub Actions Cache entries are immutable by primary key: downstream jobs
    # restoring this cache can run 'mvn install' (which is used for building snapshot artifacts
    # to the local ~/.m2 repository) or add SNAPSHOT JARs locally without ever
    # polluting or overwriting the remote cache.
    - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
      with:
        java-version: 21
        distribution: 'temurin'
        cache: 'maven'
References
  1. In documentation about the Java build process, clarify that mvn install is used for building snapshot artifacts to the local ~/.m2 repository.

# Only run mvn test-compile if this is a primary key CACHE MISS (new/modified pom.xml).
# If cache-hit == 'true', ~/.m2/repository is already warm in GitHub Actions Cache and
# this step is skipped entirely (~3s total job execution!).
# Why 'mvn test-compile'?
# Using test-compile (instead of compile) downloads both production dependencies (compile scope)
# AND test libraries (test scope: JUnit, Mockito, Truth, Testcontainers) into ~/.m2/repository.
# When this job completes, setup-java saves ~/.m2/repository to GitHub Actions Cache.
# Downstream unit test jobs restore this cache and run offline without downloading any JARs from Maven Central.
- name: Prime Maven Cache
if: steps.setup-java.outputs.cache-hit != 'true'
shell: bash
run: mvn test-compile -DskipTests -Pquick-build -T 1C --batch-mode --no-transfer-progress
63 changes: 22 additions & 41 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ jobs:
- '.github/workflows/ci.yaml'
- '.kokoro/**'
# these unit tests are "bulk" (non-handwritten) libraries
# prime-cache populates ~/.m2/repository once for the entire workflow.
# This downloads all required JARs so downstream unit test jobs do not need to download any JARs from Maven Central.
prime-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- uses: ./.github/actions/prime-maven-cache

units:
runs-on: ubuntu-latest
needs: bulk-filter
needs: [bulk-filter, prime-cache]
strategy:
fail-fast: false
matrix:
java: [11, 17, 21, 25, 26]
steps:
- name: Get current week within the year
id: date
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
run: echo "::set-output name=week_of_year::$(date +'%W' --utc)"
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
with:
Expand All @@ -79,28 +85,19 @@ jobs:
with:
distribution: temurin
java-version: ${{matrix.java}}
cache: maven
- run: java -version
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: mvn-cache
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.week_of_year }}
- run: .kokoro/build.sh
if: ${{ needs.bulk-filter.outputs.runnable == 'true' && (needs.bulk-filter.outputs.src == 'true' || needs.bulk-filter.outputs.ci == 'true') }}
env:
JOB_TYPE: test
JOB_NAME: units-${{matrix.java}}
units-8-runtime:
runs-on: ubuntu-latest
needs: bulk-filter
needs: [bulk-filter, prime-cache]
name: "units (8)"
steps:
- name: Get current week within the year
id: date
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
run: echo "::set-output name=week_of_year::$(date +'%W' --utc)"
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
with:
Expand All @@ -122,12 +119,6 @@ jobs:
java-version: 11
distribution: temurin
cache: maven
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: mvn-cache
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.week_of_year }}
- run: .kokoro/build.sh
if: ${{ needs.bulk-filter.outputs.runnable == 'true' && (needs.bulk-filter.outputs.src == 'true' || needs.bulk-filter.outputs.ci == 'true') }}
shell: bash
Expand All @@ -136,7 +127,7 @@ jobs:
JOB_NAME: units-8-runtime-${{matrix.java}}
# detect which libraries have changed
changes:
needs: bulk-filter
needs: [bulk-filter, prime-cache]
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -271,16 +262,14 @@ jobs:
package: ${{ fromJSON(needs.changes.outputs.packages) }}
java: [11, 17, 21, 25, 26]
steps:
- name: Get current week within the year
id: date
run: echo "::set-output name=week_of_year::$(date +'%W' --utc)"
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4
with:
distribution: temurin
java-version: ${{matrix.java}}
cache: maven
- run: .kokoro/build.sh
env:
BUILD_SUBDIR: ${{matrix.package}}
Expand All @@ -296,9 +285,6 @@ jobs:
package: ${{ fromJSON(needs.changes.outputs.packages) }}
java: [8]
steps:
- name: Get current week within the year
id: date
run: echo "::set-output name=week_of_year::$(date +'%W' --utc)"
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
Expand All @@ -308,11 +294,6 @@ jobs:
distribution: temurin
cache: maven
- run: java -version
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: mvn-cache
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.week_of_year }}
- name: Install all modules using Java 11
shell: bash
run: .kokoro/build.sh
Expand Down Expand Up @@ -353,6 +334,7 @@ jobs:
with:
distribution: temurin
java-version: 11
cache: maven
- run: .kokoro/build.sh
env:
BUILD_SUBDIR: ${{matrix.package}}
Expand All @@ -372,6 +354,7 @@ jobs:
with:
distribution: temurin
java-version: 17
cache: maven
- run: .kokoro/dependencies.sh
env:
BUILD_SUBDIR: ${{matrix.package}}
Expand All @@ -387,7 +370,7 @@ jobs:
- name: Success otherwise
run: echo "Success!"
windows:
needs: bulk-filter
needs: [bulk-filter, prime-cache]
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: windows-latest
steps:
Expand All @@ -407,7 +390,7 @@ jobs:
JOB_TYPE: test
JOB_NAME: windows-units
lint:
needs: bulk-filter
needs: [bulk-filter, prime-cache]
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: ubuntu-latest
steps:
Expand All @@ -419,20 +402,18 @@ jobs:
with:
distribution: temurin
java-version: 17
cache: maven
- run: java -version
- run: .kokoro/build.sh
env:
JOB_TYPE: lint
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
enforcer:
needs: bulk-filter
needs: [bulk-filter, prime-cache]
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Get current week within the year
id: date
run: echo "::set-output name=week_of_year::$(date +'%W' --utc)"
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
Expand All @@ -449,7 +430,7 @@ jobs:
- run: java -version
- run: mvn -B -ntp enforcer:enforce@enforce -T 1C
gapic-libraries-bom:
needs: bulk-filter
needs: [bulk-filter, prime-cache]
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}
runs-on: ubuntu-latest
steps:
Expand Down
Loading