-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
36 lines (36 loc) · 1.3 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
name: Maven Periodic Cache
description: Caches the Maven repository periodically by date.
inputs:
cache-period-days:
description: The maximum duration in days to keep the cache.
required: true
default: '30'
additional-path:
description: Additional paths to cache (or not cache).
required: false
default: ''
key-suffix:
description: Additional suffix to add to the key.
required: false
default: ''
runs:
using: composite
steps:
# When code changes to a project are infrequent, and most commits
# change the pom.xml, it better to cache by date period rather than file
# hash.
- name: Calculate the cache period
shell: bash
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "Repo: $GITHUB_REPOSITORY=$leveler"
echo "::set-output name=CACHE_PERIOD::$(date +%Y)-$(($(($leveler + $(date +%-j))) / ${{ inputs.cache-period-days }}))"
id: cache-period
- name: Cache the local Maven repository
uses: actions/cache@v4
with:
path: |
~/.m2/repository
${{ inputs.additional-path }}
key: ${{ runner.os }}-maven-${{ steps.cache-period.outputs.CACHE_PERIOD }}${{ inputs.key-suffix }}
restore-keys: ${{ runner.os }}-maven-${{ steps.cache-period.outputs.CACHE_PERIOD }}