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

如何配置GitHub Action:测试失败时上传日志并终止流程

解决方案

不用continue-on-error: true,直接靠GitHub Actions的步骤状态判断就能实现需求,配置示例如下:

jobs:
  build-test:
    runs-on: ubuntu-latest
    steps:
      - name: 检出代码
        uses: actions/checkout@v4

      - name: 执行make check
        id: make-check
        run: make check
        # 这里不设置continue-on-error,让步骤正常标记失败,但不影响后续步骤执行

      - name: 上传测试日志到工件
        uses: actions/upload-artifact@v4
        with:
          name: test-logs
          path: ./test.log  # 替换成你的测试日志实际路径
        # 不管make check成没成功,这一步都要执行,确保日志能归档
        if: always()

      - name: 失败就终止流程
        run: exit 1
        # 只要make check失败,就执行这一步退出,终止整个任务
        if: steps.make-check.outcome == 'failure'

      - name: 执行make install
        run: make install
        # 只有make check成功的时候才触发这一步
        if: steps.make-check.outcome == 'success'

逻辑说明:

  • 给make check步骤设置id,方便后续通过steps.make-check.outcome获取它的执行状态
  • 日志上传步骤用if: always(),保证无论前面步骤成功失败,日志都能被归档
  • 新增终止步骤,一旦make check失败就直接退出流程,避免后续不必要的make install执行
  • make install仅在make check成功时触发,完全符合需求逻辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 01:57:35