Github操作-/bin/sh:1:jest:未找到



使用Github操作发布npm包,它可以正常工作并运行jest测试用例,不会出错。所以我决定添加yarn缓存来优化构建时间和缓存过程,但jest失败了,出现了以下错误。

$ jest --config=jest.config.js
/bin/sh: 1: jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Process completed with exit code 127.

这是我的yml

name: NPM Publish
on:
push:
branches: 
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Test cases
run: yarn run pdn:test

您的管道只缓存yarn的缓存,而不缓存node_modules。Jest二进制文件应该在node_modules中,所以它(以及其他dep(不会从缓存中恢复。这是根据actions/cache指南进行的,该指南建议先缓存纱线缓存,然后再执行yarn install

actions/setup-node已经可以处理纱线缓存,不需要为此使用自己的逻辑。

- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- run: yarn run test

如果您真的想缓存node_modules而不是yarn的缓存,那么手动缓存目录

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- run: yarn run test

我遇到了类似的问题,我介绍了一些其他人的情况。也许试试

- name: Cache dependencies
uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies (from network)
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
yarn policies set-version
yarn install --frozen-lockfile --ignore-optional
- name: Install Dependencies (from cache)
if: steps.cache-deps.outputs.cache-hit == 'true'
run: |
yarn policies set-version
yarn install --frozen-lockfile --ignore-optional --offline

最新更新