cache-maven/action.yml

32 lines
No EOL
1.3 KiB
YAML

name: 'Maven Cache'
description: 'The .m2/repository caching mechanism'
inputs:
root-cache-key:
description: 'The unique root key for the cache. For example `m2-cache-project-name`.'
required: true
runs:
using: 'composite'
steps:
- name: Generate cache keys
id: generate-cache-keys
shell: bash
run: |
CURRENT_BRANCH="${{ github.head_ref || github.ref_name }}"
CURRENT_MONTH=$(/bin/date -u "+%Y-%m")
CURRENT_DAY=$(/bin/date -u "+%d")
echo "m2-monthly-cache-key=${{ inputs.root-cache-key }}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT
echo "m2-monthly-branch-cache-key=${{ inputs.root-cache-key }}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT
echo "m2-cache-key=${{ inputs.root-cache-key }}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT
- name: Cache Maven repository
id: cache-maven-repository
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.generate-cache-keys.outputs.m2-cache-key }}
restore-keys: |
${{ steps.generate-cache-keys.outputs.m2-monthly-branch-cache-key }}
${{ steps.generate-cache-keys.outputs.m2-monthly-cache-key }}