You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修改Cypress测试时PR跳过任务却卡在状态等待上报求助

问题

在一个包含前端/后端/自动化测试的单体仓库中配置了Pull Request工作流,该工作流会在每个PR触发。为了仅修改Cypress测试时不部署前后端,添加了path-ignore规则且已生效,但此时仅修改path-ignore文件夹内容的PR会被以下信息阻塞:

Questions E2E Test / build-and-test Expected — Waiting for status to be reported

即便E2E工作流并未运行,系统仍要求其上报状态。

E2E工作流末尾代码

- name: Check for Report Files
        id: check_report
        run: |
          if [ -f backend/reports/junit.xml ]; then
            echo "report_exists=true" >> $GITHUB_ENV
          else
            echo "report_exists=false" >> $GITHUB_ENV
          fi

      - name: Upload Report to artifacts
        uses: actions/upload-artifact@v3
        if: env.report_exists == 'true'
        with:
          name: e2e-report.${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
          path: backend/reports/junit.xml

      - name: Clear connection
        if: success() || failure()
        run: |
          pkill -9 -f start-iap-tunnel

      - name: Test Report
        id: e2e_test_report
        uses: dorny/test-reporter@v1
        if: env.report_exists == 'true'
        with:
          name: Questions E2E Tests
          path: backend/reports/*.xml
          reporter: jest-junit

      - name: Notify on PR
        if: github.event_name == 'pull_request' && (success() || failure()) && steps.e2e_test_report.outputs.url_html != ''
        uses: actions/github-script@v6
        with:
          script: |
            await github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `### E2E Questions test report overview

              | Passed ✅     | Failed ❌     | Skipped |
              | ------------- |:-------------:| -------:|
              | ${{ steps.e2e_test_report.outputs.passed }}  | ${{ steps.e2e_test_report.outputs.failed }} | ${{ steps.e2e_test_report.outputs.skipped }} |
              
              **Report link:** ${{ steps.e2e_test_report.outputs.url_html }}

              `
            });

Pull Request工作流代码

on:
  pull_request:
    branches:
      - main
    paths-ignore:
      - '.github/**'
      - 'cypress-tests/**'
      - 'api-tests/**'
jobs:
  questions-e2e-test:
    name: Questions E2E Test
    uses: ./.github/workflows/job-questions-e2e-test.yml
    with:
      WORKLOAD_IDENTITY_PROVIDER_DEV: ${{ vars.WORKLOAD_IDENTITY_PROVIDER_DEV }}
      SERVICE_ACCOUNT_DEV: ${{ vars.SERVICE_ACCOUNT_DEV }}
    secrets:
      token: ${{ secrets.GITHUB_TOKEN }}

  deploy-preview-backend:
    name: Deploy backend preview
    uses: ./.github/workflows/backend-deploy-preview.yml
    with:
      WORKLOAD_IDENTITY_PROVIDER_DEV: ${{ vars.WORKLOAD_IDENTITY_PROVIDER_DEV }}
      SERVICE_ACCOUNT_DEV: ${{ vars.SERVICE_ACCOUNT_DEV }}
      DEPLOY_CHANNEL_ID_DEV: ${{ github.head_ref == 'pentest' && 'pentest' || format('pr{0}', github.event.pull_request.number) }}

  deploy-preview-frontend:
    name: Deploy frontend preview
    uses: ./.github/workflows/frontend-deploy-preview.yml
    with:
      WORKLOAD_IDENTITY_PROVIDER_DEV: ${{ vars.WORKLOAD_IDENTITY_PROVIDER_DEV }}
      SERVICE_ACCOUNT_DEV: ${{ vars.SERVICE_ACCOUNT_DEV }}
      DEPLOY_CHANNEL_ID_DEV: ${{ github.head_ref == 'pentest' && 'pentest' || format('pr{0}', github.event.pull_request.number) }}
 

  send-message:
    needs: [deploy-preview-frontend, deploy-preview-backend]
    runs-on: ubuntu-latest
    if: ${{ always() && contains(needs.*.result, 'success') && !(contains(needs.*.result, 'failure')) && !(contains(needs.*.result, 'cancelled')) }}
    steps:
      - uses: actions/checkout@v4
      - name: Notify pull request
        uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: ${{ github.event.pull_request.number }},
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Deployed to ${{ format('https://{0}.preview.dev', format('pr{0}', github.event.pull_request.number)) }}`
            })

如何在跳过指定任务的同时避免该状态阻塞问题?

解决方案

方案1:为E2E任务添加条件判断,标记为跳过而非不触发

在PR工作流的questions-e2e-test任务中添加if条件,判断PR修改的文件是否属于测试目录。当仅修改测试文件时,该任务会被标记为skipped,而非完全不触发,这样就能满足系统的状态检查要求:

修改后的questions-e2e-test任务代码:

jobs:
  questions-e2e-test:
    name: Questions E2E Test
    if: ${{ !contains(github.event.pull_request.changes.*.filename, 'cypress-tests/') && !contains(github.event.pull_request.changes.*.filename, 'api-tests/') }}
    uses: ./.github/workflows/job-questions-e2e-test.yml
    with:
      WORKLOAD_IDENTITY_PROVIDER_DEV: ${{ vars.WORKLOAD_IDENTITY_PROVIDER_DEV }}
      SERVICE_ACCOUNT_DEV: ${{ vars.SERVICE_ACCOUNT_DEV }}
    secrets:
      token: ${{ secrets.GITHUB_TOKEN }}

方案2:调整分支保护规则,允许跳过的检查通过

如果仓库设置了分支保护,要求Questions E2E Test状态必须通过,可以修改规则:

  1. 进入仓库Settings → Branches → Branch protection rules
  2. 找到对应的分支规则,在Require status checks to pass before merging区域,勾选Allow skipped checks to pass选项
  3. 保存后,当E2E任务被跳过时,系统会默认该状态为通过,不会阻塞PR合并

方案3:拆分工作流,按文件路径触发不同任务

将原PR工作流拆分为两个独立工作流:

  1. 原工作流去掉paths-ignore中的测试目录,仅在修改前端/后端代码时触发,包含部署和E2E测试任务
  2. 新建一个工作流,仅在修改cypress-tests/、api-tests/目录时触发,只运行测试相关任务,不包含部署和E2E测试

这样修改测试文件时,只会触发专属测试工作流,不会触发原PR工作流,也就不会出现状态等待的问题。


内容的提问来源于stack exchange,提问作者George

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 09:14:51