@@ -15,12 +15,16 @@ inputs:
1515 node_version :
1616 required : false
1717 default : v20.x
18+ skip-install-if-cache-hit :
19+ description : " Skip yarn install if node_modules cache is hit. Use this for jobs that only need to check that cache exists."
20+ required : false
21+ default : " false"
1822
1923runs :
2024 using : " composite"
2125 steps :
2226 - name : Use Node ${{ inputs.node_version }}
23- uses : buildjet /setup-node@v4
27+ uses : actions /setup-node@v4
2428 with :
2529 node-version : ${{ inputs.node_version }}
2630 - name : Expose yarn config as "$GITHUB_OUTPUT"
@@ -29,36 +33,86 @@ runs:
2933 run : |
3034 echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
3135
36+ # When skip-install-if-cache-hit is true, first check if all caches exist without downloading (lookup-only mode)
37+ # This avoids downloading ~1.2GB of cache data when we just want to verify caches exist
38+ - name : Check yarn cache (lookup-only)
39+ if : ${{ inputs.skip-install-if-cache-hit == 'true' }}
40+ uses : actions/cache/restore@v4
41+ id : yarn-download-cache-check
42+ with :
43+ path : ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
44+ key : yarn-download-cache-${{ hashFiles('yarn.lock') }}
45+ lookup-only : true
46+
47+ - name : Check node_modules cache (lookup-only)
48+ if : ${{ inputs.skip-install-if-cache-hit == 'true' }}
49+ uses : actions/cache/restore@v4
50+ id : yarn-nm-cache-check
51+ with :
52+ path : |
53+ **/node_modules/
54+ !**/.next/node_modules/
55+ key : ${{ runner.os }}-yarn-nm-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
56+ lookup-only : true
57+
58+ - name : Check yarn install state cache (lookup-only)
59+ if : ${{ inputs.skip-install-if-cache-hit == 'true' }}
60+ uses : actions/cache/restore@v4
61+ id : yarn-install-state-cache-check
62+ with :
63+ path : .yarn/ci-cache/
64+ key : ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
65+ lookup-only : true
66+
67+ # Compute whether all caches hit (only in skip mode)
68+ - name : Check if all caches hit
69+ if : ${{ inputs.skip-install-if-cache-hit == 'true' }}
70+ id : all-caches-check
71+ shell : bash
72+ run : |
73+ if [[ "${{ steps.yarn-download-cache-check.outputs.cache-hit }}" == "true" && \
74+ "${{ steps.yarn-nm-cache-check.outputs.cache-hit }}" == "true" && \
75+ "${{ steps.yarn-install-state-cache-check.outputs.cache-hit }}" == "true" ]]; then
76+ echo "all-hit=true" >> $GITHUB_OUTPUT
77+ else
78+ echo "all-hit=false" >> $GITHUB_OUTPUT
79+ fi
80+
3281 # Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
3382 # Yarn cache is also reusable between arch and os.
83+ # Only restore if not in skip mode, or if skip mode but any cache check missed
3484 - name : Restore yarn cache
35- uses : buildjet/cache@v4
85+ if : ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
86+ uses : actions/cache@v4
3687 id : yarn-download-cache
3788 with :
3889 path : ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
3990 key : yarn-download-cache-${{ hashFiles('yarn.lock') }}
4091
4192 # Invalidated on yarn.lock changes
4293 - name : Restore node_modules
94+ if : ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
4395 id : yarn-nm-cache
44- uses : buildjet /cache@v4
96+ uses : actions /cache@v4
4597 with :
46- path : " **/node_modules/"
98+ path : |
99+ **/node_modules/
100+ !**/.next/node_modules/
47101 key : ${{ runner.os }}-yarn-nm-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
48102
49103 # Invalidated on yarn.lock changes
50104 - name : Restore yarn install state
105+ if : ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
51106 id : yarn-install-state-cache
52- uses : buildjet /cache@v4
107+ uses : actions /cache@v4
53108 with :
54109 path : .yarn/ci-cache/
55110 key : ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
56111
57112 - name : Install dependencies
113+ if : ${{ inputs.skip-install-if-cache-hit != 'true' || steps.all-caches-check.outputs.all-hit != 'true' }}
58114 shell : bash
59- run : |
60- yarn install --inline-builds
61- yarn prisma generate
115+ run : yarn install --inline-builds
62116 env :
63117 # CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
64118 YARN_ENABLE_IMMUTABLE_INSTALLS : " false" # So it doesn't try to remove our private submodule deps
0 commit comments