I'm working on configuration of CI/CD in github and faced a problem with caching of dependencies.
My github actions lint config for my Node.js app attached.
As you can see I have additional step called build
which is used to cache dependencies using actions/cache@v2
. Then on eslint
and Prettier
steps I extract cached data using restore-keys
.
The script fails on eslint step with error:
sh: 1: eslint: not found
I have eslint is my devDependencies section in package.json
.
name: test
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Install dependencies
run: npm ci --ignore-scripts
eslint:
needs: build
name: ESLint
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Lint source code with ESLint
run: npm run lint
prettier:
needs: build
name: Prettier
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Lint source code with Prettier
run: npm run check:format
The problem was that I didn't run dependencies installation on eslint
and prettier
steps. It still needs to be done to create node_modules
.