Save ccache even when a later step fails (split restore/save)

actions/cache's post-save is gated by post-if: success(), so the failing publish step discarded the compile cache on every run — each build started cold. Split into actions/cache/restore + actions/cache/save, with the save placed right after the build and gated on !cancelled(), so the valid compiler cache is persisted whether or not publish (or any later step) fails. Skips only on cancellation, to avoid bloating the cache with half-built runs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-06-18 01:15:02 +08:00
parent 54afeb6762
commit 93e72f8cbe
+18 -3
View File
@@ -163,12 +163,15 @@ jobs:
- name: 恢复 ccache 缓存 - name: 恢复 ccache 缓存
if: env.BUILD_NEEDED == 'true' if: env.BUILD_NEEDED == 'true'
uses: actions/cache@v4 uses: actions/cache/restore@v4
with: with:
# Only the compiler cache is worth persisting: the kernel source is # Only the compiler cache is worth persisting: the kernel source is
# re-cloned each run and out/ holds freshly built packages. A unique key # re-cloned each run and out/ holds freshly built packages. A unique key
# per run forces a save; restore-keys warm-start from the most recent # per run forces a fresh save; restore-keys warm-start from the most recent
# prior build of the same arch (then any build of the same arch). # prior build of the same arch (then any build of the same arch). Restore
# and save are split (not the combined actions/cache) because that action's
# post-save is gated by post-if: success() — a failed publish would discard
# the whole compile cache. The matching save runs right after the build.
path: ~/.ccache path: ~/.ccache
key: ccache-${{ matrix.arch }}-${{ needs.preflight.outputs.kernel_version }}-${{ github.run_id }} key: ccache-${{ matrix.arch }}-${{ needs.preflight.outputs.kernel_version }}-${{ github.run_id }}
restore-keys: | restore-keys: |
@@ -236,6 +239,18 @@ jobs:
if: env.BUILD_NEEDED == 'true' if: env.BUILD_NEEDED == 'true'
run: ccache -s run: ccache -s
- name: 保存 ccache 缓存
# Save even when a later step fails: the compiler cache is valid the moment
# the build finishes, so a downstream failure (e.g. the registry upload) must
# not discard it. !cancelled() = save on success or failure, but skip
# cancellations (cancel-in-progress) so half-built runs don't bloat the cache.
# Key matches the restore step's primary key above.
if: ${{ !cancelled() && env.BUILD_NEEDED == 'true' }}
uses: actions/cache/save@v4
with:
path: ~/.ccache
key: ccache-${{ matrix.arch }}-${{ needs.preflight.outputs.kernel_version }}-${{ github.run_id }}
- name: 检查 deb 包 - name: 检查 deb 包
if: env.BUILD_NEEDED == 'true' if: env.BUILD_NEEDED == 'true'
run: | run: |