Skip to content

Commit

Permalink
Extracted maven-periodic-cache-action
Browse files Browse the repository at this point in the history
For when dependencies change frequently.
  • Loading branch information
freemanjp committed Aug 1, 2022
1 parent 2dd8dc3 commit c0a7a82
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .github/actions/maven-periodic-cache/action.yml
@@ -0,0 +1,27 @@
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-paths:
description: Additional paths to cache (or not cache).
required: false
default: ''
runs:
using: composite
steps:
- name: Calculate the cache period
shell: bash
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_PERIOD::$(date +%Y)-$(($(($leveler + $(date +%-j))) / ${{ inputs.cache-period-days }}))"
id: cache-interval
- name: Cache the local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
${{ inputs.additional-paths }}
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_PERIOD }}
14 changes: 2 additions & 12 deletions .github/workflows/maven-build.yml
Expand Up @@ -27,20 +27,10 @@ jobs:
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
uses: './github/actions/maven-periodic-cache'
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
additional-path: '!~/.m2/repository/com/github/gantsign/maven'
- name: Build with Maven
run: .github/scripts/build.sh
env:
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/maven-deploy.yml
Expand Up @@ -22,22 +22,10 @@ jobs:
java-version: 8
distribution: 'temurin'
gpg-private-key: ${{ secrets.GPG_KEY }}
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
uses: './github/actions/maven-interval-cache'
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}-deploy
restore-keys: |
${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
additional-path: '!~/.m2/repository/com/github/gantsign/maven'
- name: Deploy with Maven
run: .github/scripts/deploy.sh
env:
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/release.yml
Expand Up @@ -34,22 +34,10 @@ jobs:
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
uses: './github/actions/maven-interval-cache'
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}-deploy-site
restore-keys: |
${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
additional-path: '!~/.m2/repository/com/github/gantsign/maven'
- name: Configure Git user
run: >-
git config --global user.name 'John Freeman' &&
Expand Down

0 comments on commit c0a7a82

Please sign in to comment.