Skip to content

Commit 977c508

Browse files
authored
ci: Do not fail on missing dependency cache (#13492)
This PR updates CI to never fail on cache misses. Instead, we rerun install or rebuild the tarballs, if necessary. One tricky aspect of this is that `yarn install` will fail when running on node 14, because some dependencies do not work with it. We "fix" this by temporarily installing the default node version in this case, run `yarn install`, then revert to node 14.
1 parent 14e56c7 commit 977c508

File tree

2 files changed

+79
-45
lines changed

2 files changed

+79
-45
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: "Restore dependency & build cache"
22
description: "Restore the dependency & build cache."
33

4+
inputs:
5+
dependency_cache_key:
6+
description: "The dependency cache key"
7+
required: true
8+
node_version:
9+
description: "If set, temporarily set node version to default one before installing, then revert to this version after."
10+
required: false
11+
412
runs:
513
using: "composite"
614
steps:
@@ -9,15 +17,26 @@ runs:
917
uses: actions/cache/restore@v4
1018
with:
1119
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
12-
key: ${{ env.DEPENDENCY_CACHE_KEY }}
20+
key: ${{ inputs.dependency_cache_key }}
1321

1422
- name: Restore build artifacts
1523
uses: actions/download-artifact@v4
1624
with:
1725
name: build-output
1826

19-
- name: Check if caches are restored
20-
uses: actions/github-script@v6
27+
- name: Use default node version for install
28+
if: inputs.node_version && steps.dep-cache.outputs.cache-hit != 'true'
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version-file: 'package.json'
32+
33+
- name: Install dependencies
2134
if: steps.dep-cache.outputs.cache-hit != 'true'
35+
run: yarn install --ignore-engines --frozen-lockfile
36+
shell: bash
37+
38+
- name: Revert node version to ${{ inputs.node_version }}
39+
if: inputs.node_version && steps.dep-cache.outputs.cache-hit != 'true'
40+
uses: actions/setup-node@v4
2241
with:
23-
script: core.setFailed('Dependency cache could not be restored - please re-run ALL jobs.')
42+
node-version: ${{ inputs.node_version }}

.github/workflows/build.yml

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ jobs:
233233
node-version-file: 'package.json'
234234
- name: Restore caches
235235
uses: ./.github/actions/restore-cache
236-
env:
237-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
236+
with:
237+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
238238
- name: Check bundle sizes
239239
uses: ./dev-packages/size-limit-gh-action
240240
with:
@@ -260,8 +260,8 @@ jobs:
260260
node-version-file: 'package.json'
261261
- name: Restore caches
262262
uses: ./.github/actions/restore-cache
263-
env:
264-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
263+
with:
264+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
265265
- name: Lint source files
266266
run: yarn lint:lerna
267267
- name: Lint C++ files
@@ -306,8 +306,8 @@ jobs:
306306
node-version-file: 'package.json'
307307
- name: Restore caches
308308
uses: ./.github/actions/restore-cache
309-
env:
310-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
309+
with:
310+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
311311
- name: Run madge
312312
run: yarn circularDepCheck
313313

@@ -328,8 +328,8 @@ jobs:
328328
node-version-file: 'package.json'
329329
- name: Restore caches
330330
uses: ./.github/actions/restore-cache
331-
env:
332-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
331+
with:
332+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
333333

334334
- name: Extract Profiling Node Prebuilt Binaries
335335
uses: actions/download-artifact@v4
@@ -376,8 +376,8 @@ jobs:
376376
node-version-file: 'package.json'
377377
- name: Restore caches
378378
uses: ./.github/actions/restore-cache
379-
env:
380-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
379+
with:
380+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
381381

382382
- name: Run affected tests
383383
run: yarn test:pr:browser --base=${{ github.event.pull_request.base.sha }}
@@ -413,8 +413,8 @@ jobs:
413413
uses: oven-sh/setup-bun@v2
414414
- name: Restore caches
415415
uses: ./.github/actions/restore-cache
416-
env:
417-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
416+
with:
417+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
418418
- name: Run tests
419419
run: |
420420
yarn test:ci:bun
@@ -442,8 +442,8 @@ jobs:
442442
deno-version: v1.38.5
443443
- name: Restore caches
444444
uses: ./.github/actions/restore-cache
445-
env:
446-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
445+
with:
446+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
447447
- name: Run tests
448448
run: |
449449
cd packages/deno
@@ -476,8 +476,9 @@ jobs:
476476
node-version: ${{ matrix.node }}
477477
- name: Restore caches
478478
uses: ./.github/actions/restore-cache
479-
env:
480-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
479+
with:
480+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
481+
node_version: ${{ matrix.node == 14 && '14' || '' }}
481482

482483
- name: Run affected tests
483484
run: yarn test:pr:node --base=${{ github.event.pull_request.base.sha }}
@@ -515,8 +516,8 @@ jobs:
515516
python-version: '3.11.7'
516517
- name: Restore caches
517518
uses: ./.github/actions/restore-cache
518-
env:
519-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
519+
with:
520+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
520521
- name: Build Configure node-gyp
521522
run: yarn lerna run build:bindings:configure --scope @sentry/profiling-node
522523
- name: Build Bindings for Current Environment
@@ -583,8 +584,8 @@ jobs:
583584
node-version-file: 'package.json'
584585
- name: Restore caches
585586
uses: ./.github/actions/restore-cache
586-
env:
587-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
587+
with:
588+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
588589

589590
- name: Install Playwright
590591
uses: ./.github/actions/install-playwright
@@ -635,8 +636,8 @@ jobs:
635636
node-version-file: 'package.json'
636637
- name: Restore caches
637638
uses: ./.github/actions/restore-cache
638-
env:
639-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
639+
with:
640+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
640641

641642
- name: Install Playwright
642643
uses: ./.github/actions/install-playwright
@@ -674,8 +675,8 @@ jobs:
674675
node-version-file: 'package.json'
675676
- name: Restore caches
676677
uses: ./.github/actions/restore-cache
677-
env:
678-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
678+
with:
679+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
679680
- name: Check for dts files that reference stuff in the temporary build folder
680681
run: |
681682
if grep -r --include "*.d.ts" --exclude-dir ".nxcache" 'import("@sentry(-internal)?/[^/]*/build' .; then
@@ -712,8 +713,9 @@ jobs:
712713
node-version: ${{ matrix.node }}
713714
- name: Restore caches
714715
uses: ./.github/actions/restore-cache
715-
env:
716-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
716+
with:
717+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
718+
node_version: ${{ matrix.node == 14 && '14' || '' }}
717719

718720
- name: Overwrite typescript version
719721
if: matrix.typescript
@@ -753,8 +755,8 @@ jobs:
753755
node-version: ${{ matrix.node }}
754756
- name: Restore caches
755757
uses: ./.github/actions/restore-cache
756-
env:
757-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
758+
with:
759+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
758760

759761
- name: Install Playwright
760762
uses: ./.github/actions/install-playwright
@@ -791,8 +793,8 @@ jobs:
791793
node-version-file: 'package.json'
792794
- name: Restore caches
793795
uses: ./.github/actions/restore-cache
794-
env:
795-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
796+
with:
797+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
796798
- name: NX cache
797799
uses: actions/cache/restore@v4
798800
with:
@@ -953,15 +955,19 @@ jobs:
953955
uses: oven-sh/setup-bun@v2
954956
- name: Restore caches
955957
uses: ./.github/actions/restore-cache
956-
env:
957-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
958+
with:
959+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
958960

959961
- name: Restore tarball cache
960962
uses: actions/cache/restore@v4
963+
id: restore-tarball-cache
961964
with:
962965
path: ${{ github.workspace }}/packages/*/*.tgz
963966
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
964-
fail-on-cache-miss: true
967+
968+
- name: Build tarballs if not cached
969+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
970+
run: yarn build:tarball
965971

966972
- name: Install Playwright
967973
uses: ./.github/actions/install-playwright
@@ -1053,15 +1059,19 @@ jobs:
10531059
node-version-file: 'dev-packages/e2e-tests/package.json'
10541060
- name: Restore caches
10551061
uses: ./.github/actions/restore-cache
1056-
env:
1057-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
1062+
with:
1063+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
10581064

10591065
- name: Restore tarball cache
10601066
uses: actions/cache/restore@v4
1067+
id: restore-tarball-cache
10611068
with:
10621069
path: ${{ github.workspace }}/packages/*/*.tgz
10631070
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
1064-
fail-on-cache-miss: true
1071+
1072+
- name: Build tarballs if not cached
1073+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1074+
run: yarn build:tarball
10651075

10661076
- name: Install Playwright
10671077
uses: ./.github/actions/install-playwright
@@ -1148,8 +1158,8 @@ jobs:
11481158
node-version-file: 'dev-packages/e2e-tests/package.json'
11491159
- name: Restore caches
11501160
uses: ./.github/actions/restore-cache
1151-
env:
1152-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
1161+
with:
1162+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
11531163
- name: Build Profiling Node
11541164
run: yarn lerna run build:lib --scope @sentry/profiling-node
11551165
- name: Extract Profiling Node Prebuilt Binaries
@@ -1158,12 +1168,17 @@ jobs:
11581168
pattern: profiling-node-binaries-${{ github.sha }}-*
11591169
path: ${{ github.workspace }}/packages/profiling-node/lib/
11601170
merge-multiple: true
1171+
11611172
- name: Restore tarball cache
11621173
uses: actions/cache/restore@v4
1174+
id: restore-tarball-cache
11631175
with:
11641176
path: ${{ github.workspace }}/packages/*/*.tgz
11651177
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
1166-
fail-on-cache-miss : true
1178+
1179+
- name: Build tarballs if not cached
1180+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1181+
run: yarn build:tarball
11671182

11681183
- name: Install Playwright
11691184
uses: ./.github/actions/install-playwright
@@ -1244,8 +1259,8 @@ jobs:
12441259
node-version-file: 'package.json'
12451260
- name: Restore caches
12461261
uses: ./.github/actions/restore-cache
1247-
env:
1248-
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
1262+
with:
1263+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
12491264

12501265
- name: Collect
12511266
run: yarn ci:collect

0 commit comments

Comments
 (0)