ci(github-actions): use multiple maven caches for increased hit rate, use forgejo checkout action
All checks were successful
Build / build (pull_request) Successful in 1m32s

This commit is contained in:
Jorge Bornhausen 2025-01-30 09:12:56 +01:00
parent 18bcf47b57
commit 3d569f7a35
Signed by: jorge.bornhausen
SSH key fingerprint: SHA256:X2ootOwvCeP4FoNfmVUFIKIbhq95tAgnt7Oqg3x+lfs
2 changed files with 46 additions and 4 deletions

View file

@ -22,7 +22,7 @@ jobs:
steps: steps:
- name: Checkout the code - name: Checkout the code
uses: https://github.com/actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
@ -31,7 +31,28 @@ jobs:
with: with:
distribution: 'temurin' distribution: 'temurin'
java-version: '21' 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 - name: Configure Maven CI/CD settings
uses: https://github.com/s4u/maven-settings-action@v3.1.0 uses: https://github.com/s4u/maven-settings-action@v3.1.0

View file

@ -17,7 +17,7 @@ jobs:
steps: steps:
- name: Checkout the code - name: Checkout the code
uses: https://github.com/actions/checkout@v4 uses: actions/checkout@v4
- name: Retrieve project metadata - name: Retrieve project metadata
uses: https://github.com/radcortez/project-metadata-action@master uses: https://github.com/radcortez/project-metadata-action@master
@ -64,7 +64,28 @@ jobs:
with: with:
distribution: 'temurin' distribution: 'temurin'
java-version: '21' 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 - name: Make maven wrapper executable
run: chmod +x mvnw run: chmod +x mvnw