Skip to content

Commit

Permalink
Cache Node.js artifacts from maven-frontend-plugin on CI
Browse files Browse the repository at this point in the history
Closes #31835

Signed-off-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
jonkoops committed Oct 16, 2024
1 parent 61fffce commit 8ea2480
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions .github/actions/maven-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@ runs:
# Two asterisks are needed to make the follow-up exclusion work
# see https://github.com/actions/toolkit/issues/713 for the upstream issue
path: |
~/.m2/repository/*/*
~/.m2/repository/*/*/*/*
!~/.m2/repository/org/keycloak
!~/.m2/repository/com/github/eirslett/node
!~/.m2/repository/com/github/eirslett/pnpm
key: ${{ steps.weekly-cache-key.outputs.key }}
# Enable cross-os archive use the cache on both Linux and Windows
enableCrossOsArchive: true

- id: download-node-for-windows
# This is necessary as the build which creates the cache will run on a Linux node and therefore will never download the Windows artifact by default.
# If we wouldn't download it manually, it would be downloaded on each Windows build, which proved to be unstable as downloads would randomly fail in the middle of the download.
if: inputs.create-cache-if-it-doesnt-exist == 'true' && steps.cache-maven-repository.outputs.cache-hit != 'true'
shell: bash
run: |
export VERSION=$(mvn help:evaluate -Dexpression=node.version -q -DforceStdout | cut -c 2-)
curl -Lf https://nodejs.org/dist/v${VERSION}/win-x64/node.exe --create-dirs -o ~/.m2/repository/com/github/eirslett/node/${VERSION}/node-${VERSION}-win-x64.exe
- shell: powershell
name: Link the cached Maven repository to the OS-dependent location
if: inputs.create-cache-if-it-doesnt-exist == 'false' && runner.os == 'Windows'
Expand All @@ -58,7 +51,32 @@ runs:
with:
# This needs to repeat the same path pattern as above to find the matching cache
path: |
~/.m2/repository/*/*
~/.m2/repository/*/*/*/*
!~/.m2/repository/org/keycloak
!~/.m2/repository/com/github/eirslett/node
!~/.m2/repository/com/github/eirslett/pnpm
key: ${{ steps.weekly-cache-key.outputs.key }}
enableCrossOsArchive: true
enableCrossOsArchive: true

- name: List the contents of the Maven repository
shell: bash
run: |
ls -R ~/.m2/repository/org/apache || exit 0
ls -R ~/.m2/repository/org/keycloak || exit 0
ls -R ~/.m2/repository/com/github/eirslett || exit 0
- name: Get Node.js and PNPM versions
id: tooling-versions
shell: bash
run: |
echo "node=$(mvn help:evaluate -Dexpression=node.version -q -DforceStdout | cut -c 2-)" >> $GITHUB_OUTPUT
echo "pnpm=$(mvn help:evaluate -Dexpression=pnpm.version -q -DforceStdout)" >> $GITHUB_OUTPUT
# Downloading Node.js often fails due to network issues, therefore we cache the artifacts downloaded by the frontend plugin.
- uses: actions/cache@v4
name: Cache Node.js related artifacts
with:
path: |
~/.m2/repository/com/github/eirslett/node
~/.m2/repository/com/github/eirslett/pnpm
key: ${{ runner.os }}-frontend-plugin-artifacts-${{ steps.tooling-versions.outputs.node }}-${{ steps.tooling-versions.outputs.pnpm }}

0 comments on commit 8ea2480

Please sign in to comment.