From b44aee7535482d10d170b4fba0c08d5f832bbf03 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 6 Nov 2024 08:25:49 +0100 Subject: [PATCH] Use a weekly cache key for PNPM store (#34656) Closes #34655 Signed-off-by: Jon Koops --- .github/actions/build-keycloak/action.yml | 6 ++-- .github/actions/cypress-cache/action.yml | 20 ++++++++++++ .../actions/frontend-plugin-cache/action.yml | 21 ------------- .../actions/integration-test-setup/action.yml | 6 ++-- .github/actions/pnpm-setup/action.yml | 31 +++++++------------ .github/actions/pnpm-store-cache/action.yml | 20 ++++++++++++ .github/actions/unit-test-setup/action.yml | 4 +-- 7 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 .github/actions/cypress-cache/action.yml delete mode 100644 .github/actions/frontend-plugin-cache/action.yml create mode 100644 .github/actions/pnpm-store-cache/action.yml diff --git a/.github/actions/build-keycloak/action.yml b/.github/actions/build-keycloak/action.yml index 6b0e90ab64..0e59b1b039 100644 --- a/.github/actions/build-keycloak/action.yml +++ b/.github/actions/build-keycloak/action.yml @@ -24,9 +24,9 @@ runs: with: create-cache-if-it-doesnt-exist: true - - id: frontend-plugin-cache - name: Frontend Plugin Cache - uses: ./.github/actions/frontend-plugin-cache + - id: pnpm-store-cache + name: PNPM store cache + uses: ./.github/actions/pnpm-store-cache - id: build-keycloak name: Build Keycloak diff --git a/.github/actions/cypress-cache/action.yml b/.github/actions/cypress-cache/action.yml new file mode 100644 index 0000000000..994192cfb0 --- /dev/null +++ b/.github/actions/cypress-cache/action.yml @@ -0,0 +1,20 @@ +name: Cache Cypress +description: Caches Cypress binary to speed up the build. + +runs: + using: composite + steps: + - id: cache-key + name: Cache key based on Cypress version + shell: bash + run: echo "key=cypress-binary-$(jq -r '.devDependencies.cypress' js/apps/admin-ui/package.json)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + name: Cache Cypress binary + with: + # See: https://docs.cypress.io/app/references/advanced-installation#Binary-cache + path: | + ~/.cache/Cypress + /AppData/Local/Cypress/Cache + ~/Library/Caches/Cypress + key: ${{ runner.os }}-${{ steps.cache-key.outputs.key }} diff --git a/.github/actions/frontend-plugin-cache/action.yml b/.github/actions/frontend-plugin-cache/action.yml deleted file mode 100644 index 562a65a0b4..0000000000 --- a/.github/actions/frontend-plugin-cache/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Frontend Plugin Cache -description: Caches NPM dependencies for the frontend-maven-plugin to speed up builds - -runs: - using: composite - steps: - - name: Get PNPM version - id: pnpm-version - shell: bash - run: | - echo "version=$(./mvnw help:evaluate -Dexpression=pnpm.version -q -DforceStdout)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - name: Cache PNPM store - with: - # See: https://pnpm.io/npmrc#store-dir - path: | - ~/.local/share/pnpm/store - ~/AppData/Local/pnpm/store - ~/Library/pnpm/store - key: ${{ runner.os }}-frontend-plugin-pnpm-store-${{ steps.pnpm-version.outputs.version }}-${{ hashFiles('pnpm-lock.yaml') }} diff --git a/.github/actions/integration-test-setup/action.yml b/.github/actions/integration-test-setup/action.yml index ec5a9b8723..4ec5a39f9c 100644 --- a/.github/actions/integration-test-setup/action.yml +++ b/.github/actions/integration-test-setup/action.yml @@ -25,9 +25,9 @@ runs: name: Maven cache uses: ./.github/actions/maven-cache - - id: frontend-plugin-cache - name: Frontend Plugin Cache - uses: ./.github/actions/frontend-plugin-cache + - id: pnpm-store-cache + name: PNPM store cache + uses: ./.github/actions/pnpm-store-cache - id: download-keycloak name: Download Keycloak Maven artifacts diff --git a/.github/actions/pnpm-setup/action.yml b/.github/actions/pnpm-setup/action.yml index 5a0188eb69..205ee0cb95 100644 --- a/.github/actions/pnpm-setup/action.yml +++ b/.github/actions/pnpm-setup/action.yml @@ -20,26 +20,19 @@ runs: shell: bash run: corepack enable - - name: Get PNPM store directory - id: pnpm-cache - shell: bash - run: | - echo "store-path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT + - name: PNPM store cache + uses: ./.github/actions/pnpm-store-cache - - uses: actions/cache@v4 - name: Setup PNPM cache - with: - # Also cache Cypress binary. - path: | - ~/.cache/Cypress - ${{ steps.pnpm-cache.outputs.store-path }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- + - name: Cypress binary cache + uses: ./.github/actions/cypress-cache - name: Install dependencies shell: bash - # Run the store prune after the installation to avoid having caches which grow over time - run: | - pnpm install --prefer-offline --frozen-lockfile - pnpm store prune + run: pnpm install --prefer-offline --frozen-lockfile + + # This step is only needed to ensure that the Cypress binary is installed. + # If the binary was retrieved from the cache, this step is a no-op. + - name: Install Cypress dependencies + shell: bash + working-directory: js/apps/admin-ui + run: pnpm exec cypress install diff --git a/.github/actions/pnpm-store-cache/action.yml b/.github/actions/pnpm-store-cache/action.yml new file mode 100644 index 0000000000..3929d4824e --- /dev/null +++ b/.github/actions/pnpm-store-cache/action.yml @@ -0,0 +1,20 @@ +name: Cache PNPM store +description: Caches the PNPM store to speed up the build. + +runs: + using: composite + steps: + - id: weekly-cache-key + name: Key for weekly rotation of cache + shell: bash + run: echo "key=pnpm-store-`date -u "+%Y-%U"`" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + name: Cache PNPM store + with: + # See: https://pnpm.io/npmrc#store-dir + path: | + ~/.local/share/pnpm/store + ~/AppData/Local/pnpm/store + ~/Library/pnpm/store + key: ${{ runner.os }}-${{ steps.weekly-cache-key.outputs.key }} diff --git a/.github/actions/unit-test-setup/action.yml b/.github/actions/unit-test-setup/action.yml index e18b0cbaaa..f03eb91fe7 100644 --- a/.github/actions/unit-test-setup/action.yml +++ b/.github/actions/unit-test-setup/action.yml @@ -11,6 +11,6 @@ runs: name: Maven cache uses: ./.github/actions/maven-cache - - id: frontend-plugin-cache + - id: pnpm-store-cache name: Frontend Plugin Cache - uses: ./.github/actions/frontend-plugin-cache + uses: ./.github/actions/pnpm-store-cache