3 Commits

+8 -35
View File
@@ -1,52 +1,20 @@
name: 'Cache' name: 'Cache Save'
description: 'Cache build files as tar.xz on the runner filesystem' description: 'Save cache as tar.xz archive on the runner filesystem'
inputs: inputs:
path: path:
description: 'Directory to cache' description: 'Directory to cache'
required: false required: false
default: '~/.cache/' default: ${{ github.workspace }}
key-prefix: key-prefix:
description: 'Prefix for the cache key' description: 'Prefix for the cache key'
required: true required: true
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: 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 "Cache key: ${CACHE_KEY}"
echo "Archive path: ${ARCHIVE}"
echo "Cache path: ${EXPANDED_PATH}"
if [ -f "$ARCHIVE" ]; then
echo "Cache hit: ${CACHE_KEY}"
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
- name: Save cache - name: Save cache
if: steps.restore.outputs.cache-hit != 'true'
shell: bash shell: bash
run: | run: |
CACHE_DIR="$HOME/.cache/.cache-store" CACHE_DIR="$HOME/.cache/.cache-store"
@@ -58,6 +26,11 @@ runs:
EXPANDED_PATH=$(eval echo "${{ inputs.path }}") 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 if [ ! -d "$EXPANDED_PATH" ] || [ -z "$(ls -A "$EXPANDED_PATH" 2>/dev/null)" ]; then
echo "Cache directory empty, skipping save" echo "Cache directory empty, skipping save"
exit 0 exit 0