Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d128b5303 | |||
| 2d57ace5e4 | |||
| e744d2a004 |
+6
-26
@@ -1,10 +1,10 @@
|
|||||||
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'
|
||||||
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
|
||||||
@@ -31,9 +31,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 "Cache key: ${CACHE_KEY}"
|
echo "Cache key: ${CACHE_KEY}"
|
||||||
echo "Archive path: ${ARCHIVE}"
|
echo "Archive path: ${ARCHIVE}"
|
||||||
echo "Cache path: ${EXPANDED_PATH}"
|
|
||||||
|
|
||||||
if [ -f "$ARCHIVE" ]; then
|
if [ -f "$ARCHIVE" ]; then
|
||||||
echo "Cache hit: ${CACHE_KEY}"
|
echo "Cache hit: ${CACHE_KEY}"
|
||||||
@@ -44,25 +46,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"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user