Using Github actions to publish npm package, It works and runs jest test cases without errors. So I decided to add yarn cache to optimize build time and the cache process works, but jest fails with below error.
$ jest --config=jest.config.js
/bin/sh: 1: jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Process completed with exit code 127.
Here is my yml
name: NPM Publish
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Test cases
run: yarn run pdn:test
Your pipeline caches only yarn's cache, not node_modules. Jest binary is supposed to be in node_modules, so it (along with other deps) doesn't get restored from cache. This is according to actions/cache
guidelines, which suggests caching yarn cache and then doing yarn install
.
actions/setup-node
can already handle yarn caching, no need to roll your own logic for that.
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- run: yarn run test
If you really want to cache node_modules instead of yarn's cache, then cache the directory manually
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- run: yarn run test
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