Each run gets a fresh per-run workspace (~/.cache/act/<hash>/hostexecutor), so embedding the absolute path meant the next run restored into a stale workspace and the cache never actually sped up a build. Save with -C <parent> <basename> so entries are <basename>/... and restores can extract into the run's own path input location.
55 lines
1.8 KiB
YAML
55 lines
1.8 KiB
YAML
name: 'Cache Save'
|
|
description: 'Save cache as 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
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Save cache
|
|
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 "Archive path: ${ARCHIVE}"
|
|
|
|
if [ ! -d "$EXPANDED_PATH" ] || [ -z "$(ls -A "$EXPANDED_PATH" 2>/dev/null)" ]; then
|
|
echo "Cache directory empty, skipping save"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Saving cache: ${CACHE_KEY}"
|
|
# Archive only the directory itself (entries: <basename>/...), not its
|
|
# absolute path, so a later run can restore it into its own (per-run)
|
|
# workspace location. Restores use the same `path` input to find it.
|
|
PARENT="$(dirname "$EXPANDED_PATH")"
|
|
BASE="$(basename "$EXPANDED_PATH")"
|
|
TMP_ARCHIVE="${ARCHIVE}.tmp"
|
|
if tar -cJf "$TMP_ARCHIVE" -C "$PARENT" "$BASE" 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
|