Skip to content

Commit 03aac5d

Browse files
authored
Merge pull request #59 from kmatzen/ci/code-coverage
Add code coverage reporting to CI
2 parents aad39ed + 6dfc3a6 commit 03aac5d

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,34 @@ jobs:
4141
-only-testing:FacettTests/GoProCommandTests \
4242
-only-testing:FacettTests/SettingsTests \
4343
-only-testing:FacettTests/StateMachineTests \
44-
-quiet
44+
-enableCodeCoverage YES \
45+
-resultBundlePath TestResults.xcresult
46+
47+
- name: Code Coverage Summary
48+
if: always()
49+
run: |
50+
if [ -d TestResults.xcresult ]; then
51+
xcrun xccov view --report --json TestResults.xcresult > coverage.json
52+
echo "## Code Coverage" >> $GITHUB_STEP_SUMMARY
53+
echo "" >> $GITHUB_STEP_SUMMARY
54+
python3 -c "
55+
import json, sys
56+
with open('coverage.json') as f:
57+
data = json.load(f)
58+
targets = data.get('targets', [])
59+
for t in targets:
60+
name = t.get('name', '')
61+
if name == 'Facett.app':
62+
pct = t.get('lineCoverage', 0) * 100
63+
print(f'**{name}**: {pct:.1f}% line coverage')
64+
sys.stdout.flush()
65+
files = t.get('files', [])
66+
covered = [(f['name'], f['lineCoverage'] * 100) for f in files if f.get('lineCoverage', 0) > 0]
67+
covered.sort(key=lambda x: -x[1])
68+
print()
69+
print('| File | Coverage |')
70+
print('|------|----------|')
71+
for fname, cov in covered[:20]:
72+
print(f'| {fname} | {cov:.1f}% |')
73+
" >> $GITHUB_STEP_SUMMARY
74+
fi

0 commit comments

Comments
 (0)