Skip to content

Update CI script to dynamically select the latest available simulator #27

Update CI script to dynamically select the latest available simulator

Update CI script to dynamically select the latest available simulator #27

Workflow file for this run

name: CI
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: macOS-latest
env:
SCHEME: WeakMapTable
CODECOV_PACKAGE_NAME: WeakMapTable
strategy:
fail-fast: false
matrix:
env:
- sdk: iphonesimulator
- sdk: macosx
- sdk: appletvsimulator
steps:
- uses: actions/checkout@v4
- name: List SDKs and Devices
run: xcodebuild -showsdks; xcrun xctrace list devices
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Select iOS Simulator dynamically
if: matrix.env.sdk == 'iphonesimulator'
run: |
OS_VERSION=$(xcrun simctl list runtimes | grep 'iOS' | grep -oE '[0-9]+\.[0-9]+' | sort -Vr | head -n1)
DEVICE_NAME=$(xcrun simctl list devices | grep -A 20 "^-- iOS $OS_VERSION --" | grep -E '^ *iPhone [0-9]+ \(' | grep -v 'Pro\|Plus\|SE\|unavailable' | sed -E 's/^[[:space:]]*([^()]+) \(.*/\1/' | sort -t' ' -k2 -n -r | head -n1)
echo "Using simulator: $DEVICE_NAME (iOS $OS_VERSION)"
echo "DESTINATION=platform=iOS Simulator,name=$DEVICE_NAME,OS=$OS_VERSION" >> $GITHUB_ENV
- name: Set macOS destination
if: matrix.env.sdk == 'macosx'
run: echo "DESTINATION=arch=x86_64" >> $GITHUB_ENV
- name: Set tvOS destination
if: matrix.env.sdk == 'appletvsimulator'
run: echo "DESTINATION=platform=tvOS Simulator,name=Apple TV,OS=latest" >> $GITHUB_ENV
- name: Build and Test
run: |
set -o pipefail && xcodebuild build test \
-scheme "$SCHEME" \
-sdk "$SDK" \
-destination "$DESTINATION" \
-configuration Debug \
-enableCodeCoverage YES \
-resultBundlePath "./${{ matrix.env.sdk }}.xcresult" \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c;
env:
SDK: ${{ matrix.env.sdk }}
DESTINATION: ${{ env.DESTINATION }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0
with:
xcode: true
xcode_archive_path: "./${{ matrix.env.sdk }}.xcresult"