|
| 1 | +name: Test iOS Builds |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - "samples/ios/**" |
| 7 | + - ".github/workflows/test-ios.yml" |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - "samples/ios/**" |
| 11 | + - ".github/workflows/test-ios.yml" |
| 12 | + schedule: |
| 13 | + - cron: "0 10 * * 1" |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + find-projects: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + matrix: ${{ steps.find.outputs.matrix }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v6 |
| 26 | + - id: find |
| 27 | + # Each iOS sample is identified by its project.yml (xcodegen input). We use |
| 28 | + # that as the marker rather than the generated .xcodeproj because the |
| 29 | + # project.yml is the authoritative source — generated files come and go. |
| 30 | + run: | |
| 31 | + DIRS=$(find samples/ios -mindepth 2 -maxdepth 2 -name "project.yml" -exec dirname {} \; 2>/dev/null | sort | jq -R -s -c 'split("\n") | map(select(. != ""))') |
| 32 | + echo "matrix=$DIRS" >> "$GITHUB_OUTPUT" |
| 33 | +
|
| 34 | + test: |
| 35 | + needs: find-projects |
| 36 | + if: ${{ needs.find-projects.outputs.matrix != '[]' }} |
| 37 | + runs-on: macos-latest |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + matrix: |
| 41 | + project: ${{ fromJson(needs.find-projects.outputs.matrix) }} |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v6 |
| 44 | + |
| 45 | + # Config.xcconfig is gitignored — copy the example so build settings have |
| 46 | + # placeholder values. No real CIAM workspace is needed for build + unit tests |
| 47 | + # (network-touching paths only execute in the running app). |
| 48 | + - name: Provision example xcconfig |
| 49 | + working-directory: ${{ matrix.project }} |
| 50 | + run: cp Config.example.xcconfig Config.xcconfig |
| 51 | + |
| 52 | + # Pre-fetch Swift Package Manager deps (AppAuth-iOS) so the test step doesn't |
| 53 | + # also pay the resolution cost — makes failures during dep resolution easier |
| 54 | + # to spot in logs. |
| 55 | + - name: Resolve SPM dependencies |
| 56 | + working-directory: ${{ matrix.project }} |
| 57 | + run: xcodebuild -resolvePackageDependencies -project Quickstart.xcodeproj -scheme Quickstart |
| 58 | + |
| 59 | + # GitHub-hosted macOS runners ship multiple iPhone simulators. We pick the |
| 60 | + # first available one rather than hard-coding a name so the workflow keeps |
| 61 | + # working as Apple updates the runner image / device catalogue. |
| 62 | + - name: Pick iOS simulator |
| 63 | + id: sim |
| 64 | + run: | |
| 65 | + DEVICE=$(xcrun simctl list devices available --json | jq -r ' |
| 66 | + .devices |
| 67 | + | to_entries[] |
| 68 | + | select(.key | test("com.apple.CoreSimulator.SimRuntime.iOS")) |
| 69 | + | .value[] |
| 70 | + | select(.name | startswith("iPhone")) |
| 71 | + | .name |
| 72 | + ' | head -1) |
| 73 | + if [ -z "$DEVICE" ]; then |
| 74 | + echo "No iPhone simulator found"; exit 1 |
| 75 | + fi |
| 76 | + echo "Selected: $DEVICE" |
| 77 | + echo "name=$DEVICE" >> "$GITHUB_OUTPUT" |
| 78 | +
|
| 79 | + - name: Build and test |
| 80 | + working-directory: ${{ matrix.project }} |
| 81 | + run: | |
| 82 | + xcodebuild test \ |
| 83 | + -project Quickstart.xcodeproj \ |
| 84 | + -scheme Quickstart \ |
| 85 | + -destination "platform=iOS Simulator,name=${{ steps.sim.outputs.name }}" \ |
| 86 | + CODE_SIGNING_ALLOWED=NO |
| 87 | +
|
| 88 | + # Stable aggregator for branch protection. |
| 89 | + all-tests-passed: |
| 90 | + name: iOS tests passed |
| 91 | + needs: test |
| 92 | + if: always() |
| 93 | + runs-on: ubuntu-latest |
| 94 | + steps: |
| 95 | + - name: Verify test matrix succeeded |
| 96 | + if: needs.test.result != 'success' && needs.test.result != 'skipped' |
| 97 | + run: exit 1 |
0 commit comments