ci(forgejo-actions): implement cache of ~/.m2/repository

This commit is contained in:
Jorge Bornhausen 2024-11-06 17:00:37 +01:00
parent 120b3fdcc8
commit 571dbb4b6f
Signed by: jorge.bornhausen
SSH key fingerprint: SHA256:X2ootOwvCeP4FoNfmVUFIKIbhq95tAgnt7Oqg3x+lfs

View file

@ -31,12 +31,48 @@ jobs:
}
}]
- name: Generate Maven Repository cache keys
id: cache-key
run: |
CURRENT_BRANCH="${{ gitea.base_ref || gitea.ref_name }}"
CURRENT_MONTH=$(/bin/date -u "+%Y-%m")
CURRENT_DAY=$(/bin/date -u "+%d")
ROOT_CACHE_KEY="m2-cache"
echo "m2-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITEA_OUTPUT
echo "m2-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITEA_OUTPUT
- name: Cache Maven Repository
id: cache-maven
uses: https://github.com/actions/cache@v4
with:
path: ~/.m2/repository
# A new cache will be stored daily. After that first store of the day, cache save actions will fail because the cache is immutable but it's not a problem.
# The whole cache is dropped monthly to prevent unlimited growth.
# 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: Restore Maven Repository
uses: https://github.com/actions/cache/restore@v4
with:
path: ~/.m2/repository
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
- name: Populate the cache
run: |
./mvnw quarkus:go-offline
- name: Build and run tests
run: ./mvnw verify
- name: Upload libs to Gitea Maven Registry
- name: Upload libs to Forgejo Maven Registry
if: gitea.ref == 'refs/heads/main'
run: ./mvnw deploy -Dmaven.test.skip=true -Dmaven.javadoc.skip=true