我正在 github 中配置 CI/CD,但遇到了缓存依赖项的问题。
附加了我的 Node.js 应用程序的 github 操作 lint 配置。
如您所见,我有一个名为的附加步骤build
,用于使用actions/cache@v2
. 然后在步骤eslint
中Prettier
我使用restore-keys
. 该脚本在 eslint 步骤上失败并出现错误:
sh: 1: eslint: not found
我有 eslint 是我的 devDependencies 部分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