1

I need to build an Xcode project with pods, run tests, and if tests are failing => fail workflow. If tests are passed => upload the report to Codecov.

Currently, it doesn't matter if tests are passed or failed, the workflow will be marked as passed successfully anyway.

This is my workflow:

name: Test
on:
  pull_request:
    branches:
      - debug
jobs:
  xcode-tests:
    name: "Select OS"
    runs-on: macos-14-xlarge

    steps:
    - name: Checkout
      uses: actions/checkout@master

    - name: Select Xcode
      run: sudo xcode-select -switch /Applications/Xcode_15.2.app && /usr/bin/xcodebuild -version

    - name: Cache Cocoapods
      id: cache-cocoapods
      uses: actions/cache@v2
      with:
        path: Pods
        key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-pods-

    - name: Install Cocoapods
      run: pod install --repo-update

    - name: Build and Test
      env:
        scheme: ${{ 'ExampleApp' }}
        platform: ${{ 'iOS Simulator' }}
        device: ${{ 'iPhone 15' }}
        os_version: ${{ '17.4' }}
      run: xcodebuild test -workspace ExampleApp.xcworkspace -scheme ExampleApp -destination "platform=$platform,name=$device,OS=$os_version" -enableCodeCoverage YES build test | xcpretty --test

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
2
  • Did you try using xcodebuild ... || exit 1? This should return an error if the command fails. Otherwise, you could use a bash logic: xcodebuild ... if [[ $? == 0 ]]; then echo "Success" else echo "Failed" exit 1 fi (something like that) Commented May 8, 2024 at 12:13
  • Does this answer your question? Xcode test failing does not failed Github action pipeline Commented May 11, 2024 at 15:59

1 Answer 1

0

The easiest way to achieve that is set -o pipefail

If any command in the pipeline fails - the entire pipeline will fail - not just the last command.

set -o pipefail && xcodebuild ... | xcpretty --test

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.