Skip to content

Commit d844473

Browse files
committed
trying patch coverage
1 parent 79373c9 commit d844473

File tree

1 file changed

+120
-2
lines changed

1 file changed

+120
-2
lines changed

β€Ž.github/workflows/pr-code-coverage.ymlβ€Ž

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,107 @@ jobs:
184184
exit 1
185185
fi
186186
187+
# - name: Comment coverage summary on PR
188+
# uses: marocchino/sticky-pull-request-comment@v2
189+
# with:
190+
# header: Code Coverage Report
191+
# message: |
192+
# # πŸ“Š Code Coverage Report
193+
194+
# <table>
195+
# <tr>
196+
# <td align="center" width="200">
197+
198+
# ### 🎯 Coverage
199+
# ### **${{ env.COVERAGE_PERCENTAGE }}**
200+
# <br>
201+
# </td>
202+
# <td>
203+
204+
# **πŸ“ˆ Lines Covered:** `${{ env.COVERED_LINES }}` out of `${{ env.TOTAL_LINES }}`
205+
# **πŸ“ Project:** `mssql-python`
206+
207+
# </td>
208+
# </tr>
209+
# </table>
210+
211+
# ---
212+
213+
# ### πŸ“‹ Files Needing Attention
214+
# <details>
215+
# <summary>πŸ“‰ <strong>Files with lowest coverage</strong> (click to expand)</summary>
216+
# <br>
217+
218+
# ```diff
219+
# ${{ env.LOW_COVERAGE_FILES }}
220+
# ```
221+
222+
# </details>
223+
224+
# ---
225+
# ### πŸ”— Quick Links
226+
227+
# <table>
228+
# <tr>
229+
# <td align="left" width="200">
230+
# <b>βš™οΈ Build Summary</b>
231+
# </td>
232+
# <td align="left">
233+
# <b>πŸ“‹ Coverage Details</b>
234+
# </td>
235+
# </tr>
236+
# <tr>
237+
# <td align="left" width="200">
238+
239+
# [View Azure DevOps Build](${{ env.ADO_URL }})
240+
241+
# </td>
242+
# <td align="left">
243+
244+
# [Browse Full Coverage Report](${{ env.ADO_URL }}&view=codecoverage-tab)
245+
246+
# </td>
247+
# </tr>
248+
# </table>
249+
250+
- name: Download coverage XML from ADO
251+
run: |
252+
# Download the Cobertura XML directly instead of HTML
253+
BUILD_ID=${{ env.BUILD_ID }}
254+
ARTIFACTS_URL="https://dev.azure.com/SqlClientDrivers/public/_apis/build/builds/$BUILD_ID/artifacts?api-version=7.1-preview.5"
255+
256+
# Find and download coverage.xml
257+
ARTIFACTS_RESPONSE=$(curl -s "$ARTIFACTS_URL")
258+
COVERAGE_XML_ARTIFACT=$(echo "$ARTIFACTS_RESPONSE" | jq -r '.value[]? | select(.name | test("coverage")) | .resource.downloadUrl // empty' 2>/dev/null)
259+
260+
if [[ -n "$COVERAGE_XML_ARTIFACT" ]]; then
261+
curl -L "$COVERAGE_XML_ARTIFACT" -o coverage-artifacts.zip
262+
unzip -q coverage-artifacts.zip
263+
find . -name "coverage*.xml" -exec cp {} ./coverage.xml \;
264+
fi
265+
266+
- name: Generate patch coverage report
267+
run: |
268+
# Install diff-cover and jq
269+
pip install diff-cover jq
270+
# Generate diff coverage report comparing against main
271+
diff-cover coverage.xml \
272+
--compare-branch=origin/main \
273+
--html-report=patch-coverage.html \
274+
--json-report=patch-coverage.json \
275+
--markdown-report=patch-coverage.md
276+
277+
# Extract patch coverage percentage
278+
PATCH_COVERAGE=$(jq -r '.total_percent_covered // "N/A"' patch-coverage.json)
279+
echo "PATCH_COVERAGE_PCT=${PATCH_COVERAGE}%" >> $GITHUB_ENV
280+
281+
# Extract summary for comment
282+
if [[ -f patch-coverage.md ]]; then
283+
echo "PATCH_COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV
284+
cat patch-coverage.md >> $GITHUB_ENV
285+
echo "EOF" >> $GITHUB_ENV
286+
fi
287+
187288
- name: Comment coverage summary on PR
188289
uses: marocchino/sticky-pull-request-comment@v2
189290
with:
@@ -195,10 +296,16 @@ jobs:
195296
<tr>
196297
<td align="center" width="200">
197298
198-
### 🎯 Coverage
299+
### 🎯 Overall Coverage
199300
### **${{ env.COVERAGE_PERCENTAGE }}**
200301
<br>
201302
</td>
303+
<td align="center" width="200">
304+
305+
### πŸ”₯ Patch Coverage
306+
### **${{ env.PATCH_COVERAGE_PCT }}**
307+
<br>
308+
</td>
202309
<td>
203310
204311
**πŸ“ˆ Lines Covered:** `${{ env.COVERED_LINES }}` out of `${{ env.TOTAL_LINES }}`
@@ -211,6 +318,17 @@ jobs:
211318
---
212319
213320
### πŸ“‹ Files Needing Attention
321+
322+
<details>
323+
<summary>🎯 <strong>Patch Coverage Details</strong> (lines changed in this PR)</summary>
324+
<br>
325+
326+
> **Patch Coverage** shows the percentage of **newly added or modified lines** that are covered by tests.
327+
328+
${{ env.PATCH_COVERAGE_SUMMARY }}
329+
330+
</details>
331+
214332
<details>
215333
<summary>πŸ“‰ <strong>Files with lowest coverage</strong> (click to expand)</summary>
216334
<br>
@@ -245,4 +363,4 @@ jobs:
245363
246364
</td>
247365
</tr>
248-
</table>
366+
</table>

0 commit comments

Comments
Β (0)