From a1dfd09c11eba51ba16589645cd9e74a6c84a927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Derehaj=C5=82o?= Date: Fri, 11 Jul 2025 12:47:08 +0200 Subject: [PATCH] feat: inital commit --- .gitignore | 6 ++++++ README.md | 12 ++++++++++++ action.yml | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 action.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c2548b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__test__/_temp +_temp/ +lib/ +node_modules/ +.vscode/ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c6f313 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Maven Cache V1 + +This is a more advanced maven cache action. + +## Usage + +``` +- name: Cache Maven repository + uses: https://git.kvant.cloud/actions/maven-cache@v1 + with: + root-cache-key: 'm2-cache-project-name' # this should be unique +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..918760c --- /dev/null +++ b/action.yml @@ -0,0 +1,32 @@ +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 }} \ No newline at end of file