【问题标题】:Retry failed jobs in github actions在 github 操作中重试失败的作业
【发布时间】:2022-03-18 06:25:56
【问题描述】:

我正在尝试使用GitHub Actions 进行 CI 测试,到目前为止,我的测试工作流程如下:

name: test

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm install
      - name: test
        run: |
          npm run lint
          npm test
        env:
          CI: true

.github/workflows/test.yml

它工作正常,但如果测试失败,我想重试一次 test 步骤(或整个工作)。

基本上,与travis-retry 相同的行为:

script:
  - npm run lint
  - travis_retry npm test

或使用 Gitlab CI:

test:
  stage: test
  retry: 1
  script:
    - npm run lint
    - npm test

不确定是否有办法或相当简单的解决方法

【问题讨论】:

    标签: continuous-integration github-actions


    【解决方案1】:

    对于您的特定用例,只需执行以下操作:

    npm test || npm test
    

    【讨论】:

      【解决方案2】:

      Action Retry 似乎在我的测试中运行良好

      https://github.com/nick-invision/retry/

      只要它们是单行的,我就可以将它与多部分命令一起使用(例如 do-this && do-that

      【讨论】:

      • 这应该是公认的答案,因为它是独立于代码的通用解决方案
      【解决方案3】:

      我会说您需要在代码级别管理重试逻辑。意思是,实施/集成这样的机制以仅处理和执行失败的测试。恐怕只是

      如果测试失败,想要重试测试步骤(或整个作业)。

      将执行您的所有测试,甚至可能覆盖输出,例如第一次运行的报告和日志。

      根据我的经验,我使用了包装(shell)脚本。这是如何实现的:

      #!/usr/bin/env bash
      { # try
          # your npm test command here, that saves as output -  failed tests
      } || { # catch
          # retry failed tests
            if [ -f ./rerun-failed-file ]; then
              echo "============= [WARN] Rerun file found! =============="
              echo "============= [WARN] Rerunning FAILED tests mode. =============="
              # run npm test command that picks up the failed tests & aggregate test artifacts
            fi
      } 
      

      【讨论】:

        【解决方案4】:

        不幸的是doesn't look like the feature exists yet

        作为一项手动工作,我不得不使用重新运行所有检查按钮重新触发失败的工作流,您可以在viewing a failed workflow 时找到右上角的按钮。

        【讨论】:

          【解决方案5】:

          wretry.action

          该操作可以重试单个 Github 操作或 shell 命令。但有一些限制。

          【讨论】:

            【解决方案6】:

            请注意,您可以使用 GitHub CLI gh 从命令行重新运行失败的作业

            从 gh 2.6.0 开始:

            重新运行失败的作业

            gh run rerun 增加了两个新标志:

            您现在可以有选择地重新运行给定工作流运行中刚刚失败的作业!

            运行 gh run rerun --failed 将提示您选择要使用的运行。


            Web GUI 支持这一点:

            Save time with partial re-runs in GitHub Actions

            现在可以仅重新运行失败的作业或 GitHub Actions 工作流程中的单个作业。

            如果您在工作流运行中有失败的作业,您现在将看到一个新的下拉菜单,除了现有的“重新运行所有作业”之外,您还可以在其中选择“重新运行失败的作业”。

            对于已完成的运行,当您将鼠标悬停在侧边栏中列出的每个作业上时,它都有一个重新运行图标。也可以直接从日志视图重新运行作业。

            【讨论】:

              猜你喜欢
              • 2021-10-01
              • 2023-01-05
              • 2013-01-01
              • 2020-10-26
              • 2022-08-23
              • 2021-05-16
              • 2021-10-06
              • 2022-01-25
              • 2015-03-24
              相关资源
              最近更新 更多