3 Commits

+17 -10
View File
@@ -1,5 +1,5 @@
name: 'Cache Save' name: 'Cache Restore'
description: 'Save cache as tar.xz archive on the runner filesystem' description: 'Restore cache from tar.xz archive on the runner filesystem'
inputs: inputs:
path: path:
description: 'Directory to cache' description: 'Directory to cache'
@@ -11,10 +11,15 @@ inputs:
key-file: key-file:
description: 'File to hash for the cache key' description: 'File to hash for the cache key'
required: true required: true
outputs:
cache-hit:
description: 'true if exact key match found, false otherwise'
value: ${{ steps.restore.outputs.cache-hit }}
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: Save cache - name: Restore cache
id: restore
shell: bash shell: bash
run: | run: |
CACHE_DIR="$HOME/.cache/.cache-store" CACHE_DIR="$HOME/.cache/.cache-store"
@@ -29,13 +34,15 @@ runs:
echo "Key file: ${{ inputs.key-file }}" echo "Key file: ${{ inputs.key-file }}"
echo "Path input: ${{ inputs.path }}" echo "Path input: ${{ inputs.path }}"
echo "Expanded path: ${EXPANDED_PATH}" echo "Expanded path: ${EXPANDED_PATH}"
echo "Cache key: ${CACHE_KEY}"
echo "Archive path: ${ARCHIVE}" echo "Archive path: ${ARCHIVE}"
if [ ! -d "$EXPANDED_PATH" ] || [ -z "$(ls -A "$EXPANDED_PATH" 2>/dev/null)" ]; then if [ -f "$ARCHIVE" ]; then
echo "Cache directory empty, skipping save" echo "Cache hit: ${CACHE_KEY}"
exit 0 mkdir -p "$EXPANDED_PATH"
tar -xf "$ARCHIVE" -C "/" 2>/dev/null || true
echo "cache-hit=true" >> $GITHUB_OUTPUT
else
echo "Cache miss: ${CACHE_KEY}"
echo "cache-hit=false" >> $GITHUB_OUTPUT
fi fi
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"