简体   繁体   English

Node.js 应用程序的 Github 动作缓存不起作用

[英]Github actions caching for Node.js application is not working

I'm working on configuration of CI/CD in github and faced a problem with caching of dependencies.我正在 github 中配置 CI/CD,并且遇到了依赖项缓存的问题。

My github actions lint config for my Node.js app attached.我的 github 动作 lint 配置为我的 Node.js 应用程序附加。

As you can see I have additional step called build which is used to cache dependencies using actions/cache@v2 .如您所见,我还有一个名为build的附加步骤,用于使用actions/cache@v2缓存依赖项。 Then on eslint and Prettier steps I extract cached data using restore-keys .然后在eslintPrettier步骤中,我使用restore-keys提取缓存数据。 The script fails on eslint step with error:该脚本在 eslint 步骤上失败并出现错误:

sh: 1: eslint: not found

I have eslint is my devDependencies section in package.json .我有 eslint 是我在 package.json 中的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.问题是我没有在eslintprettier的步骤上运行依赖项安装。 It still needs to be done to create node_modules .仍然需要创建node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM