Add GitHub Actions iOS CI workflow #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: iOS CI | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| pull_request: | |
| workflow_dispatch: | |
| concurrency: | |
| group: ios-ci-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-test: | |
| name: Build and Test (SOPA) | |
| runs-on: macos-15 | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Select Xcode | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: latest-stable | |
| - name: Show Xcode version | |
| run: | | |
| xcodebuild -version | |
| swift --version | |
| - name: Resolve Swift packages | |
| run: | | |
| xcodebuild \ | |
| -project SOPA.xcodeproj \ | |
| -scheme SOPA \ | |
| -resolvePackageDependencies | |
| - name: Find iOS simulator destination | |
| id: sim | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Pick the newest available iOS runtime on the runner. | |
| RUNTIME=$( | |
| xcrun simctl list runtimes available \ | |
| | awk -F'[()]' '/iOS [0-9]+/{print $2}' \ | |
| | tail -n 1 | |
| ) | |
| if [[ -z "${RUNTIME:-}" ]]; then | |
| echo "No iOS runtime found on this runner." | |
| xcrun simctl list runtimes available | |
| exit 1 | |
| fi | |
| # Prefer iPhone 16 to match local development, fallback to any available iPhone. | |
| DEVICE_UDID=$( | |
| xcrun simctl list devices available "${RUNTIME}" \ | |
| | awk -F'[()]' '/iPhone 16 /{print $2; exit}' | |
| ) | |
| if [[ -z "${DEVICE_UDID:-}" ]]; then | |
| DEVICE_UDID=$( | |
| xcrun simctl list devices available "${RUNTIME}" \ | |
| | awk -F'[()]' '/iPhone [0-9]+/{print $2; exit}' | |
| ) | |
| fi | |
| if [[ -z "${DEVICE_UDID:-}" ]]; then | |
| echo "No iPhone simulator found for runtime ${RUNTIME}." | |
| xcrun simctl list devices available "${RUNTIME}" | |
| exit 1 | |
| fi | |
| echo "destination=id=${DEVICE_UDID}" >> "$GITHUB_OUTPUT" | |
| echo "Using destination id=${DEVICE_UDID} on runtime ${RUNTIME}" | |
| - name: Build | |
| run: | | |
| xcodebuild \ | |
| -project SOPA.xcodeproj \ | |
| -scheme SOPA \ | |
| -destination '${{ steps.sim.outputs.destination }}' \ | |
| build | |
| - name: Test | |
| run: | | |
| xcodebuild \ | |
| -project SOPA.xcodeproj \ | |
| -scheme SOPA \ | |
| -destination '${{ steps.sim.outputs.destination }}' \ | |
| -resultBundlePath TestResults.xcresult \ | |
| test | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: xcresult | |
| path: TestResults.xcresult | |
| if-no-files-found: ignore |