-
Notifications
You must be signed in to change notification settings - Fork 1.5k
If the target path doesn't match the source path, restore reports "Cache not found for input keys" #1444
Description
Hey there,
I've been trying to use the save/restore actions from two separate jobs, and after six hours of head-scratching, worked out what's going on. If the path provided to the restore command doesn't exactly match the path that was provided to the save command, the restore action reports "Cache not found for input keys". Here's a repro case. Run this in any repo, then look at the action console output; the second fetch-stuff-from-cache job won't restore any files.
name: cache-test
on:
push:
branches: ["main"]
paths:
- '.github/workflows/caching-test.yml'
workflow_dispatch:
jobs:
cache-some-stuff:
runs-on: ubuntu-latest
steps:
- name: Create some files
run: |
mkdir my-files
echo "Hello" > my-files/file0001.txt
echo "World" > my-files/file0002.txt
ls -lR
- uses: actions/cache/save@v4
id: put-files-in-cache
with:
path: my-files
key: my-cached-files-${{ github.run_id }}
fetch-stuff-from-cache-success:
runs-on: ubuntu-latest
steps:
- name: restore files from from cache
uses: actions/cache/restore@v4
with:
path: my-files
key: my-cached-files
- name: List files
run: ls -lR
fetch-stuff-from-cache-failure:
runs-on: ubuntu-latest
steps:
- name: restore files from from cache
uses: actions/cache/restore@v4
with:
path: this-will-fail-because-the-path-is-not-the-same
key: my-cached-files
- name: List files
run: ls -lR
It's not clear anywhere in the documentation or in the error message that you can only restore cached content to the same path it was originally cached from - presumably because if you're using the cache action rather than separate save/restore actions there's no way to specify a different path.
Is there any underlying technical reason I can't restore cached content to a different path than it was originally saved from? If not, this would make the save/restore combination far more flexible for caching files in complex build jobs - but if this isn't possible, could the restore error message be updated to make it explicit that the target path doesn't match and that's the reason it can't find anything?
Thanks,
Dylan