Skip to content

Commit b2a1ac6

Browse files
committed
testing
1 parent cdb94b2 commit b2a1ac6

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Post Coverage Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Code Coverage"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
post-comment:
11+
runs-on: ubuntu-latest
12+
if: >
13+
github.event.workflow_run.event == 'pull_request' &&
14+
github.event.workflow_run.conclusion == 'success'
15+
permissions:
16+
pull-requests: write
17+
contents: read
18+
19+
steps:
20+
- name: Download coverage data
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: coverage-comment-data
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
run-id: ${{ github.event.workflow_run.id }}
26+
27+
- name: Read coverage data
28+
id: coverage
29+
run: |
30+
if [[ ! -f pr-info.json ]]; then
31+
echo "❌ pr-info.json not found"
32+
exit 1
33+
fi
34+
35+
cat pr-info.json
36+
37+
# Extract values from JSON
38+
PR_NUMBER=$(jq -r '.pr_number' pr-info.json)
39+
COVERAGE_PCT=$(jq -r '.coverage_percentage' pr-info.json)
40+
COVERED_LINES=$(jq -r '.covered_lines' pr-info.json)
41+
TOTAL_LINES=$(jq -r '.total_lines' pr-info.json)
42+
PATCH_PCT=$(jq -r '.patch_coverage_pct' pr-info.json)
43+
LOW_COV_FILES=$(jq -r '.low_coverage_files' pr-info.json)
44+
PATCH_SUMMARY=$(jq -r '.patch_coverage_summary' pr-info.json)
45+
ADO_URL=$(jq -r '.ado_url' pr-info.json)
46+
47+
# Export to env for next step
48+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
49+
echo "COVERAGE_PERCENTAGE=$COVERAGE_PCT" >> $GITHUB_ENV
50+
echo "COVERED_LINES=$COVERED_LINES" >> $GITHUB_ENV
51+
echo "TOTAL_LINES=$TOTAL_LINES" >> $GITHUB_ENV
52+
echo "PATCH_COVERAGE_PCT=$PATCH_PCT" >> $GITHUB_ENV
53+
echo "ADO_URL=$ADO_URL" >> $GITHUB_ENV
54+
55+
# Handle multiline values
56+
echo "LOW_COVERAGE_FILES<<EOF" >> $GITHUB_ENV
57+
echo "$LOW_COV_FILES" >> $GITHUB_ENV
58+
echo "EOF" >> $GITHUB_ENV
59+
60+
echo "PATCH_COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV
61+
echo "$PATCH_SUMMARY" >> $GITHUB_ENV
62+
echo "EOF" >> $GITHUB_ENV
63+
64+
- name: Comment coverage summary on PR
65+
uses: marocchino/sticky-pull-request-comment@v2
66+
with:
67+
number: ${{ env.PR_NUMBER }}
68+
header: Code Coverage Report
69+
message: |
70+
# 📊 Code Coverage Report
71+
72+
<table>
73+
<tr>
74+
<td align="center" width="200">
75+
76+
### 🔥 Diff Coverage
77+
### **${{ env.PATCH_COVERAGE_PCT }}**
78+
<br>
79+
</td>
80+
<td align="center" width="200">
81+
82+
### 🎯 Overall Coverage
83+
### **${{ env.COVERAGE_PERCENTAGE }}**
84+
<br>
85+
</td>
86+
<td>
87+
88+
**📈 Total Lines Covered:** `${{ env.COVERED_LINES }}` out of `${{ env.TOTAL_LINES }}`
89+
**📁 Project:** `mssql-python`
90+
91+
</td>
92+
</tr>
93+
</table>
94+
95+
---
96+
97+
${{ env.PATCH_COVERAGE_SUMMARY }}
98+
99+
---
100+
### 📋 Files Needing Attention
101+
102+
<details>
103+
<summary>📉 <strong>Files with overall lowest coverage</strong> (click to expand)</summary>
104+
<br>
105+
106+
```diff
107+
${{ env.LOW_COVERAGE_FILES }}
108+
```
109+
110+
</details>
111+
112+
---
113+
### 🔗 Quick Links
114+
115+
<table>
116+
<tr>
117+
<td align="left" width="200">
118+
<b>⚙️ Build Summary</b>
119+
</td>
120+
<td align="left">
121+
<b>📋 Coverage Details</b>
122+
</td>
123+
</tr>
124+
<tr>
125+
<td align="left" width="200">
126+
127+
[View Azure DevOps Build](${{ env.ADO_URL }})
128+
129+
</td>
130+
<td align="left">
131+
132+
[Browse Full Coverage Report](${{ env.ADO_URL }}&view=codecoverage-tab)
133+
134+
</td>
135+
</tr>
136+
</table>

.github/workflows/pr-code-coverage.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,33 @@ jobs:
417417
echo "PATCH_COVERAGE_SUMMARY=Patch coverage report could not be generated." >> $GITHUB_ENV
418418
fi
419419
420+
- name: Save coverage data for comment
421+
run: |
422+
mkdir -p coverage-comment-data
423+
cat > coverage-comment-data/pr-info.json << EOF
424+
{
425+
"pr_number": "${{ github.event.pull_request.number }}",
426+
"coverage_percentage": "${{ env.COVERAGE_PERCENTAGE }}",
427+
"covered_lines": "${{ env.COVERED_LINES }}",
428+
"total_lines": "${{ env.TOTAL_LINES }}",
429+
"patch_coverage_pct": "${{ env.PATCH_COVERAGE_PCT }}",
430+
"low_coverage_files": $(jq -Rs . <<< "${{ env.LOW_COVERAGE_FILES }}"),
431+
"patch_coverage_summary": $(jq -Rs . <<< "${{ env.PATCH_COVERAGE_SUMMARY }}"),
432+
"ado_url": "${{ env.ADO_URL }}"
433+
}
434+
EOF
435+
cat coverage-comment-data/pr-info.json
436+
437+
- name: Upload coverage comment data
438+
uses: actions/upload-artifact@v4
439+
with:
440+
name: coverage-comment-data
441+
path: coverage-comment-data/
442+
retention-days: 1
443+
420444
- name: Comment coverage summary on PR
445+
# Skip for forked PRs due to token permission restrictions
446+
if: github.event.pull_request.head.repo.full_name == github.repository
421447
uses: marocchino/sticky-pull-request-comment@v2
422448
with:
423449
header: Code Coverage Report

0 commit comments

Comments
 (0)