Skip to content

Commit 61d22c2

Browse files
committed
ci: Better error handling when caches can't be restored
1 parent 70abc37 commit 61d22c2

File tree

2 files changed

+89
-151
lines changed

2 files changed

+89
-151
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Restore dependency & build cache"
2+
description: "Restore the dependency & build cache."
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Check dependency cache
8+
id: dep-cache
9+
uses: actions/cache/restore@v3
10+
with:
11+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
12+
key: ${{ env.DEPENDENCY_CACHE_KEY }}
13+
14+
- name: Check build cache
15+
uses: actions/cache/restore@v3
16+
id: build-cache
17+
with:
18+
path: ${{ env.CACHED_BUILD_PATHS }}
19+
key: ${{ env.BUILD_CACHE_KEY }}
20+
21+
- name: Check if caches are restored
22+
uses: actions/github-script@v6
23+
if: steps.dep-cache.outputs.cache-hit != 'true' || steps.build-cache.outputs.cache-hit != 'true'
24+
with:
25+
script: core.setFailed('Dependency or build cache could not be restored - please re-run ALL jobs.')

.github/workflows/build.yml

Lines changed: 64 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ jobs:
192192
ref: ${{ env.HEAD_COMMIT }}
193193
- name: Set up Node
194194
uses: volta-cli/action@v4
195+
195196
- name: Check dependency cache
196-
uses: actions/cache@v3
197+
uses: actions/cache/restore@v3
197198
with:
198199
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
199200
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
201+
fail-on-cache-miss: true
200202

201203
- name: Check build cache
202204
uses: actions/cache@v3
@@ -245,16 +247,11 @@ jobs:
245247
ref: ${{ env.HEAD_COMMIT }}
246248
- name: Set up Node
247249
uses: volta-cli/action@v4
248-
- name: Check dependency cache
249-
uses: actions/cache/restore@v3
250-
with:
251-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
252-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
253-
- name: Check build cache
254-
uses: actions/cache/restore@v3
255-
with:
256-
path: ${{ env.CACHED_BUILD_PATHS }}
257-
key: ${{ env.BUILD_CACHE_KEY }}
250+
- name: Restore caches
251+
uses: ./.github/actions/restore-cache
252+
env:
253+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
254+
258255
- name: Get SDK version
259256
# `jq` reads JSON files, and `tee` pipes its input to the given location and to stdout. (Adding `-a` is the
260257
# equivalent of using >> rather than >.)
@@ -289,16 +286,10 @@ jobs:
289286
# The size limit action runs `yarn` and `yarn build` when this job is executed on
290287
# use Node 14 for now.
291288
node-version: '14'
292-
- name: Check dependency cache
293-
uses: actions/cache/restore@v3
294-
with:
295-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
296-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
297-
- name: Check build cache
298-
uses: actions/cache/restore@v3
299-
with:
300-
path: ${{ env.CACHED_BUILD_PATHS }}
301-
key: ${{ env.BUILD_CACHE_KEY }}
289+
- name: Restore caches
290+
uses: ./.github/actions/restore-cache
291+
env:
292+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
302293
- name: Check bundle sizes
303294
uses: getsentry/size-limit-action@runForBranch
304295
with:
@@ -323,16 +314,10 @@ jobs:
323314
ref: ${{ env.HEAD_COMMIT }}
324315
- name: Set up Node
325316
uses: volta-cli/action@v4
326-
- name: Check dependency cache
327-
uses: actions/cache/restore@v3
328-
with:
329-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
330-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
331-
- name: Check build cache
332-
uses: actions/cache/restore@v3
333-
with:
334-
path: ${{ env.CACHED_BUILD_PATHS }}
335-
key: ${{ env.BUILD_CACHE_KEY }}
317+
- name: Restore caches
318+
uses: ./.github/actions/restore-cache
319+
env:
320+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
336321
- name: Run linter
337322
run: yarn lint
338323

