Save atomically and auto-prune the cache store

Write the archive to a .tmp file then rename into place so a concurrent
prune can never delete a half-written archive, and run prune.sh after
every save: keep the 3 newest archives per key-prefix family, expire
anything older than 7 days, hard-cap the store at 2 GB (oldest first,
trumping the keep set), never touch files younger than 1h, and drop
stale run workspaces under ~/.cache/act older than 2 days.
This commit is contained in:
2026-08-14 22:54:43 +08:00
parent 985f68d26e
commit c9286e3624
3 changed files with 119 additions and 1 deletions
+10 -1
View File
@@ -38,4 +38,13 @@ runs:
echo "Saving cache: ${CACHE_KEY}"
REL_PATH="$(echo "$EXPANDED_PATH" | sed 's|^/||')"
tar -cJf "$ARCHIVE" -C "/" "$REL_PATH" 2>/dev/null && echo "Cache saved" || echo "Cache save failed"
TMP_ARCHIVE="${ARCHIVE}.tmp"
if tar -cJf "$TMP_ARCHIVE" -C "/" "$REL_PATH" 2>/dev/null && mv -f "$TMP_ARCHIVE" "$ARCHIVE"; then
echo "Cache saved"
else
rm -f "$TMP_ARCHIVE"
echo "Cache save failed"
fi
# Trim the shared cache store and stale workspaces (best-effort)
bash "${{ github.action_path }}/prune.sh" || true