From 79f69140616f22f2420f198e2d953c048426dc30 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Mon, 1 Aug 2022 19:13:26 +0100 Subject: [PATCH] Extracted maven-periodic-cache-action For when dependencies change frequently. --- .../actions/maven-periodic-cache/action.yml | 27 +++++++++++++++++++ .github/workflows/maven-build.yml | 14 ++-------- .github/workflows/maven-deploy.yml | 16 ++--------- .github/workflows/release.yml | 16 ++--------- 4 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 .github/actions/maven-periodic-cache/action.yml diff --git a/.github/actions/maven-periodic-cache/action.yml b/.github/actions/maven-periodic-cache/action.yml new file mode 100644 index 00000000..2a60035a --- /dev/null +++ b/.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 }} diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index d6c83a34..58aa5761 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -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: diff --git a/.github/workflows/maven-deploy.yml b/.github/workflows/maven-deploy.yml index 230f9b1d..886d0474 100644 --- a/.github/workflows/maven-deploy.yml +++ b/.github/workflows/maven-deploy.yml @@ -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: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 794f66e2..4c4f023b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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' &&