Skip to content

Commit 278b3e7

Browse files
Merge pull request #4 from captcha-solver-api/ci/coverage
ci: measure coverage and publish badge to gist
2 parents c7af29e + d36b823 commit 278b3e7

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎.github/workflows/tests.yml‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,30 @@ jobs:
5454
run: python -m pip install -e ".[dev]"
5555

5656
- name: Run tests
57-
run: python -m pytest tests/ -v
57+
run: python -m pytest tests/ -v --cov --cov-report=term --cov-report=json
58+
59+
# Coverage badge: the percentage is written to a gist that shields.io
60+
# renders in README. Only from main and from a single matrix entry so
61+
# PRs and duplicate uploads never overwrite the number.
62+
- name: Read coverage percentage
63+
if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12'
64+
id: coverage
65+
run: |
66+
percent=$(python -c 'import json; print(round(json.load(open("coverage.json"))["totals"]["percent_covered"]))')
67+
echo "percent=$percent" >> "$GITHUB_OUTPUT"
68+
69+
- name: Update coverage badge
70+
if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12'
71+
uses: schneegans/dynamic-badges-action@v1.9.0
72+
with:
73+
auth: ${{ secrets.GIST_SECRET }}
74+
gistID: 77b084ed0d46c740183f89ec66af8a95
75+
filename: python-sdk-coverage.json
76+
label: coverage
77+
message: ${{ steps.coverage.outputs.percent }}%
78+
valColorRange: ${{ steps.coverage.outputs.percent }}
79+
minColorRange: 50
80+
maxColorRange: 90
5881

5982
- name: Verify package builds
6083
run: |

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ENV/
2424
# Testing
2525
.pytest_cache/
2626
.coverage
27+
coverage.json
28+
coverage.xml
2729
htmlcov/
2830

2931
# Type checkers

‎pyproject.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dev = [
4848
"ruff>=0.6",
4949
"mypy>=1.10",
5050
"types-requests>=2.28",
51+
"pytest-cov>=4",
5152
]
5253

5354
[project.urls]
@@ -67,6 +68,13 @@ captcha_solver_api = ["py.typed"]
6768
[tool.pytest.ini_options]
6869
asyncio_mode = "auto"
6970

71+
[tool.coverage.run]
72+
source = ["captcha_solver_api"]
73+
branch = true
74+
75+
[tool.coverage.report]
76+
show_missing = true
77+
7078
[tool.mypy]
7179
# mypy 2.x cannot target 3.9; 3.10 is the lowest it accepts. Runtime
7280
# compatibility with 3.9 is still covered by the CI test matrix.

0 commit comments

Comments
 (0)