Skip to content

Commit 068887d

Browse files
authored
CI caching (#5222)
* Attempt to warmpup sharp * Fix run all dispatch * Remove debug output * Optimize docker cache restoring - skip when not needed in the testing job * Improve warmup debug
1 parent c55198a commit 068887d

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

.github/workflows/monorepo.yml

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ jobs:
3636
# BASE_SHA narrows the diff to the merge-base (PR) or latest push SHA for branch builds.
3737
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before || '' }}
3838
# FORCE_ALL flips to true when the workflow_dispatch input is toggled so every package runs.
39-
FORCE_ALL: ${{ (github.event_name == 'schedule' || inputs.run_all == 'true') && 'true' || 'false' }}
39+
FORCE_ALL: ${{ (github.event_name == 'schedule' || inputs.run_all == true || inputs.run_all == 'true') && 'true' || 'false' }}
4040
outputs:
4141
matrix: ${{ steps.impact.outputs.matrix }}
4242
runtime-matrix: ${{ steps.runtime-matrix.outputs.runtime_matrix }}
43+
node-versions: ${{ steps.node-versions.outputs.node_versions }}
4344
has-packages: ${{ steps.impact.outputs.has_packages }}
4445
steps:
4546
- name: Git checkout
@@ -71,6 +72,10 @@ jobs:
7172
matrix_json=${matrix_json//$'\r'/'%0D'}
7273
echo "runtime_matrix=$matrix_json" >> "$GITHUB_OUTPUT"
7374
75+
- name: Export node versions
76+
id: node-versions
77+
run: echo "node_versions=${{ env.NODE_VERSIONS_JSON }}" >> "$GITHUB_OUTPUT"
78+
7479
shared-runtime:
7580
name: Shared runtime
7681
runs-on: ubuntu-latest
@@ -139,11 +144,74 @@ jobs:
139144
docker pull "redis:${{ env.REDIS_VERSION }}"
140145
docker save "redis:${{ env.REDIS_VERSION }}" -o ".github/docker-cache/redis-${{ env.REDIS_VERSION }}.tar"
141146
147+
warm-sharp-cache:
148+
name: Warm sharp/libvips cache (Node ${{ matrix.nodeVersion }})
149+
runs-on: ubuntu-latest
150+
needs:
151+
- setup
152+
- shared-runtime
153+
if: needs.setup.outputs.has-packages == 'true'
154+
strategy:
155+
fail-fast: false
156+
matrix:
157+
nodeVersion: ${{ fromJson(needs.setup.outputs['node-versions']) }}
158+
steps:
159+
- name: Git checkout
160+
uses: actions/checkout@v5
161+
with:
162+
fetch-depth: 0
163+
164+
- name: Download pnpm lockfile
165+
uses: actions/download-artifact@v4
166+
with:
167+
name: pnpm-lock
168+
path: .
169+
170+
- name: Install pnpm
171+
uses: pnpm/action-setup@v4
172+
with:
173+
version: 10.18.0
174+
175+
- name: Use Node.js ${{ matrix.nodeVersion }}
176+
uses: actions/setup-node@v4
177+
with:
178+
node-version: ${{ matrix.nodeVersion }}
179+
cache: pnpm
180+
cache-dependency-path: pnpm-lock.yaml
181+
182+
- name: Grant private repositories access
183+
uses: webfactory/ssh-agent@v0.9.0
184+
with:
185+
ssh-private-key: |
186+
${{ secrets.AUTOMATIC_TRANSLATION_DEPLOYMENT_KEY }}
187+
188+
- name: Cache sharp/libvips downloads
189+
id: sharp-cache
190+
uses: actions/cache@v4
191+
with:
192+
path: |
193+
~/.npm/_libvips
194+
key: sharp-libvips-${{ runner.os }}-node${{ matrix.nodeVersion }}-${{ hashFiles('pnpm-lock.yaml') }}
195+
restore-keys: |
196+
sharp-libvips-${{ runner.os }}-node${{ matrix.nodeVersion }}-
197+
sharp-libvips-${{ runner.os }}-
198+
199+
- name: Warm cache by installing dependencies once
200+
run: pnpm install --frozen-lockfile
201+
202+
- name: Debug sharp/libvips cache contents
203+
if: always()
204+
run: |
205+
echo "-- ~/.npm/_libvips"
206+
ls -alh ~/.npm/_libvips || true
207+
du -sh ~/.npm/_libvips || true
208+
142209
package-tests:
143210
name: ${{ format('{0} ({1}, {2})', matrix.package, matrix.nodeVersion, matrix.needsMongo && matrix.mongodbVersion || 'n/a') }}
144211
needs:
145212
- setup
146213
- shared-runtime
214+
- warm-sharp-cache
147215
if: needs.setup.outputs.has-packages == 'true'
148216
runs-on: ubuntu-latest
149217
strategy:
@@ -173,6 +241,17 @@ jobs:
173241
cache: pnpm
174242
cache-dependency-path: pnpm-lock.yaml
175243

244+
- name: Cache sharp/libvips downloads
245+
id: sharp-cache
246+
uses: actions/cache@v4
247+
with:
248+
path: |
249+
~/.npm/_libvips
250+
key: sharp-libvips-${{ runner.os }}-node${{ matrix.nodeVersion }}-${{ hashFiles('pnpm-lock.yaml') }}
251+
restore-keys: |
252+
sharp-libvips-${{ runner.os }}-node${{ matrix.nodeVersion }}-
253+
sharp-libvips-${{ runner.os }}-
254+
176255
- name: Grant private repositories access
177256
uses: webfactory/ssh-agent@v0.9.0
178257
with:
@@ -182,6 +261,7 @@ jobs:
182261
- name: Restore docker image cache
183262
id: docker-cache-restore
184263
uses: actions/cache/restore@v4
264+
if: matrix.needsMongo || matrix.needsRedis
185265
with:
186266
path: .github/docker-cache
187267
key: ${{ needs.shared-runtime.outputs.docker-cache-key }}

0 commit comments

Comments
 (0)