[英]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
.然后在eslint
和Prettier
步骤中,我使用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.问题是我没有在eslint
和prettier
的步骤上运行依赖项安装。 It still needs to be done to create node_modules
.仍然需要创建node_modules
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.