Existing cache cannot be restored
I have the GHA-workflow below, which installs R and some R packages on windows-latest and should cache the R packages directory.
The workflow is always triggered manually (workflow_dispatch) from the main branch of the repo (which is also the only branch in this repo).
Workflow yaml
name: Test Cache R
on:
workflow_dispatch:
permissions:
contents: read
actions: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
jobs:
evaluation:
runs-on: windows-latest
env:
R_LIBS_USER: ${{ github.workspace }}\RLibrary
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Restore setup cache
id: cache-setup
uses: actions/cache@v4
with:
key: Ronly-Main-123456789
path: |
${{ env.R_LIBS_USER }}
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.3.1'
use-public-rspm: true
rtools-version: 'none'
- id: install-cran-packages
name: Install cran packages (NO CACHE FOUND)
if: steps.cache-setup.outputs.cache-hit != 'true'
run: |
install.packages(c("remotes", "pak"))
shell: Rscript {0}
- name: Debug cached paths before save
if: steps.cache-setup.outputs.cache-hit != 'true'
run: |
echo "Listing R library root: $R_LIBS_USER"
if [ -d "$R_LIBS_USER" ]; then
ls -l "$R_LIBS_USER"
else
echo "R library directory missing"
fi
shell: bash
The first workflow run creates the cache as expected.
Screens: created cache
All following workflow runs (started again manually from the same main branch of the repo) however cannot restore from cache. But the cache exists - which results in the error message when trying to save the cache again in the "Post restore" workflow step:
E.g. here is the result from the 2nd workflow run:
(The error message is misleading; in fact the cache for the given combination of {branch, key, version} exists - compare https://github.com/actions/cache/issues/1665)
Attached are the log files from 3rd workflow run (created with the GHA debug diagnostics turned on): logs_47695047952.zip
Update: I have figured out what the problem was. The environment variable R_LIBS_USER, which was used in the cache path to restore, was overwritten by the R installation. This meant that the cache saved the wrong path.
Each time I tried to restore the cache, the original R_LIBS_USER path was requested, but the corresponding path was missing from the cache, which is why there was no match.
- While I think this is correct behavior for the cache, an explicit error message would be extremely helpful. For example,
The cache with the key 'MyKey-1234' was found;
however, the cache cannot be restored because some of the required paths are missing:
- Path1
- Path2
- ...
- It would also be great if this behavior was clearly described in the documentation. I could not find any mention of the fact that the cache is not found not only if there is no matching key/restore-key, but also if a path is missing. https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching#cache-hits-and-misses https://github.com/actions/cache?tab=readme-ov-file#cache-scopes