From 0d32c48d80ccb529f533bc803547040d09924ad0 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 12 May 2021 11:41:03 +0200 Subject: [PATCH] Correctly setup cache to be able to make use of different restore keys (#11248) Motivation: We should setup the caching so it will be able to use different restore keys and so almost never need to start from scratch Modifications: Adjust caching config to make use of different restore keys for maven caching but also docker caching Result: Better cache usage --- .github/workflows/ci-build.yml | 8 ++++--- .github/workflows/ci-deploy.yml | 6 ++++-- .github/workflows/ci-pr.yml | 14 ++++++++----- .github/workflows/ci-release.yml | 30 ++++++++++++++++++++++----- .github/workflows/codeql-analysis.yml | 3 ++- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 1839224a4d..920e1463e9 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -29,17 +29,19 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-${{ matrix.setup }}- ${{ runner.os }}-maven- # Enable caching of Docker layers - uses: satackey/action-docker-layer-caching@v0.0.11 continue-on-error: true with: - key: build-${{ matrix.setup }}-docker-cache-{hash} + key: build-docker-cache-${{ matrix.setup }}-{hash} restore-keys: | - build-${{ matrix.setup }}-docker-cache- + build-docker-cache-${{ matrix.setup }}- + build-docker-cache- - name: Build docker image run: docker-compose ${{ matrix.docker-compose-build }} diff --git a/.github/workflows/ci-deploy.yml b/.github/workflows/ci-deploy.yml index 7314f20aa4..6917f3c11d 100644 --- a/.github/workflows/ci-deploy.yml +++ b/.github/workflows/ci-deploy.yml @@ -32,8 +32,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-${{ matrix.setup }}- ${{ runner.os }}-maven- # Enable caching of Docker layers @@ -79,8 +80,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-deploy-staged-snapshots-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-deploy-staged-snapshots- ${{ runner.os }}-maven- # Setup some env to re-use later. diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 2de731a9af..1f679ca540 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -21,8 +21,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-verify-pr-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-verify-pr- ${{ runner.os }}-maven- - name: Verify with Maven run: mvn verify -B --file pom.xml -Pci -DskipTests=true @@ -40,8 +41,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-build-pr-aarch64-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-build-pr-aarch64- ${{ runner.os }}-maven- - uses: uraimo/run-on-arch-action@v2.0.9 @@ -96,17 +98,19 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-${{ matrix.setup }}-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-${{ matrix.setup }}- ${{ runner.os }}-maven- # Enable caching of Docker layers - uses: satackey/action-docker-layer-caching@v0.0.11 continue-on-error: true with: - key: build-${{ matrix.setup }}-docker-cache-{hash} + key: build-docker-cache-${{ matrix.setup }}-{hash} restore-keys: | - build-${{ matrix.setup }}-docker-cache- + build-docker-cache-${{ matrix.setup }}- + build-docker-cache- - name: Build docker image run: docker-compose ${{ matrix.docker-compose-build }} diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index e90da58891..e33038837d 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -34,8 +34,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-prepare-release-${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-prepare-release- ${{ runner.os }}-maven- - name: Prepare release with Maven @@ -95,13 +96,12 @@ jobs: # Enable caching of Docker layers - uses: satackey/action-docker-layer-caching@v0.0.11 - env: - docker-cache-name: staging-${{ matrix.setup }}-cache-docker continue-on-error: true with: - key: ${{ runner.os }}-staging-${{ env.docker-cache-name }}-{hash} + key: ${{ runner.os }}-staging-docker-cache-${{ matrix.setup }}-{hash} restore-keys: | - ${{ runner.os }}-staging-${{ env.docker-cache-name }}- + ${{ runner.os }}-staging-docker-cache-${{ matrix.setup }}- + ${{ runner.os }}-staging-docker-cache- - uses: s4u/maven-settings-action@v2.2.0 with: @@ -112,6 +112,16 @@ jobs: "password": "${{ secrets.SONATYPE_PASSWORD }}" }] + # Cache .m2/repository + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ matrix.setup }-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-${{ matrix.setup }- + ${{ runner.os }}-maven- + - name: Create local staging directory run: mkdir -p ~/local-staging @@ -196,6 +206,16 @@ jobs: "password": "${{ secrets.SONATYPE_PASSWORD }}" }] + # Cache .m2/repository + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-deploy-staged-release-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-deploy-staged-release- + ${{ runner.os }}-maven- + - name: Deploy local staged artifacts working-directory: ./prepare-release-workspace/ # If we don't want to close the repository we can add -DskipStagingRepositoryClose=true diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9e0d9c81a6..b2ae4fd095 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -41,8 +41,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-${{ matrix.language }} ${{ hashFiles('**/pom.xml') }} restore-keys: | + ${{ runner.os }}-maven-${{ matrix.language }} ${{ runner.os }}-maven- # If this run was triggered by a pull request event, then checkout