0

我正在 github 中配置 CI/CD,但遇到了缓存依赖项的问题。

附加了我的 Node.js 应用程序的 github 操作 lint 配置。

如您所见,我有一个名为的附加步骤build,用于使用actions/cache@v2. 然后在步骤eslintPrettier我使用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

4

1 回答 1

0

问题是我没有在eslintprettier步骤上运行依赖项安装。仍然需要创建node_modules.

于 2021-05-29T18:51:53.737 回答