-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (140 loc) · 5.8 KB
/
Copy pathcoverage.yml
File metadata and controls
158 lines (140 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: KeyPath Coverage
on:
schedule:
- cron: '30 8 * * *'
workflow_dispatch:
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
jobs:
narrow-coverage:
runs-on: [self-hosted, macOS, keypath]
timeout-minutes: 10
env:
COVERAGE_BASELINE_PERCENT: "0.27"
COVERAGE_TOLERANCE_PERCENT: "0.01"
steps:
- name: Clean stale git credentials
run: |
git config --global --unset-all http.https://github.com/.extraheader 2>/dev/null || true
git config --global --unset-all url.https://github.com/.insteadof 2>/dev/null || true
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
persist-credentials: false
- name: Add Homebrew to PATH
run: echo "/opt/homebrew/bin" >> $GITHUB_PATH
- name: Generate coverage
timeout-minutes: 5
env:
KP_SIGN_DRY_RUN: "1"
CI_ENVIRONMENT: "true"
SKIP_EVENT_TAP_TESTS: "1"
run: |
echo "Generating narrow-lane coverage..."
swift test --enable-code-coverage --filter 'KeyPathErrorTests|PermissionOracleTests'
chmod +x ./Scripts/generate-coverage.sh
./Scripts/generate-coverage.sh coverage
- name: Enforce coverage non-regression
run: |
echo "Enforcing narrow-lane coverage floor (${COVERAGE_BASELINE_PERCENT}%)..."
if [ ! -f "coverage/coverage-summary.txt" ]; then
echo "Missing coverage/coverage-summary.txt"
exit 1
fi
ACTUAL_COVERAGE=$(awk '/^TOTAL/ {for(i=1;i<=NF;i++) if ($i ~ /%$/) {gsub("%","",$i); print $i; exit}}' coverage/coverage-summary.txt)
if [ -z "${ACTUAL_COVERAGE}" ]; then
echo "Could not parse TOTAL coverage from coverage/coverage-summary.txt"
cat coverage/coverage-summary.txt
exit 1
fi
echo "Coverage (narrow lane): ${ACTUAL_COVERAGE}%"
EFFECTIVE_FLOOR=$(awk -v baseline="${COVERAGE_BASELINE_PERCENT}" -v tol="${COVERAGE_TOLERANCE_PERCENT}" 'BEGIN {printf "%.2f", baseline - tol}')
if awk -v actual="${ACTUAL_COVERAGE}" -v floor="${EFFECTIVE_FLOOR}" 'BEGIN {exit !(actual + 0 >= floor + 0)}'; then
echo "Coverage is non-regressing (>= ${EFFECTIVE_FLOOR}% effective floor)"
else
echo "Coverage regression: ${ACTUAL_COVERAGE}% < ${EFFECTIVE_FLOOR}% effective floor"
exit 1
fi
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
if-no-files-found: ignore
retention-days: 14
- name: Generate coverage summary
if: always()
run: |
echo "## Coverage (narrow lane)" >> $GITHUB_STEP_SUMMARY
if [ -f "coverage/coverage-summary.txt" ]; then
echo "- Summary: \`$(cat coverage/coverage-summary.txt)\`" >> $GITHUB_STEP_SUMMARY
echo "- Enforced narrow-lane floor: \`${COVERAGE_BASELINE_PERCENT}%\`" >> $GITHUB_STEP_SUMMARY
else
echo "- Coverage not generated." >> $GITHUB_STEP_SUMMARY
fi
# Visibility-only: runs the WHOLE suite under coverage instrumentation and
# reports real numbers (total + the core business-logic files). It does NOT
# enforce a floor yet — the narrow lane above is the only gate. Once these
# numbers are trusted, a realistic per-file floor can be added here.
full-coverage:
runs-on: [self-hosted, macOS, keypath]
# Sequence after the narrow lane: the two jobs share the self-hosted runner's
# workspace/.build, so running them in parallel risks clobbering each other's
# default.profdata (CLAUDE.md: avoid concurrent broad Swift builds). `needs`
# serializes them; `if: always()` still surfaces full numbers when the narrow
# floor regresses or a filtered test fails.
needs: [narrow-coverage]
if: always()
timeout-minutes: 40
steps:
- name: Clean stale git credentials
run: |
git config --global --unset-all http.https://github.com/.extraheader 2>/dev/null || true
git config --global --unset-all url.https://github.com/.insteadof 2>/dev/null || true
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
persist-credentials: false
- name: Add Homebrew to PATH
run: echo "/opt/homebrew/bin" >> $GITHUB_PATH
- name: Generate full-suite coverage
timeout-minutes: 30
env:
KP_SIGN_DRY_RUN: "1"
CI_ENVIRONMENT: "true"
SKIP_EVENT_TAP_TESTS: "1"
run: |
echo "Generating full-suite coverage (no filter)..."
swift test --enable-code-coverage
chmod +x ./Scripts/generate-coverage.sh
./Scripts/generate-coverage.sh coverage-full
- name: Upload full coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-full
path: coverage-full/
if-no-files-found: ignore
retention-days: 14
- name: Report full coverage
if: always()
run: |
echo "## Coverage (full suite — visibility only, not enforced)" >> $GITHUB_STEP_SUMMARY
if [ -f "coverage-full/coverage-summary.txt" ]; then
echo "- Total: \`$(cat coverage-full/coverage-summary.txt)\`" >> $GITHUB_STEP_SUMMARY
else
echo "- Coverage not generated." >> $GITHUB_STEP_SUMMARY
fi
if [ -s "coverage-full/coverage-core.txt" ]; then
{
echo ""
echo "### Core business-logic files"
echo '```'
cat "coverage-full/coverage-core.txt"
echo '```'
} >> $GITHUB_STEP_SUMMARY
fi