I have a workflow which caches the output of:
composer install using a hash of composer.locknpm ci using a hash of package-lock.jsonnpm run prod using a hash of public/**/*so they can be reused on subsequent runs.
The problem is, only the composer cache is ever hit - the two npm caches always result in a message in the CI output saying Cache not found for input keys.
Taking the npm ci code as an example, the cache setup and the subsequent usage are done by these two steps:
- name: Cache node packages
id: cache-npm-packages
uses: actions/cache@v2
env:
cache-name: cache-node-packages
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- if: ${{ steps.cache-npm-packages.outputs.cache-hit != 'true' }}
run: npm ci
But the CI output says:
Cache not found for input keys: Linux-build-cache-node-packages-4370b0e1b9396b576e8db83e048ce2efe36557c8c4bae8492253ef706fc8a4bc
Despite being in the list of cache entries:

The screenshot also shows that the cache of npm run prod is repeatedly being generated and never reused.
What am I doing wrong?
I had this same issue, the problem is that a branch 'A' can only retrieve the cache of the 'main' branch or if it is a child branch.
All your cache is being created by pull requests, as you can see ref/pull/foo/merge
Caches stored by pull request can only be accessed on re-runs on the same branch.
To solve your problem, you should run the workflow once in the main branch, so any other action will be able to access it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With