Create restore-only action

This commit is contained in:
2026-05-17 02:03:11 +08:00
parent d31ec2f341
commit e744d2a004
+2 -24
View File
@@ -1,5 +1,5 @@
name: 'Cache' name: 'Cache Restore'
description: 'Cache build files as tar.xz 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'
@@ -44,25 +44,3 @@ runs:
echo "Cache miss: ${CACHE_KEY}" echo "Cache miss: ${CACHE_KEY}"
echo "cache-hit=false" >> $GITHUB_OUTPUT echo "cache-hit=false" >> $GITHUB_OUTPUT
fi fi
- name: Save cache
if: steps.restore.outputs.cache-hit != 'true'
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 }}")
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}"
REL_PATH="$(echo "$EXPANDED_PATH" | sed 's|^/||')"
tar -cJf "$ARCHIVE" -C "/" "$REL_PATH" 2>/dev/null && echo "Cache saved" || echo "Cache save failed"