Commit d1837ad
authored
ci: make build cache restore resilient to eviction (#16275)
# Overview
Downstream CI jobs fail when re-running individual jobs after the build
cache has been evicted from GitHub's 10GB repo-wide LRU cache. For
example, [this
run](https://github.com/payloadcms/payload/actions/runs/24259697364/job/71108809903?pr=15268#step:5:22)
had 4 jobs fail at "Restore build" because the cache was evicted ~43
hours after the original build.
## Time Savings
This replaces the fixed 120s `sleep` propagation delay and hard-failing
`fail-on-cache-miss: true` with a polling + fallback approach that
self-heals on cache miss. **This change will save 2 mins per run.**
## Key Changes
- **New `restore-build` input on the setup action**
- When `true`, the action polls for the build cache using `gh cache
list` (10s intervals, 120s timeout), restores it if found, or falls back
to `pnpm install && pnpm run build:all` if not. This replaces
`pnpm-run-install: false`, `pnpm-restore-cache: false`,
`cache-propagation-delay: 120`, and the separate `Restore build` step
that every downstream job previously had.
- **Simplified downstream jobs**
- All 8 downstream jobs (`tests-unit`, `tests-types`, `tests-int`,
`e2e-prep`, `tests-e2e`, `build-and-test-templates`,
`tests-type-generation`, `analyze`) go from ~10 lines of setup + cache
restore boilerplate to `restore-build: true`.
- **Removed `cache-propagation-delay` input**
- The fixed 120s sleep is no longer needed. Polling finds the cache as
soon as it's available (typically instantly), and fallback handles the
miss case.
## Design Decisions
**Polling over fixed sleep:** The old 120s delay was wasted time on the
happy path (propagation is effectively instant) and didn't help when the
cache was evicted entirely. Polling with `gh cache list` finds the cache
as soon as it propagates, and the timeout triggers a fallback build
instead of a hard failure.
**`gh cache list` over `actions/cache/restore` with `lookup-only`:**
`lookup-only` is a step-level action that can't be called in a bash
loop. `gh cache list` is a CLI command available on all runners, works
in a loop, and requires no extra extensions. Uses exact key match via jq
filter to avoid prefix-match false positives.
**Fallback builds with warm pnpm store:** The pnpm store cache is
restored regardless of `restore-build` mode, so if the fallback build
triggers, `pnpm install` has a warm store rather than starting cold.
**Error handling:** If `gh cache list` fails (rate limit, auth,
network), the loop breaks immediately and falls back to a full build
rather than silently polling for 120s.
## Overall Flow
```mermaid
sequenceDiagram
participant B as Build Job
participant C as GitHub Cache
participant D as Downstream Job
participant S as Setup Action
B->>C: Save build cache (key: SHA)
D->>S: restore-build: true
S->>S: Restore pnpm store cache
loop Every 10s (up to 120s)
S->>C: gh cache list (exact key match)
C-->>S: Found / Not found
end
alt Cache found
S->>C: actions/cache/restore
C-->>S: Build artifacts
else Cache not found (evicted or timeout)
S->>S: pnpm install && pnpm run build:all
end
```
## References / Links
- [actions/cache#1710](actions/cache#1710) —
original cache propagation delay issue
- [gh cache list docs](https://cli.github.com/manual/gh_cache_list)
- [actions/cache/restore
README](https://github.com/actions/cache/blob/main/restore/README.md)1 parent 1e1c591 commit d1837ad
2 files changed
Lines changed: 62 additions & 89 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | | - | |
120 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 106 | + | |
116 | 107 | | |
117 | 108 | | |
118 | 109 | | |
| |||
129 | 120 | | |
130 | 121 | | |
131 | 122 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 123 | + | |
142 | 124 | | |
143 | 125 | | |
144 | 126 | | |
| |||
198 | 180 | | |
199 | 181 | | |
200 | 182 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 183 | + | |
211 | 184 | | |
212 | 185 | | |
213 | 186 | | |
| |||
266 | 239 | | |
267 | 240 | | |
268 | 241 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 242 | + | |
279 | 243 | | |
280 | 244 | | |
281 | 245 | | |
| |||
307 | 271 | | |
308 | 272 | | |
309 | 273 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
| 274 | + | |
320 | 275 | | |
321 | 276 | | |
322 | 277 | | |
| |||
447 | 402 | | |
448 | 403 | | |
449 | 404 | | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
| 405 | + | |
460 | 406 | | |
461 | 407 | | |
462 | 408 | | |
| |||
522 | 468 | | |
523 | 469 | | |
524 | 470 | | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
| 471 | + | |
535 | 472 | | |
536 | 473 | | |
537 | 474 | | |
| |||
585 | 522 | | |
586 | 523 | | |
587 | 524 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
| 525 | + | |
598 | 526 | | |
599 | 527 | | |
600 | 528 | | |
| |||
0 commit comments