From 571dbb4b6fe94bee59db211554dca4989140b4e4 Mon Sep 17 00:00:00 2001 From: Jorge Bornhausen Date: Wed, 6 Nov 2024 17:00:37 +0100 Subject: [PATCH 1/2] ci(forgejo-actions): implement cache of ~/.m2/repository --- .gitea/workflows/build.yml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index fe95ecf..3235fef 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -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 \ No newline at end of file From 9da1fd106cbe82f6c26c06202dff5144435e22d5 Mon Sep 17 00:00:00 2001 From: Jorge Bornhausen Date: Wed, 6 Nov 2024 17:03:22 +0100 Subject: [PATCH 2/2] ci(forgejo-actions): added missing cache key --- .gitea/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 3235fef..9b04655 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -40,6 +40,7 @@ jobs: 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 + echo "m2-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITEA_OUTPUT - name: Cache Maven Repository id: cache-maven