Skip to content

Commit 24ac006

Browse files
ci: make coverage PR comment sticky to avoid duplicates (fixes #34) (#35)
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 14e272b commit 24ac006

File tree

2 files changed

+20
-87
lines changed

2 files changed

+20
-87
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -43,94 +43,13 @@ jobs:
4343
if: always()
4444
run: uv run coverage xml -i -o coverage.xml
4545

46-
- name: Code Coverage Summary
47-
if: ${{ always() && hashFiles('coverage.xml') != '' }}
48-
continue-on-error: true
49-
uses: irongut/CodeCoverageSummary@v1.3.0
50-
with:
51-
filename: coverage.xml
52-
badge: true
53-
fail_below_min: false
54-
format: markdown
55-
hide_branch_rate: false
56-
hide_complexity: true
57-
indicators: true
58-
output: both
59-
60-
- name: Add Coverage PR Comment
46+
- name: Pytest coverage PR comment
6147
if: ${{ always() && github.event_name == 'pull_request' }}
6248
continue-on-error: true
63-
uses: marocchino/sticky-pull-request-comment@v2
64-
with:
65-
recreate: true
66-
path: code-coverage-results.md
67-
68-
- name: Upload coverage artifacts
69-
if: always()
70-
uses: actions/upload-artifact@v4
71-
with:
72-
name: coverage-artifacts
73-
path: |
74-
coverage.xml
75-
code-coverage-results.md
76-
docs/assets/coverage.svg
77-
if-no-files-found: ignore
78-
- name: Parse coverage percent
79-
if: ${{ always() && github.event_name == 'pull_request' }}
80-
id: parsecov
81-
run: |
82-
python - << 'PY'
83-
import xml.etree.ElementTree as ET
84-
import math
85-
p = 'coverage.xml'
86-
try:
87-
root = ET.parse(p).getroot()
88-
lr = root.attrib.get('line-rate')
89-
pct = int(round(float(lr) * 100)) if lr is not None else 0
90-
except Exception:
91-
pct = 0
92-
print(f"coverage_percent={pct}")
93-
with open("coverage_percent.txt", "w") as f:
94-
f.write(str(pct))
95-
PY
96-
97-
- name: Determine badge color
98-
if: ${{ always() && github.event_name == 'pull_request' }}
99-
id: color
100-
run: |
101-
PCT=$(cat coverage_percent.txt || echo 0)
102-
if [ "$PCT" -ge 90 ]; then COLOR=brightgreen;
103-
elif [ "$PCT" -ge 75 ]; then COLOR=green;
104-
elif [ "$PCT" -ge 60 ]; then COLOR=yellowgreen;
105-
elif [ "$PCT" -ge 50 ]; then COLOR=yellow;
106-
else COLOR=red; fi
107-
echo "color=$COLOR" >> $GITHUB_OUTPUT
108-
echo "pct=$PCT" >> $GITHUB_OUTPUT
109-
110-
- name: Ensure docs/assets directory
111-
if: ${{ always() && github.event_name == 'pull_request' }}
112-
run: mkdir -p docs/assets
113-
114-
- name: Generate coverage badge
115-
if: ${{ always() && github.event_name == 'pull_request' }}
116-
uses: emibcn/badge-action@v2.0.2
49+
uses: MishaKav/pytest-coverage-comment@v1
11750
with:
118-
label: coverage
119-
status: "${{ steps.color.outputs.pct }}%"
120-
color: "${{ steps.color.outputs.color }}"
121-
path: docs/assets/coverage.svg
51+
github-token: ${{ secrets.GITHUB_TOKEN }}
52+
pytest-xml-coverage-path: coverage.xml
53+
title: Coverage Report
54+
create-new-comment: false
12255

123-
- name: Upload badge artifact (PRs)
124-
if: ${{ always() && github.event_name == 'pull_request' }}
125-
uses: actions/upload-artifact@v4
126-
with:
127-
name: coverage-badge
128-
path: docs/assets/coverage.svg
129-
130-
- name: Commit coverage badge (push builds on non-main branches)
131-
if: ${{ always() && github.event_name == 'push' && github.ref != 'refs/heads/main' }}
132-
uses: EndBug/add-and-commit@v9
133-
with:
134-
add: "docs/assets/coverage.svg"
135-
message: "docs: update coverage badge [skip ci]"
136-
default_author: github_actions

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,17 @@ python_files = ["test_*.py"]
4646
python_classes = ["Test*"]
4747
python_functions = ["test_*"]
4848
addopts = "-v --tb=short"
49+
50+
# Coverage.py configuration
51+
[tool.coverage.run]
52+
omit = [
53+
"openhands/core/tests/*",
54+
"openhands/tools/tests/*",
55+
]
56+
57+
[tool.coverage.report]
58+
omit = [
59+
"openhands/core/tests/*",
60+
"openhands/tools/tests/*",
61+
]
62+

0 commit comments

Comments
 (0)