|
13 | 13 | with:
|
14 | 14 | xcode-version: latest-stable
|
15 | 15 |
|
| 16 | + - name: Setup Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: '3.x' |
| 20 | + |
16 | 21 | - name: Setup Ruby and xcpretty
|
17 | 22 | run: |
|
18 | 23 | gem install erb
|
|
25 | 30 | run: |
|
26 | 31 | xcodebuild test -project swift-sdk.xcodeproj -scheme swift-sdk -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16 Pro,OS=18.2' -enableCodeCoverage YES -resultBundlePath TestResults.xcresult CODE_SIGNING_REQUIRED=NO | xcpretty && exit ${PIPESTATUS[0]}
|
27 | 32 |
|
| 33 | + - name: Process test results |
| 34 | + run: | |
| 35 | + python3 scripts/process_xcresult.py --path TestResults.xcresult --test-output test-results.html --coverage-output coverage-results.html --test-plan tests/swift-sdk.xctestplan --summary-json test-summary.json --commit-sha ${{ github.sha }} |
| 36 | + if: success() || failure() |
| 37 | + |
| 38 | + - name: Create Test Report Check |
| 39 | + uses: actions/github-script@v7 |
| 40 | + if: success() || failure() |
| 41 | + with: |
| 42 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + script: | |
| 44 | + const fs = require('fs'); |
| 45 | + |
| 46 | + // Read the test results and coverage reports |
| 47 | + let testReport = ""; |
| 48 | + let coverageReport = ""; |
| 49 | + |
| 50 | + try { |
| 51 | + testReport = fs.readFileSync("test-results.html", 'utf8'); |
| 52 | + coverageReport = fs.readFileSync("coverage-results.html", 'utf8'); |
| 53 | + } catch (error) { |
| 54 | + core.warning(`Error reading report files: ${error.message}`); |
| 55 | + } |
| 56 | + |
| 57 | + // Read test summary |
| 58 | + let testStats = { |
| 59 | + total_tests: 0, |
| 60 | + passed_tests: 0, |
| 61 | + failed_tests: 0, |
| 62 | + success_rate: 0 |
| 63 | + }; |
| 64 | + |
| 65 | + try { |
| 66 | + const summaryJson = fs.readFileSync("test-summary.json", 'utf8'); |
| 67 | + testStats = JSON.parse(summaryJson); |
| 68 | + |
| 69 | + // Generate simple markdown summary |
| 70 | + fs.writeFileSync("report-summary.md", |
| 71 | + `# Test Results\n\n` + |
| 72 | + `- Total: ${testStats.total_tests}\n` + |
| 73 | + `- Passed: ${testStats.passed_tests}\n` + |
| 74 | + `- Failed: ${testStats.failed_tests}\n` + |
| 75 | + `- Success: ${(testStats.success_rate).toFixed(1)}%\n` |
| 76 | + ); |
| 77 | + } catch (error) { |
| 78 | + core.warning(`Error reading test summary: ${error.message}`); |
| 79 | + } |
| 80 | +
|
| 81 | + |
| 82 | + // Extract just the main content from the HTML - removing the HTML tags |
| 83 | + function stripHtml(html) { |
| 84 | + // Simple regex to extract text content from HTML |
| 85 | + return html |
| 86 | + .replace(/<h2>[\s\S]*?<\/h2>/gi, '') |
| 87 | + .trim(); |
| 88 | + } |
| 89 | + |
| 90 | + // Create the check with test results as summary and coverage as details |
| 91 | + await github.rest.checks.create({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + name: 'Unit Test Results', |
| 95 | + head_sha: context.payload.pull_request?.head.sha || context.sha, |
| 96 | + status: 'completed', |
| 97 | + conclusion: testStats.failed_tests > 0 ? 'failure' : 'success', |
| 98 | + output: { |
| 99 | + title: `Tests: ${testStats.passed_tests}/${testStats.passed_tests + testStats.failed_tests} passed (${(testStats.success_rate).toFixed(1)}%) Skipped: ${testStats.skipped_tests}`, |
| 100 | + summary: stripHtml(testReport.substring(0, 65000)), |
| 101 | + text: stripHtml(coverageReport.substring(0, 65000)) |
| 102 | + } |
| 103 | + }); |
| 104 | +
|
28 | 105 | - name: CocoaPods lint
|
29 | 106 | run: pod lib lint --allow-warnings
|
30 | 107 |
|
31 | 108 | - name: Upload coverage report to codecov.io
|
32 |
| - run: bash <(curl -s https://codecov.io/bash) -X gcov -J 'IterableSDK' -J 'IterableAppExtensions' |
| 109 | + env: |
| 110 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 111 | + run: bash <(curl -s https://codecov.io/bash) -X gcov -J 'IterableSDK' -J 'IterableAppExtensions' -B main -C ${{ github.sha }} -r ${{ github.repository }} |
0 commit comments