Skip to content

Commit f4292ff

Browse files
authored
[MOB-11000] CI Reporting (#907)
1 parent 31f8629 commit f4292ff

File tree

3 files changed

+1183
-1
lines changed

3 files changed

+1183
-1
lines changed

.github/workflows/build-and-test.yml

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
with:
1414
xcode-version: latest-stable
1515

16+
- name: Setup Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.x'
20+
1621
- name: Setup Ruby and xcpretty
1722
run: |
1823
gem install erb
@@ -25,8 +30,82 @@ jobs:
2530
run: |
2631
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]}
2732
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+
28105
- name: CocoaPods lint
29106
run: pod lib lint --allow-warnings
30107

31108
- 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

Comments
 (0)