Reputation: 1017
How can I verify that npm install installed modules from the npm cache, from inside a Github action step?
Upvotes: 1
Views: 418
Reputation: 5786
There won't be an npm cache by default. The boxes it spins up will be new every time. You can configure one using actions/cache. It would look something like:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build
run: npm run build
To verify it, you can run the build once, then run the same build again. The subsequent run should be faster. You can also verify in the output that the "Install dependencies" (or whatever name you give it) is skipped.
Note: the display above will be what you see with explicitly defined steps like the config above. More complex setups might bundle all of this in an action, but you would still
Upvotes: 0