首页 > 解决方案 > ci github-actions “env-cmd:未找到”

问题描述

我正在尝试使用 github-actions 设置 CI 工作流程并运行一些问题。想法:

  1. 创建构建并上传为工件
  2. 下载工件,运行 4 个使用下载的工件的不同运行程序并运行测试。

问题:我可以设法运行构建和上传,它还下载了工件,但后来我遇到了错误:

块引用

我的工作流程文件

name: CI Pull Request
on:
  # Trigger the workflow on push or pull request,
  # but only for the master branch
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
env:
  CI: false
jobs:
  install:
    runs-on: ubuntu-latest
    container: cypress/browsers:node12.18.3-chrome87-ff82
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run install & build
        run: |
          npm ci
          npm run build --if-present

      - name: Save build folder
        uses: actions/upload-artifact@v2
        with:
          name: build
          if-no-files-found: error
          path: build

      - name: Cypress install
        uses: cypress-io/github-action@v2
        with:
          # Disable running of tests within install job
          runTests: false
          build: npm build
  ui-chrome-tests:
    runs-on: ubuntu-latest
    container: cypress/browsers:node12.18.3-chrome87-ff82
    needs: install
    strategy:
      fail-fast: false
      matrix:
        # run copies of the current job in parallel
        containers: [1, 2, 3, 4, 5]
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Download the build folders
        uses: actions/download-artifact@v2
        with:
          name: build
          path: build

      - name:

      - name: "UI Tests - Chrome"
        uses: cypress-io/github-action@v2
        with:
          # we have already installed all dependencies above
          install: false
          start: |
            npm install env-cmd
            npm run start
          wait-on: "http://localhost:3000"
          wait-on-timeout: 120
          browser: chrome
          record: false
          parallel: true
          group: "UI - Chrome"
          spec: cypress/tests/ui/*
          command: npm run e2e
        env:
          # Recommended: pass the GitHub token lets this action correctly
          # determine the unique run id necessary to re-run the checks
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

还有我的 package.json:

"scripts": {
"e2e": "cypress run",
"test:cypress": "run-p --race start e2e",
"start": "rm -f .env; sh -ac 'env-cmd -f .env.local craco start'",
"build": "craco build",
"test": "craco test",
"cypress:open": "cypress open",
"eject": "react-scripts eject",
"format": "prettier --write src/**/*",
"lint": "eslint --fix src/**/*",
"deploy:staging": "./deploy.sh -s",
"deploy:production": "./deploy.sh -p"

},

任何提示/提示如何解决它?我想通过运行 npm install 和上传+下载工件 env-cmd 应该可用?

非常感谢和赞赏!

标签: githubcontinuous-integrationgithub-actions

解决方案


现在通过将所有内容添加到每个容器中来解决问题。

name: CI Pull Request
on:
  # Trigger the workflow on push or pull request,
  # but only for the master branch
  push:
    branches:
      - master
  pull_request:
    types: [assigned, opened, synchronize, reopened, ready_for_review]
    branches:
      - master
env:
  CI: false
jobs:
  ui-chrome-tests:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    container: cypress/browsers:node12.18.3-chrome87-ff82
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Run Server
        run: |
          npm ci
          npm run start & npx wait-on http://localhost:3000

      - name: "UI Tests - Chrome"
        uses: cypress-io/github-action@v2
        with:
          install: false
          start: npm run e2e
          browser: chrome
          spec: cypress/integration/**
        env:
          # Recommended: pass the GitHub token lets this action correctly
          # determine the unique run id necessary to re-run the checks
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


推荐阅读