I am having a Github action which runs on Windows OS. Then, for caching the dependencies, I use the actions/cache@v2
. But, it is not working as expected. When I saw the debug logs, the size of the cache is only about 30 B
.
Here is the code I am using:
name: Build
on: push
jobs:
build_on_win:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, 'skip-publish')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 15
- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: install dependencies
run: npm install
rest of the code..
Any help is greatly appreciated !
CodePudding user response:
Caching package dependencies is a feature that is already available in the actions/setup-node@v2. You don't have to configure actions/cache@v2 and instead of that what you can do is use the setup-node@v2 action like below and you just have to add cache: 'npm'
and it will automatically detect and will cache the dependencies.
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'npm'
- run: npm install
- run: npm test
If you have monorepo then you can also define the path
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'npm'
cache-dependency-path: subdir/package-lock.json
- run: npm install
- run: npm test
You can read more about it in Caching packages dependencies.