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 }}
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)