From 03ad41f1294a9829656ec7c1d5aca5bb70fd2636 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Thu, 1 Aug 2024 14:30:58 +0200 Subject: [PATCH] Cache node binary for Windows to avoid download failures Closes #31835 Signed-off-by: Alexander Schwartz --- .../actions/integration-test-setup/action.yml | 3 ++- .github/actions/maven-cache/action.yml | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/actions/integration-test-setup/action.yml b/.github/actions/integration-test-setup/action.yml index d777e68bd874..ec5a9b8723d8 100644 --- a/.github/actions/integration-test-setup/action.yml +++ b/.github/actions/integration-test-setup/action.yml @@ -40,6 +40,7 @@ runs: shell: bash run: | if [ "$RUNNER_OS" == "Windows" ]; then - choco install zstandard + # zstd binary might be missing in older versions, install only when necessary + which zstd > /dev/null || choco install zstandard fi tar -C ~/ --use-compress-program="zstd -d" -xf m2-keycloak.tzts diff --git a/.github/actions/maven-cache/action.yml b/.github/actions/maven-cache/action.yml index b131eaba52fc..a4f1ffedb25d 100644 --- a/.github/actions/maven-cache/action.yml +++ b/.github/actions/maven-cache/action.yml @@ -28,18 +28,40 @@ runs: ~/.m2/repository/*/* !~/.m2/repository/org/keycloak 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' + # The cache restore in the next step uses the relative path which was valid on Linux and that is part of the archive it downloads. + # You'll see that path when you enable debugging for the GitHub workflow on Windows. + # On Windows, the .m2 folder is in different location, so move all the contents to the right folder here. + # Also, not using the C: drive will speed up the build, see https://github.com/actions/runner-images/issues/8755 + run: | + mkdir -p ../../../.m2/repository + cmd /c mklink /d $HOME\.m2\repository D:\.m2\repository - id: restore-maven-repository name: Maven cache uses: actions/cache/restore@v4 if: inputs.create-cache-if-it-doesnt-exist == 'false' with: - # Two asterisks are needed to make the follow-up exclusion work - # see https://github.com/actions/toolkit/issues/713 for the upstream issue + # This needs to repeat the same path pattern as above to find the matching cache path: | ~/.m2/repository/*/* !~/.m2/repository/org/keycloak key: ${{ steps.weekly-cache-key.outputs.key }} + enableCrossOsArchive: true - name: Cache Maven Wrapper uses: actions/cache@v4