Github 操作 - /bin/sh: 1: jest: not found
Posted
技术标签:
【中文标题】Github 操作 - /bin/sh: 1: jest: not found【英文标题】:Github actions - /bin/sh: 1: jest: not found 【发布时间】:2020-08-11 19:57:57 【问题描述】:使用 Github 操作发布 npm 包,它可以正常运行并运行 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
【问题讨论】:
你解决了吗?我怀疑问题是恢复缓存目录不会将笑话添加回 $path,因此需要手动添加或直接通过其 ./node_modules 路径调用 【参考方案1】:我遇到了类似的问题,我提到了一些其他人的做法。也许试一试
- 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
【讨论】:
这解决了找不到命令的问题,但在时间上大大否定了缓存的好处。由于构建了新的包,在线和离线步骤都需要相似的时间来运行。【参考方案2】:您的管道仅缓存纱线的缓存,而不是 node_modules。 Jest 二进制文件应该在 node_modules 中,因此它(连同其他部门)不会从缓存中恢复。这是根据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
【讨论】:
以上是关于Github 操作 - /bin/sh: 1: jest: not found的主要内容,如果未能解决你的问题,请参考以下文章