diff --git a/README.md b/README.md index 3ffd0f8..108f160 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ A Gitea Action that caches build files as `tar.xz` archives on the runner filesy 2. Stores archives at `~/.cache/.cache-store/.tar.xz` 3. Restores by extracting the archive to `/`, saves by creating one 4. Saves atomically (write to `.tar.xz.tmp`, then rename) +5. Archives store the cached directory **relative** (`/...`), not its + absolute path — a later run restores into its own `path` location, so the + cache works across runs even though each run gets a fresh workspace ## Cache Retention diff --git a/action.yaml b/action.yaml index ecb22e4..e53421c 100644 --- a/action.yaml +++ b/action.yaml @@ -37,9 +37,13 @@ runs: fi echo "Saving cache: ${CACHE_KEY}" - REL_PATH="$(echo "$EXPANDED_PATH" | sed 's|^/||')" + # Archive only the directory itself (entries: /...), 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 "/" "$REL_PATH" 2>/dev/null && mv -f "$TMP_ARCHIVE" "$ARCHIVE"; then + 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"