From a0e16579ce299d467fb93a20650052f8d3057f13 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Sat, 11 Jul 2026 22:31:54 +0200 Subject: [PATCH] [FLINK-40124][ci] Do not store cache on every run if no dependency changed --- .github/actions/job_init/action.yml | 21 ++++++++++++--- .github/workflows/template.flink-ci.yml | 34 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/.github/actions/job_init/action.yml b/.github/actions/job_init/action.yml index a56238be3c6935..ea44331507dcfb 100644 --- a/.github/actions/job_init/action.yml +++ b/.github/actions/job_init/action.yml @@ -38,6 +38,13 @@ inputs: description: "Runs tools/azure-pipelines/free_disk_space.sh to remove unneeded pre-installed software from the runner (only works for jobs that run directly on the host, not in a container)." required: false default: "false" +outputs: + maven-cache-hit: + description: "Whether the Maven package cache was restored via an exact key match. Callers should only save a new cache when this is not 'true'." + value: ${{ steps.maven-cache-restore.outputs.cache-hit }} + maven-cache-key: + description: "The cache key computed for the Maven package cache, for use by a caller's own explicit save step (placed after Maven has actually run)." + value: ${{ steps.maven-cache-key.outputs.key }} runs: using: "composite" steps: @@ -105,14 +112,20 @@ runs: echo "namespace=${ns}" >> "${GITHUB_OUTPUT}" echo "Cache namespace: ${ns}" - - name: "Setup Maven package cache" + - name: "Compute Maven package cache key" if: ${{ inputs.maven_repo_folder != '' }} - uses: actions/cache@v5 + id: maven-cache-key + shell: bash + run: echo "key=${{ runner.os }}-ns-${{ steps.cache-ns.outputs.namespace }}-maven-${{ hashFiles('**/pom.xml') }}" >> "${GITHUB_OUTPUT}" + + - name: "Restore Maven package cache" + if: ${{ inputs.maven_repo_folder != '' }} + id: maven-cache-restore + uses: actions/cache/restore@v6 with: path: ${{ inputs.maven_repo_folder }} - key: ${{ runner.os }}-ns-${{ steps.cache-ns.outputs.namespace }}-maven-${{ hashFiles('**/pom.xml') }}-${{ github.run_id }} + key: ${{ steps.maven-cache-key.outputs.key }} restore-keys: | - ${{ runner.os }}-ns-${{ steps.cache-ns.outputs.namespace }}-maven-${{ hashFiles('**/pom.xml') }}- ${{ runner.os }}-ns-${{ steps.cache-ns.outputs.namespace }}-maven- ${{ runner.os }}-maven- diff --git a/.github/workflows/template.flink-ci.yml b/.github/workflows/template.flink-ci.yml index c18f633a68e885..8f8c5ad3b6229f 100644 --- a/.github/workflows/template.flink-ci.yml +++ b/.github/workflows/template.flink-ci.yml @@ -88,6 +88,7 @@ jobs: persist-credentials: false - name: "Initialize job" + id: job-init uses: "./.github/actions/job_init" with: jdk_version: ${{ inputs.jdk_version }} @@ -123,6 +124,15 @@ jobs: # use minimum here because we only need these artifacts to speed up the build retention-days: 1 + # Only saves when the restore in job_init wasn't an exact hit, i.e. pom.xml actually + # changed since the last save for this namespace - avoids re-uploading an unchanged cache. + - name: "Save Maven package cache" + if: ${{ !cancelled() && steps.job-init.outputs.maven-cache-hit != 'true' }} + uses: actions/cache/save@v6 + with: + path: ${{ env.MAVEN_REPO_FOLDER }} + key: ${{ steps.job-init.outputs.maven-cache-key }} + packaging: name: "Test packaging/licensing" needs: compile @@ -145,6 +155,7 @@ jobs: tools - name: "Initialize job" + id: job-init uses: "./.github/actions/job_init" with: jdk_version: ${{ inputs.jdk_version }} @@ -168,6 +179,13 @@ jobs: run: | ${{ inputs.environment }} ./tools/ci/compile_ci.sh || exit $? + - name: "Save Maven package cache" + if: ${{ !cancelled() && steps.job-init.outputs.maven-cache-hit != 'true' }} + uses: actions/cache/save@v6 + with: + path: ${{ env.MAVEN_REPO_FOLDER }} + key: ${{ steps.job-init.outputs.maven-cache-key }} + test: name: "Test (module: ${{ matrix.module }})" needs: compile @@ -212,6 +230,7 @@ jobs: tools - name: "Initialize job" + id: job-init uses: "./.github/actions/job_init" with: jdk_version: ${{ inputs.jdk_version }} @@ -315,6 +334,13 @@ jobs: if: ${{ !cancelled() && (failure() || steps.docker-cache.outputs.cache-hit != 'true') }} run: ./tools/azure-pipelines/cache_docker_images.sh save + - name: "Save Maven package cache" + if: ${{ !cancelled() && steps.job-init.outputs.maven-cache-hit != 'true' }} + uses: actions/cache/save@v6 + with: + path: ${{ env.MAVEN_REPO_FOLDER }} + key: ${{ steps.job-init.outputs.maven-cache-key }} + e2e: name: "E2E (group ${{ matrix.group }})" needs: compile @@ -353,6 +379,7 @@ jobs: tools - name: "Initialize job" + id: job-init uses: "./.github/actions/job_init" with: jdk_version: ${{ inputs.jdk_version }} @@ -446,3 +473,10 @@ jobs: - name: "Save Docker images to Cache" if: ${{ !cancelled() && (failure() || steps.docker-cache.outputs.cache-hit != 'true') }} run: ./tools/azure-pipelines/cache_docker_images.sh save + + - name: "Save Maven package cache" + if: ${{ !cancelled() && steps.job-init.outputs.maven-cache-hit != 'true' }} + uses: actions/cache/save@v6 + with: + path: ${{ env.MAVEN_REPO_FOLDER }} + key: ${{ steps.job-init.outputs.maven-cache-key }}