Record last use by touching the archive so the retention policy can expire by access time, and run prune.sh after every restore (even on miss) to keep the shared store trimmed: 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.
58 lines
1.8 KiB
YAML
58 lines
1.8 KiB
YAML
name: 'Cache Restore'
|
|
description: 'Restore cache from tar.xz archive on the runner filesystem'
|
|
inputs:
|
|
path:
|
|
description: 'Directory to cache'
|
|
required: false
|
|
default: ${{ github.workspace }}
|
|
key-prefix:
|
|
description: 'Prefix for the cache key'
|
|
required: true
|
|
key-file:
|
|
description: 'File to hash for the cache key'
|
|
required: true
|
|
outputs:
|
|
cache-hit:
|
|
description: 'true if exact key match found, false otherwise'
|
|
value: ${{ steps.restore.outputs.cache-hit }}
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Restore cache
|
|
id: restore
|
|
shell: bash
|
|
run: |
|
|
CACHE_DIR="$HOME/.cache/.cache-store"
|
|
mkdir -p "$CACHE_DIR"
|
|
|
|
KEY_HASH=$(sha256sum "${{ inputs.key-file }}" | awk '{print $1}')
|
|
CACHE_KEY="${{ inputs.key-prefix }}-${KEY_HASH}"
|
|
ARCHIVE="${CACHE_DIR}/${CACHE_KEY}.tar.xz"
|
|
|
|
EXPANDED_PATH=$(eval echo "${{ inputs.path }}")
|
|
|
|
echo "Key file: ${{ inputs.key-file }}"
|
|
echo "Path input: ${{ inputs.path }}"
|
|
echo "Expanded path: ${EXPANDED_PATH}"
|
|
echo "Cache key: ${CACHE_KEY}"
|
|
echo "Archive path: ${ARCHIVE}"
|
|
|
|
if [ -f "$ARCHIVE" ]; then
|
|
echo "Cache hit: ${CACHE_KEY}"
|
|
mkdir -p "$EXPANDED_PATH"
|
|
if tar -xf "$ARCHIVE" -C "/" 2>/dev/null; then
|
|
# record last use so the retention policy can expire by access time
|
|
touch "$ARCHIVE"
|
|
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Cache restore failed"
|
|
echo "cache-hit=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
else
|
|
echo "Cache miss: ${CACHE_KEY}"
|
|
echo "cache-hit=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
# Trim the shared cache store and stale workspaces (best-effort)
|
|
bash "${{ github.action_path }}/prune.sh" || true
|