【问题标题】:Xcode test failing does not failed Github action pipelineXcode 测试失败并没有失败 Github 操作管道
【发布时间】:2020-02-29 20:09:50
【问题描述】:

我有一个 Github Action 管道:

name: default

on: [push]

jobs:
  build:

    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v1
    - name: CocoaPod Install
      run: pod install
    - name: Force xcode 11
      run: sudo xcode-select -switch /Applications/Xcode_11.1.app
    - name: Test
      run: ./pipelines.sh test
    - name: Save report
      uses: actions/upload-artifact@v1
      with:
        name: test_report
        path: ./Test

还有一个脚本Shell:

function test
{
    xcodebuild \
       -workspace MyApp.xcworkspace \
       -scheme DEBUG\ -\ MyApp \
       -destination 'platform=iOS Simulator,name=iPhone 11' \
       test
}

我的问题是当我运行我的管道但测试失败时,管道被标记为通过,这是一个问题......

我也检查过 fastlane,失败的测试不会导致管道失败。

当测试未通过时,如何使我的管道失败?

Fastlane 截图:

【问题讨论】:

    标签: xcode continuous-integration xctest xcodebuild github-actions


    【解决方案1】:

    您需要返回一个非零值才能使该步骤失败。 尝试将此添加到xcodebuild 命令。

    xcodebuild -... || exit 1
    

    在下面的问题中,除此之外还有一些其他的解决方案。 How to get the return value of xcodebuild?

    更新:根据您希望之后完成的步骤,您可以执行以下操作。

    更改您的脚本以设置包含xcodebuild 命令结果的输出。

        xcodebuild \
           -workspace MyApp.xcworkspace \
           -scheme DEBUG\ -\ MyApp \
           -destination 'platform=iOS Simulator,name=iPhone 11' \
           test
        echo "::set-output name=result::$?"
    

    在执行此脚本的步骤中添加id

        - name: Test
          id: xcodebuild
          run: ./pipelines.sh test
    

    在您的工作流程结束时,您可以检查测试是否通过和失败的工作流程。

          - name: Check Tests Passed
            if: steps.xcodebuild.outputs.result != 0
            run: exit 1
    

    【讨论】:

    • 当我创建 xcodebuild -... || exit 1 时,如果我有一些命令,则不会执行此行之后的命令
    • 步骤Save report未在管道中执行
    • @KevinABRIOUX 使用解决方案更新了答案,以允许执行进一步的步骤并在之后失败。
    猜你喜欢
    • 2020-10-26
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-14
    • 2015-02-04
    • 2015-05-22
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多