【问题标题】:Github actions not working after npm startnpm start 后 Github 操作不起作用
【发布时间】:2020-02-13 20:23:25
【问题描述】:

我有一个非常简单的配置,以便在 Nextjs 应用程序中使用 Github Actions 使用 Cypress 运行 e2e 测试。当它到达npm start 命令时,虽然它似乎可以工作,因为它给出了正确的输出:> Ready on http://localhost:3000,但该步骤仍处于挂起状态,而不会进入下一步。

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

按照 github 操作配置 (.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

【问题讨论】:

  • 不知道是不是npx wait-on http://localhost:3000的问题。你试过npx wait-on http://127.0.0.1:3000吗?我想我之前经历过一些 localhost 不起作用的事情。

标签: node.js continuous-integration next.js cypress github-actions


【解决方案1】:

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

    - 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

如果一个命令被控制操作符 & 终止,shell 执行命令 子shell中的背景。 shell 不会等待命令完成,并且 返回状态为 0。这些被称为异步命令。命令分开 由一个;依次执行; shell 等待每个命令依次终止。 返回状态是最后执行的命令的退出状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-05
    • 2017-06-10
    • 2023-03-06
    • 2017-07-24
    • 1970-01-01
    • 2021-09-26
    • 2021-01-03
    • 1970-01-01
    相关资源
    最近更新 更多