@@ -348,16 +333,10 @@ jobs:
348333
ref: ${{ env.HEAD_COMMIT }}
349334
- name: Set up Node
350335
uses: volta-cli/action@v4
351-
- name: Check dependency cache
352-
uses: actions/cache/restore@v3
353-
with:
354-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
355-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
356-
- name: Check build cache
357-
uses: actions/cache/restore@v3
358-
with:
359-
path: ${{ env.CACHED_BUILD_PATHS }}
360-
key: ${{ env.BUILD_CACHE_KEY }}
336+
- name: Restore caches
337+
uses: ./.github/actions/restore-cache
338+
env:
339+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
361340
- name: Run madge
362341
run: yarn circularDepCheck
363342

@@ -374,16 +353,10 @@ jobs:
374353
ref: ${{ env.HEAD_COMMIT }}
375354
- name: Set up Node
376355
uses: volta-cli/action@v4
377-
- name: Check dependency cache
378-
uses: actions/cache/restore@v3
379-
with:
380-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
381-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
382-
- name: Check build cache
383-
uses: actions/cache/restore@v3
384-
with:
385-
path: ${{ env.CACHED_BUILD_PATHS }}
386-
key: ${{ env.BUILD_CACHE_KEY }}
356+
- name: Restore caches
357+
uses: ./.github/actions/restore-cache
358+
env:
359+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
387360
- name: Pack
388361
run: yarn build:tarball
389362
- name: Archive artifacts
@@ -411,16 +384,10 @@ jobs:
411384
uses: actions/setup-node@v3
412385
with:
413386
node-version: ${{ env.DEFAULT_NODE_VERSION }}
414-
- name: Check dependency cache
415-
uses: actions/cache/restore@v3
416-
with:
417-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
418-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
419-
- name: Check build cache
420-
uses: actions/cache/restore@v3
421-
with:
422-
path: ${{ env.CACHED_BUILD_PATHS }}
423-
key: ${{ env.BUILD_CACHE_KEY }}
387+
- name: Restore caches
388+
uses: ./.github/actions/restore-cache
389+
env:
390+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
424391
- name: Run tests
425392
env:
426393
NODE_VERSION: 16
@@ -446,16 +413,10 @@ jobs:
446413
uses: actions/setup-node@v3
447414
with:
448415
node-version: ${{ matrix.node }}
449-
- name: Check dependency cache
450-
uses: actions/cache/restore@v3
451-
with:
452-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
453-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
454-
- name: Check build cache
455-
uses: actions/cache/restore@v3
456-
with:
457-
path: ${{ env.CACHED_BUILD_PATHS }}
458-
key: ${{ env.BUILD_CACHE_KEY }}
416+
- name: Restore caches
417+
uses: ./.github/actions/restore-cache
418+
env:
419+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
459420
- name: Run tests
460421
env:
461422
NODE_VERSION: ${{ matrix.node }}
@@ -484,16 +445,10 @@ jobs:
484445
uses: actions/setup-node@v3
485446
with:
486447
node-version: ${{ matrix.node }}
487-
- name: Check dependency cache
488-
uses: actions/cache/restore@v3
489-
with:
490-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
491-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
492-
- name: Check build cache
493-
uses: actions/cache/restore@v3
494-
with:
495-
path: ${{ env.CACHED_BUILD_PATHS }}
496-
key: ${{ env.BUILD_CACHE_KEY }}
448+
- name: Restore caches
449+
uses: ./.github/actions/restore-cache
450+
env:
451+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
497452
- name: Get npm cache directory
498453
id: npm-cache-dir
499454
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
@@ -558,16 +513,10 @@ jobs:
558513
ref: ${{ env.HEAD_COMMIT }}
559514
- name: Set up Node
560515
uses: volta-cli/action@v4
561-
- name: Check dependency cache
562-
uses: actions/cache/restore@v3
563-
with:
564-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
565-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
566-
- name: Check build cache
567-
uses: actions/cache/restore@v3
568-
with:
569-
path: ${{ env.CACHED_BUILD_PATHS }}
570-
key: ${{ env.BUILD_CACHE_KEY }}
516+
- name: Restore caches
517+
uses: ./.github/actions/restore-cache
518+
env:
519+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
571520
- name: Get npm cache directory
572521
id: npm-cache-dir
573522
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
@@ -616,16 +565,10 @@ jobs:
616565
ref: ${{ env.HEAD_COMMIT }}
617566
- name: Set up Node
618567
uses: volta-cli/action@v4
619-
- name: Check dependency cache
620-
uses: actions/cache/restore@v3
621-
with:
622-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
623-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
624-
- name: Check build cache
625-
uses: actions/cache/restore@v3
626-
with:
627-
path: ${{ env.CACHED_BUILD_PATHS }}
628-
key: ${{ env.BUILD_CACHE_KEY }}
568+
- name: Restore caches
569+
uses: ./.github/actions/restore-cache
570+
env:
571+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
629572
- name: Run integration tests
630573
env:
631574
KARMA_BROWSER: ${{ matrix.browser }}
@@ -646,16 +589,10 @@ jobs:
646589
ref: ${{ env.HEAD_COMMIT }}
647590
- name: Set up Node
648591
uses: volta-cli/action@v4
649-
- name: Check dependency cache
650-
uses: actions/cache/restore@v3
651-
with:
652-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
653-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
654-
- name: Check build cache
655-
uses: actions/cache/restore@v3
656-
with:
657-
path: ${{ env.CACHED_BUILD_PATHS }}
658-
key: ${{ env.BUILD_CACHE_KEY }}
592+
- name: Restore caches
593+
uses: ./.github/actions/restore-cache
594+
env:
595+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
659596
- name: Run browser build tests
660597
run: |
661598
cd packages/browser
@@ -684,16 +621,10 @@ jobs:
684621
uses: actions/setup-node@v3
685622
with:
686623
node-version: ${{ matrix.node }}
687-
- name: Check dependency cache
688-
uses: actions/cache/restore@v3
689-
with:
690-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
691-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
692-
- name: Check build cache
693-
uses: actions/cache/restore@v3
694-
with:
695-
path: ${{ env.CACHED_BUILD_PATHS }}
696-
key: ${{ env.BUILD_CACHE_KEY }}
624+
- name: Restore caches
625+
uses: ./.github/actions/restore-cache
626+
env:
627+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
697628
- name: Run integration tests
698629
env:
699630
NODE_VERSION: ${{ matrix.node }}
@@ -720,16 +651,10 @@ jobs:
720651
uses: actions/setup-node@v3
721652
with:
722653
node-version: ${{ matrix.node }}
723-
- name: Check dependency cache
724-
uses: actions/cache/restore@v3
725-
with:
726-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
727-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
728-
- name: Check build cache
729-
uses: actions/cache/restore@v3
730-
with:
731-
path: ${{ env.CACHED_BUILD_PATHS }}
732-
key: ${{ env.BUILD_CACHE_KEY }}
654+
- name: Restore caches
655+
uses: ./.github/actions/restore-cache
656+
env:
657+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
733658
- name: Run integration tests
734659
env:
735660
NODE_VERSION: ${{ matrix.node }}
@@ -754,16 +679,10 @@ jobs:
754679
ref: ${{ env.HEAD_COMMIT }}
755680
- name: Set up Node
756681
uses: volta-cli/action@v4
757-
- name: Check dependency cache
758-
uses: actions/cache/restore@v3
759-
with:
760-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
761-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
762-
- name: Check build cache
763-
uses: actions/cache/restore@v3
764-
with:
765-
path: ${{ env.CACHED_BUILD_PATHS }}
766-
key: ${{ env.BUILD_CACHE_KEY }}
682+
- name: Restore caches
683+
uses: ./.github/actions/restore-cache
684+
env:
685+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
767686
- name: Get node version
768687
id: versions
769688
run: |
@@ -817,16 +736,10 @@ jobs:
817736
ref: ${{ env.HEAD_COMMIT }}
818737
- name: Set up Node
819738
uses: volta-cli/action@v4
820-
- name: Check dependency cache
821-
uses: actions/cache/restore@v3
822-
with:
823-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
824-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
825-
- name: Check build cache
826-
uses: actions/cache/restore@v3
827-
with:
828-
path: ${{ env.CACHED_BUILD_PATHS }}
829-
key: ${{ env.BUILD_CACHE_KEY }}
739+
- name: Restore caches
740+
uses: ./.github/actions/restore-cache
741+
env:
742+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
830743

831744
- name: Collect
832745
run: yarn ci:collect

0 commit comments

Comments
 (0)