Skip to content

Scheduling infrastructure for absolutely everyone.

chore: use lookup-only cache check to skip deps job downloads (#26314)

Keith Williams1dbbc934ccdc
diff --git a/.github/actions/yarn-install/action.yml b/.github/actions/yarn-install/action.yml
index c48a484f0f0..a930ce326d3 100644
--- a/.github/actions/yarn-install/action.yml
+++ b/.github/actions/yarn-install/action.yml
@@ -15,6 +15,10 @@ inputs:
node_version:
required: false
default: v20.x
+ skip-install-if-cache-hit:
+ description: "Skip yarn install if node_modules cache is hit. Use this for jobs that only need to check that cache exists."
+ required: false
+ default: "false"
runs:
using: "composite"
@@ -29,9 +33,56 @@ runs:
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
+ # When skip-install-if-cache-hit is true, first check if all caches exist without downloading (lookup-only mode)
+ # This avoids downloading ~1.2GB of cache data when we just want to verify caches exist
+ - name: Check yarn cache (lookup-only)
+ if: ${{ inputs.skip-install-if-cache-hit == 'true' }}
+ uses: actions/cache/restore@v4
+ id: yarn-download-cache-check
+ with:
+ path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
+ key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
+ lookup-only: true
+
+ - name: Check node_modules cache (lookup-only)
+ if: ${{ inputs.skip-install-if-cache-hit == 'true' }}
+ uses: actions/cache/restore@v4
+ id: yarn-nm-cache-check
+ with:
+ path: |
+ **/node_modules/
+ !**/.next/node_modules/
+ key: ${{ runner.os }}-yarn-nm-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
+ lookup-only: true
+
+ - name: Check yarn install state cache (lookup-only)
+ if: ${{ inputs.skip-install-if-cache-hit == 'true' }}
+ uses: actions/cache/restore@v4
+ id: yarn-install-state-cache-check
+ with:
+ path: .yarn/ci-cache/
+ key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
+ lookup-only: true
+
+ # Compute whether all caches hit (only in skip mode)
+ - name: Check if all caches hit
+ if: ${{ inputs.skip-install-if-cache-hit == 'true' }}
+ id: all-caches-check
+ shell: bash
+ run: |
+ if [[ "${{ steps.yarn-download-cache-check.outputs.cache-hit }}" == "true" && \
+ "${{ steps.yarn-nm-cache-check.outputs.cache-hit }}" == "true" && \
+ "${{ steps.yarn-install-state-cache-check.outputs.cache-hit }}" == "true" ]]; then
+ echo "all-hit=true" >> $GITHUB_OUTPUT
+ else
+ echo "all-hit=false" >> $GITHUB_OUTPUT
+ fi
+
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
# Yarn cache is also reusable between arch and os.
+ # Only restore if not in skip mode, or if skip mode but any cache check missed
- name: Restore yarn cache
+ if: ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
uses: actions/cache@v4
id: yarn-download-cache
with:
@@ -40,6 +91,7 @@ runs:
# Invalidated on yarn.lock changes
- name: Restore node_modules
+ if: ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
id: yarn-nm-cache
uses: actions/cache@v4
with:
@@ -50,6 +102,7 @@ runs:
# Invalidated on yarn.lock changes
- name: Restore yarn install state
+ if: ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
id: yarn-install-state-cache
uses: actions/cache@v4
with:
@@ -57,6 +110,7 @@ runs:
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
- name: Install dependencies
+ if: ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
shell: bash
run: |
yarn install --inline-builds
diff --git a/.github/actions/yarn-playwright-install/action.yml b/.github/actions/yarn-playwright-install/action.yml
index 7d444283c1f..ea3ae0469b8 100644
--- a/.github/actions/yarn-playwright-install/action.yml
+++ b/.github/actions/yarn-playwright-install/action.yml
@@ -1,5 +1,10 @@
name: Install playwright binaries
description: "Install playwright, cache and restore if necessary"
+inputs:
+ skip-install-if-cache-hit:
+ description: "Skip playwright install if cache is hit. Use this for jobs that only need to check that cache exists."
+ required: false
+ default: "false"
runs:
using: "composite"
steps:
@@ -7,7 +12,23 @@ runs:
shell: bash
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package.json').devDependencies['@playwright/test'])")" >> $GITHUB_ENV
+
+ # When skip-install-if-cache-hit is true, first check if cache exists without downloading (lookup-only mode)
+ - name: Check playwright cache (lookup-only)
+ if: ${{ inputs.skip-install-if-cache-hit == 'true' }}
+ id: playwright-cache-check
+ uses: actions/cache/restore@v4
+ with:
+ path: |
+ ~/Library/Caches/ms-playwright
+ ~/.cache/ms-playwright
+ ${{ github.workspace }}/node_modules/playwright
+ key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
+ lookup-only: true
+
+ # Only restore cache if not in skip mode, or if skip mode but cache check missed
- name: Cache playwright binaries
+ if: ${{ inputs.skip-install-if-cache-hit != 'true' || steps.playwright-cache-check.outputs.cache-hit != 'true' }}
id: playwright-cache
uses: actions/cache@v4
with:
@@ -16,7 +37,10 @@ runs:
~/.cache/ms-playwright
${{ github.workspace }}/node_modules/playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
+
+ # In default mode: run if playwright-cache missed
+ # In skip mode: run if playwright-cache-check missed (but cache restore step was also skipped)
- name: Yarn playwright install
- if: steps.playwright-cache.outputs.cache-hit != 'true'
+ if: ${{ (inputs.skip-install-if-cache-hit != 'true' && steps.playwright-cache.outputs.cache-hit != 'true') || (inputs.skip-install-if-cache-hit == 'true' && steps.playwright-cache-check.outputs.cache-hit != 'true') }}
shell: bash
run: yarn playwright install --with-deps
diff --git a/.github/workflows/yarn-install.yml b/.github/workflows/yarn-install.yml
index 81eb75d6304..e9e4c6ca593 100644
--- a/.github/workflows/yarn-install.yml
+++ b/.github/workflows/yarn-install.yml
@@ -15,4 +15,8 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout
- uses: ./.github/actions/yarn-install
+ with:
+ skip-install-if-cache-hit: "true"
- uses: ./.github/actions/yarn-playwright-install
+ with:
+ skip-install-if-cache-hit: "true"