在npm启动后Github动作不起作用 [英] Github actions not working after npm start

查看:78
本文介绍了在npm启动后Github动作不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的配置,以便在Nextjs应用程序中使用Github Actions使用Cypress运行e2e测试.当它到达 npm start 命令时,尽管它似乎可以工作,因为它给出了正确的输出:在http://localhost:3000 上就绪后,该步骤将保持待处理状态,而无需进行下一步.

I have a very simple config in order to run e2e tests with Cypress using Github Actions in a Nextjs app. When it reaches the npm start command, although it seems to work since it gives the correct output: > Ready on http://localhost:3000, the step stays in pending state without ever advancing to the next step.

关于如何解决此问题的任何建议?

Any suggestions on how to fix this?

以下github操作配置( .github/workflows/nodejs.yml ):

Following github actions config (.github/workflows/nodejs.yml):

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [8.x, 10.x, 12.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: npm install, build, and test
      run: |
        npm ci
        npm run build --if-present
        npm start
        npx wait-on http://localhost:3000
      env:
        CI: true
    - name: Run Cypress
      run: |
        npx cypress run
      env:
        CI: true

推荐答案

使用控制操作符& 对我有用.请尝试以下操作.

Using the control operator & works for me. Try the following.

    - name: npm install, build, and test
      run: |
        npm ci
        npm run build --if-present
        npm start & npx wait-on http://localhost:3000
      env:
        CI: true

来自 man bash

如果命令被控制操作符& amp;终止,则外壳程序将在以下位置执行命令:子外壳中的背景.外壳程序不等待命令完成,并且返回状态为0.这些被称为异步命令.命令分开由一个;按顺序执行;Shell等待每个命令依次终止.返回状态是最后执行的命令的退出状态.

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. These are referred to as asynchronous commands. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.

这篇关于在npm启动后Github动作不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