|
1 |
| -# This workflow builds an iPhone app using Xcode |
2 |
| -name: Build iPhone App |
| 1 | +name: Build & Test iPhone App |
3 | 2 |
|
4 | 3 | on:
|
5 | 4 | push:
|
6 | 5 | branches: [ "main" ]
|
7 | 6 | pull_request:
|
8 |
| - branches: [ "main" ] |
9 | 7 |
|
10 | 8 | jobs:
|
11 | 9 | build:
|
12 | 10 | runs-on: macos-latest
|
| 11 | + env: |
| 12 | + XCODE_VERSION_PATH: "/Applications/Xcode_16.1.app" |
| 13 | + WORKSPACE: "ophelia/ophelia.xcodeproj/project.xcworkspace" |
| 14 | + SCHEME: "ophelia" |
| 15 | + DESTINATION: "platform=iOS Simulator,name=iPhone 16,OS=18.1" |
| 16 | + CACHE_KEY_PREFIX: "ophelia-xcode-cache" |
13 | 17 |
|
14 | 18 | steps:
|
15 |
| - # Check out the repository |
16 | 19 | - name: Check Out Code
|
17 | 20 | uses: actions/checkout@v4
|
| 21 | + with: |
| 22 | + fetch-depth: 1 |
18 | 23 |
|
19 |
| - # Select Xcode 16.1 |
20 | 24 | - name: Select Xcode Version
|
21 |
| - run: sudo xcode-select -switch /Applications/Xcode_16.1.app |
| 25 | + run: sudo xcode-select -switch $XCODE_VERSION_PATH |
22 | 26 |
|
23 |
| - # Check Xcode version and list simulators |
24 | 27 | - name: Debug Environment
|
25 | 28 | run: |
|
26 | 29 | echo "Xcode Version:"
|
27 | 30 | xcodebuild -version
|
28 | 31 | echo "Available Simulators:"
|
29 | 32 | xcrun simctl list
|
30 | 33 |
|
31 |
| - # Ensure DerivedData directory exists |
32 |
| - - name: Ensure DerivedData Exists |
33 |
| - run: mkdir -p ~/Library/Developer/Xcode/DerivedData |
34 |
| - |
35 |
| - # Cache DerivedData |
| 34 | + # Use a stable cache key to maximize cache hits based on the project files. |
36 | 35 | - name: Cache DerivedData
|
37 | 36 | uses: actions/cache@v3
|
38 | 37 | with:
|
39 | 38 | path: ~/Library/Developer/Xcode/DerivedData
|
40 |
| - key: ${{ runner.os }}-xcode-${{ github.sha }} |
| 39 | + key: ${{ env.CACHE_KEY_PREFIX }}-${{ runner.os }}-${{ hashFiles('ophelia/ophelia.xcodeproj/**', 'Package.resolved') }} |
41 | 40 | restore-keys: |
|
42 |
| - ${{ runner.os }}-xcode- |
| 41 | + ${{ env.CACHE_KEY_PREFIX }}-${{ runner.os }}- |
43 | 42 |
|
44 |
| - # List project files for debugging |
45 |
| - - name: List Project Directory |
46 |
| - run: ls -R ophelia |
47 |
| - |
48 |
| - # Build the app |
49 | 43 | - name: Build App
|
50 | 44 | run: |
|
51 |
| - xcodebuild -workspace ophelia/ophelia.xcodeproj/project.xcworkspace \ |
52 |
| - -scheme ophelia \ |
53 |
| - -sdk iphonesimulator \ |
54 |
| - -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.1' \ |
55 |
| - build |
56 |
| -
|
57 |
| - # Debug DerivedData if build fails |
58 |
| - - name: Check Derived Data |
| 45 | + set -o pipefail && xcodebuild \ |
| 46 | + -workspace "$WORKSPACE" \ |
| 47 | + -scheme "$SCHEME" \ |
| 48 | + -sdk iphonesimulator \ |
| 49 | + -destination "$DESTINATION" \ |
| 50 | + build | xcpretty |
| 51 | + shell: bash |
| 52 | + |
| 53 | + # Upload logs if build fails for debugging |
| 54 | + - name: Upload Logs on Failure |
59 | 55 | if: failure()
|
| 56 | + uses: actions/upload-artifact@v3 |
| 57 | + with: |
| 58 | + name: build-logs |
| 59 | + path: ~/Library/Logs/DiagnosticReports/ |
| 60 | + |
| 61 | + test: |
| 62 | + runs-on: macos-latest |
| 63 | + needs: build |
| 64 | + env: |
| 65 | + XCODE_VERSION_PATH: "/Applications/Xcode_16.1.app" |
| 66 | + WORKSPACE: "ophelia/ophelia.xcodeproj/project.xcworkspace" |
| 67 | + SCHEME: "ophelia" |
| 68 | + DESTINATION: "platform=iOS Simulator,name=iPhone 16,OS=18.1" |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Check Out Code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Select Xcode Version |
| 75 | + run: sudo xcode-select -switch $XCODE_VERSION_PATH |
| 76 | + |
| 77 | + - name: Run Tests |
60 | 78 | run: |
|
61 |
| - echo "DerivedData Directory:" |
62 |
| - ls ~/Library/Developer/Xcode/DerivedData || echo "DerivedData not found" |
| 79 | + set -o pipefail && xcodebuild \ |
| 80 | + -workspace "$WORKSPACE" \ |
| 81 | + -scheme "$SCHEME" \ |
| 82 | + -sdk iphonesimulator \ |
| 83 | + -destination "$DESTINATION" \ |
| 84 | + test | xcpretty |
| 85 | + shell: bash |
| 86 | + |
| 87 | + - name: Upload Test Results on Failure |
| 88 | + if: failure() |
| 89 | + uses: actions/upload-artifact@v3 |
| 90 | + with: |
| 91 | + name: test-logs |
| 92 | + path: ~/Library/Logs/DiagnosticReports/ |
0 commit comments