|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + SCHEME: C2PAExample |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + name: ${{ matrix.device }} Xcode ${{ matrix.xcode }} |
| 15 | + runs-on: macos-14 |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + xcode: ["16.1"] |
| 20 | + device: |
| 21 | + [ |
| 22 | + "iPhone 16 Pro", |
| 23 | + "iPhone 16", |
| 24 | + "iPhone SE (3rd generation)", |
| 25 | + "iPad Pro 11-inch (M4)", |
| 26 | + ] |
| 27 | + ios: ["18.1"] |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Xcode ${{ matrix.xcode }} |
| 33 | + uses: maxim-lobanov/setup-xcode@v1 |
| 34 | + with: |
| 35 | + xcode-version: ${{ matrix.xcode }} |
| 36 | + |
| 37 | + - name: Verify Xcode version |
| 38 | + run: xcodebuild -version |
| 39 | + |
| 40 | + - name: Build iOS Framework |
| 41 | + run: make ios-framework |
| 42 | + |
| 43 | + - name: Build & test |
| 44 | + run: | |
| 45 | + set -eo pipefail |
| 46 | + cd example |
| 47 | + xcrun xcodebuild test \ |
| 48 | + -project C2PAExample.xcodeproj \ |
| 49 | + -scheme "$SCHEME" \ |
| 50 | + -sdk iphonesimulator \ |
| 51 | + -destination "platform=iOS Simulator,name=${{ matrix.device }},OS=${{ matrix.ios }}" \ |
| 52 | + -resultBundlePath TestResults \ |
| 53 | + -enableCodeCoverage YES \ |
| 54 | + | xcpretty --test --color |
| 55 | +
|
| 56 | + - name: Generate test summary |
| 57 | + run: | |
| 58 | + cd example |
| 59 | + xcrun xcresulttool get test-results summary --path TestResults.xcresult || true |
| 60 | + xcrun xcresulttool get object --path TestResults.xcresult --format json > test-results.json || true |
| 61 | + xcrun xcresulttool get test-results tests --path TestResults.xcresult || true |
| 62 | +
|
| 63 | + - name: Upload test summary |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: TestSummary-${{ matrix.xcode }}-${{ matrix.device }} |
| 67 | + path: example/test-results.json |
| 68 | + |
| 69 | + - name: Export coverage LCOV |
| 70 | + if: success() |
| 71 | + run: | |
| 72 | + cd example |
| 73 | +
|
| 74 | + # Get DerivedData path from xcodebuild |
| 75 | + DERIVED_DATA=$(xcodebuild -showBuildSettings -project C2PAExample.xcodeproj -scheme C2PAExample -sdk iphonesimulator | grep -m 1 " BUILD_DIR " | sed 's/.*= //' | sed 's|/Build/Products||') |
| 76 | + echo "Derived data path: $DERIVED_DATA" |
| 77 | +
|
| 78 | + # Find Coverage.profdata |
| 79 | + PROFDATA_PATH="" |
| 80 | + if [ -n "$DERIVED_DATA" ]; then |
| 81 | + PROFDATA_PATH=$(find "$DERIVED_DATA/Build/ProfileData" -name "Coverage.profdata" -type f 2>/dev/null | head -1 || true) |
| 82 | + fi |
| 83 | +
|
| 84 | + # Method 2: If not found, look in common CI locations |
| 85 | + if [ -z "$PROFDATA_PATH" ]; then |
| 86 | + PROFDATA_PATH=$(find ~/Library/Developer/Xcode/DerivedData -path "*/Build/ProfileData/*/Coverage.profdata" -type f 2>/dev/null | grep -i c2paexample | head -1 || true) |
| 87 | + fi |
| 88 | +
|
| 89 | + echo "Coverage.profdata path: $PROFDATA_PATH" |
| 90 | +
|
| 91 | + # Find the test binary |
| 92 | + TEST_BINARY_PATH="" |
| 93 | + if [ -n "$DERIVED_DATA" ]; then |
| 94 | + TEST_BINARY_PATH=$(find "$DERIVED_DATA/Build/Products" -path "*/C2PAExampleTests.xctest/C2PAExampleTests" -type f 2>/dev/null | head -1 || true) |
| 95 | + fi |
| 96 | +
|
| 97 | + # If not found, search more broadly |
| 98 | + if [ -z "$TEST_BINARY_PATH" ]; then |
| 99 | + TEST_BINARY_PATH=$(find ~/Library/Developer/Xcode/DerivedData -path "*/C2PAExampleTests.xctest/C2PAExampleTests" -type f 2>/dev/null | grep -i c2paexample | head -1 || true) |
| 100 | + fi |
| 101 | +
|
| 102 | + echo "Test binary path: $TEST_BINARY_PATH" |
| 103 | +
|
| 104 | + # Try to generate LCOV if we have both files |
| 105 | + if [ -n "$PROFDATA_PATH" ] && [ -n "$TEST_BINARY_PATH" ]; then |
| 106 | + # Export to LCOV format |
| 107 | + # Use a sanitized filename to avoid shell issues with special characters |
| 108 | + DEVICE_NAME="${{ matrix.device }}" |
| 109 | + SANITIZED_DEVICE=$(echo "$DEVICE_NAME" | tr ' ()' '---') |
| 110 | +
|
| 111 | + xcrun llvm-cov export \ |
| 112 | + -format=lcov \ |
| 113 | + -instr-profile="$PROFDATA_PATH" \ |
| 114 | + "$TEST_BINARY_PATH" \ |
| 115 | + > "../coverage-${{ matrix.xcode }}-${SANITIZED_DEVICE}.lcov" |
| 116 | +
|
| 117 | + echo "LCOV coverage report generated successfully" |
| 118 | + else |
| 119 | + echo "ERROR: Could not generate LCOV report - missing profdata or binary" |
| 120 | + echo "PROFDATA_PATH: $PROFDATA_PATH" |
| 121 | + echo "TEST_BINARY_PATH: $TEST_BINARY_PATH" |
| 122 | + exit 1 |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Upload coverage report to GitHub |
| 126 | + if: success() |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: coverage-${{ matrix.xcode }}-${{ matrix.device }} |
| 130 | + path: coverage-*.lcov |
| 131 | + |
| 132 | + - name: Upload coverage report to Codecov |
| 133 | + if: success() |
| 134 | + uses: codecov/codecov-action@v5 |
| 135 | + with: |
| 136 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 137 | + slug: contentauth/c2pa-ios |
0 commit comments