Closed GaxZE closed 11 months ago
You're running the cache after instead of before the npm i
, try adding the cache before you create the things you want to cache.
I also suggest adding the following to the restore action so the restore fails on the correct part
with:
fail-on-cache-miss: true
Try this:
name: Main
on:
pull_request:
branches: [main]
jobs:
setup:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
id: npm-cache
with:
path: |
~/.npm
node_modules
key: ${{ matrix.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
- run: npm ci
if: steps.npm-cache.outputs.cache-hit != 'true'
- run: npm run build-stylable-types
if: steps.npm-cache.outputs.cache-hit != 'true'
lint:
runs-on: ubuntu-latest
needs: setup
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/cache/restore@v3
id: npm-cache
with:
fail-on-cache-miss: true
path: |
~/.npm
node_modules
key: ${{ matrix.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm run lint
You're running the cache after instead of before the
npm i
, try adding the cache before you create the things you want to cache.
Thanks for the response. I was actually running it after npm ci
which will remove the cache I am restoring. I seemingly solved this issue by removing ~/.npm
in the path and used absolute paths /home/runner/.npm
for example.
This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.
This issue was closed because it has been inactive for 5 days since being marked as stale.
I am trying to run a workflow with a caching strategy that starts with a setup job and then caches the dependencies and restores them being running a linting job.
Jobs end up with following:
Setup:
Build:
Key is
16.x-npm-cache-8653ab79e0fd3bd57121958ffb101b35fc1f86cc4c053b96ff238091a01df3ae
(also18.x-npm-cache-8653ab79e0fd3bd57121958ffb101b35fc1f86cc4c053b96ff238091a01df3ae
Have I missed a part of the docs where the cache can't persist to another job? The Pull request it's coming from is a fork PR. I am trying to understand the scope to be able to restore. I suspect my issue is there. But I did also try this as a branch within the repository instead of a forked one.