|
| 1 | +# Copyright Strata Contributors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | +name: Restore lake cache |
| 4 | +description: > |
| 5 | + Thin wrapper around actions/cache/restore@v5 using the cache key |
| 6 | + lake-<os>-<arch>-<lean-toolchain>-<lake-manifest>-<sha> |
| 7 | + with two fallback keys dropping each trailing component in turn. The |
| 8 | + manifest hash covers the cloned Strata dependency. |
| 9 | +inputs: |
| 10 | + fail-on-cache-miss: |
| 11 | + description: > |
| 12 | + If 'true', the step fails when no cache entry matches. Use this in |
| 13 | + jobs that depend on a cache saved by an upstream job for the same |
| 14 | + SHA (see https://github.com/strata-org/Strata/issues/952). |
| 15 | + required: false |
| 16 | + default: "false" |
| 17 | + path: |
| 18 | + description: Cache path(s), newline-separated. |
| 19 | + required: false |
| 20 | + default: ".lake" |
| 21 | + key-prefix: |
| 22 | + description: > |
| 23 | + Prefix used in the cache key. The action also hashes the |
| 24 | + repo-root `lean-toolchain` and `lake-manifest.json`, so changing |
| 25 | + only this prefix is appropriate for caches keyed on the same |
| 26 | + root-level Lean build (e.g. distinguishing different artifact |
| 27 | + names with the same source set). Sub-projects with their own |
| 28 | + toolchain/manifest do not currently fit this action and should |
| 29 | + not reuse it as-is. |
| 30 | + required: false |
| 31 | + default: "lake" |
| 32 | + use-restore-keys: |
| 33 | + description: > |
| 34 | + Must be the string `'true'` or `'false'`. |
| 35 | +
|
| 36 | + If `'true'` (default), include two fallback `restore-keys` so |
| 37 | + that a near match (same toolchain/manifest but different SHA) is |
| 38 | + used when no exact-SHA cache exists. |
| 39 | +
|
| 40 | + Set to `'false'` for downstream jobs that depend on a cache saved |
| 41 | + by an upstream job for the *same* SHA (typically together with |
| 42 | + `fail-on-cache-miss: 'true'`); see |
| 43 | + https://github.com/strata-org/Strata/issues/952. With fallback |
| 44 | + keys present, `fail-on-cache-miss` only triggers when every |
| 45 | + fallback also misses, which silently allows stale cross-SHA cache |
| 46 | + matches and defeats the safety net. |
| 47 | + required: false |
| 48 | + default: "true" |
| 49 | + |
| 50 | +outputs: |
| 51 | + cache-hit: |
| 52 | + description: Whether a cache entry was restored (see actions/cache/restore@v5). |
| 53 | + value: ${{ steps.restore-with-fallback.outputs.cache-hit || steps.restore-exact.outputs.cache-hit }} |
| 54 | + |
| 55 | +runs: |
| 56 | + using: composite |
| 57 | + steps: |
| 58 | + - name: Restore lake cache (with fallback keys) |
| 59 | + id: restore-with-fallback |
| 60 | + if: inputs.use-restore-keys != 'false' |
| 61 | + uses: actions/cache/restore@v5 |
| 62 | + with: |
| 63 | + path: ${{ inputs.path }} |
| 64 | + key: ${{ inputs.key-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('lean-toolchain') }}-${{ hashFiles('lake-manifest.json') }}-${{ github.sha }} |
| 65 | + restore-keys: | |
| 66 | + ${{ inputs.key-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('lean-toolchain') }}-${{ hashFiles('lake-manifest.json') }} |
| 67 | + ${{ inputs.key-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('lean-toolchain') }} |
| 68 | + fail-on-cache-miss: ${{ inputs.fail-on-cache-miss }} |
| 69 | + - name: Restore lake cache (exact SHA only) |
| 70 | + id: restore-exact |
| 71 | + if: inputs.use-restore-keys == 'false' |
| 72 | + uses: actions/cache/restore@v5 |
| 73 | + with: |
| 74 | + path: ${{ inputs.path }} |
| 75 | + key: ${{ inputs.key-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('lean-toolchain') }}-${{ hashFiles('lake-manifest.json') }}-${{ github.sha }} |
| 76 | + fail-on-cache-miss: ${{ inputs.fail-on-cache-miss }} |
0 commit comments