From 3d569f7a355547ba2d02c5522041c34446597cf4 Mon Sep 17 00:00:00 2001 From: Jorge Bornhausen Date: Thu, 30 Jan 2025 09:12:56 +0100 Subject: [PATCH] ci(github-actions): use multiple maven caches for increased hit rate, use forgejo checkout action --- .github/workflows/build.yaml | 25 +++++++++++++++++++++++-- .github/workflows/release.yaml | 25 +++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 983a5ec..298e5f4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,7 +22,7 @@ jobs: steps: - name: Checkout the code - uses: https://github.com/actions/checkout@v4 + uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis @@ -31,7 +31,28 @@ jobs: with: distribution: 'temurin' java-version: '21' - cache: 'maven' + + - name: Generate cache keys + id: cache-key + run: | + CURRENT_BRANCH="${{ github.head_ref || github.ref_name }}" + CURRENT_MONTH=$(/bin/date -u "+%Y-%m") + CURRENT_DAY=$(/bin/date -u "+%d") + ROOT_CACHE_KEY="m2-cache-quarkus-commons" + echo "m2-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT + echo "m2-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT + echo "m2-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT + + - name: Cache Maven Repository + id: cache-maven + uses: actions/cache@v4 + with: + path: ~/.m2/repository + # The cache is per branch but in case we don't find a branch for a given branch, we will get a cache from another branch. + key: ${{ steps.cache-key.outputs.m2-cache-key }} + restore-keys: | + ${{ steps.cache-key.outputs.m2-monthly-branch-cache-key }} + ${{ steps.cache-key.outputs.m2-monthly-cache-key }} - name: Configure Maven CI/CD settings uses: https://github.com/s4u/maven-settings-action@v3.1.0 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9dfa3b1..37ff2fd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout the code - uses: https://github.com/actions/checkout@v4 + uses: actions/checkout@v4 - name: Retrieve project metadata uses: https://github.com/radcortez/project-metadata-action@master @@ -64,7 +64,28 @@ jobs: with: distribution: 'temurin' java-version: '21' - cache: 'maven' + + - name: Generate cache keys + id: cache-key + run: | + CURRENT_BRANCH="${{ github.ref_name }}" + CURRENT_MONTH=$(/bin/date -u "+%Y-%m") + CURRENT_DAY=$(/bin/date -u "+%d") + ROOT_CACHE_KEY="m2-cache-quarkus-commons" + echo "m2-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT + echo "m2-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT + echo "m2-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT + + - name: Cache Maven Repository + id: cache-maven + uses: actions/cache@v4 + with: + path: ~/.m2/repository + # The cache is per branch but in case we don't find a branch for a given branch, we will get a cache from another branch. + key: ${{ steps.cache-key.outputs.m2-cache-key }} + restore-keys: | + ${{ steps.cache-key.outputs.m2-monthly-branch-cache-key }} + ${{ steps.cache-key.outputs.m2-monthly-cache-key }} - name: Make maven wrapper executable run: chmod +x mvnw