Skip to content

Commit 7103ca5

Browse files
authored
Merge pull request #618 from py-cov-action/update
2 parents 587892b + e2bc11c commit 7103ca5

25 files changed

+572
-365
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@ on:
77

88
concurrency:
99
group: ${{ github.event_name }}-${{ github.ref }}
10+
cancel-in-progress: true
1011

1112
jobs:
13+
typing:
14+
name: Run type checking
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v5
19+
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v7
22+
23+
- name: Install deps
24+
run: uv sync --all-groups
25+
26+
- name: Run type checker
27+
run: uv run basedpyright
28+
1229
test:
1330
name: Run tests & display coverage
1431
runs-on: ubuntu-latest
@@ -21,22 +38,14 @@ jobs:
2138

2239
- name: Install uv
2340
uses: astral-sh/setup-uv@v7
24-
with:
25-
python-version: "3.12"
26-
27-
- name: Poetry caches
28-
uses: actions/cache@v4
29-
with:
30-
path: |
31-
~/.cache/
32-
key: ${{ hashFiles('uv.lock') }}
3341

3442
- name: Install deps
3543
run: uv sync --all-groups
3644

3745
- name: Run tests
3846
run: uv run pytest
3947
env:
48+
PY_COLORS: 1
4049
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1 }}
4150
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2 }}
4251
COVERAGE_COMMENT_E2E_ACTION_REF: ${{ github.sha }}

.github/workflows/e2e-external-phase-2.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ jobs:
9090

9191
- name: Install uv
9292
uses: astral-sh/setup-uv@v7
93-
with:
94-
python-version: "3.12"
9593

9694
- name: Poetry caches
9795
uses: actions/cache@v4
@@ -106,6 +104,7 @@ jobs:
106104
- name: Run end-to-end tests
107105
run: uv run pytest tests/end_to_end
108106
env:
107+
PY_COLORS: 1
109108
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_1 }}
110109
COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2: ${{ secrets.COVERAGE_COMMENT_E2E_GITHUB_TOKEN_USER_2 }}
111110
COVERAGE_COMMENT_E2E_ACTION_REF: ${{ steps.extract_commit.outputs.COMMIT_ID }}

.pre-commit-config.yaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
default_language_version:
4-
python: python3.12
4+
python: python3.14
55

66
ci:
77
# Renovate updates the file. We can't disable pre-commit CI's autoupdate entirely
88
# but this is the least frequent we can make it.
99
autoupdate_schedule: quarterly
10+
skip: [basedpyright]
1011

1112
repos:
1213
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -18,18 +19,32 @@ repos:
1819
- id: check-added-large-files
1920

2021
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.14.0
22+
rev: v0.13.3
2223
hooks:
2324
- id: ruff
2425
args: [--fix]
2526
- id: ruff-format
2627

27-
- repo: local
28+
- repo: https://github.com/DetachHead/basedpyright-prek-mirror
29+
rev: 1.32.1
2830
hooks:
29-
- id: sync-pre-commit
30-
name: Sync pre-commit hooks
31-
language: python
32-
entry: scripts/sync-pre-commit.py
31+
- id: basedpyright
32+
3333
additional_dependencies:
34-
- uv
35-
- ruamel.yaml
34+
- anyio==4.11.0
35+
- certifi==2025.10.5
36+
- coverage==7.10.7
37+
- h11==0.16.0
38+
- h2==4.3.0
39+
- hpack==4.1.0
40+
- httpcore==1.0.9
41+
- httpx==0.28.1
42+
- hyperframe==6.1.0
43+
- idna==3.10
44+
- jinja2==3.1.6
45+
- markupsafe==3.0.3
46+
- sniffio==1.3.1
47+
- repo: https://github.com/ewjoachim/sync-pre-commit-with-uv
48+
rev: 1.1.0
49+
hooks:
50+
- id: sync

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.14

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You're welcome to contribute, though I can't promise the experience will be as s
44

55
### Things to know:
66

7-
- Python3.12
7+
- Python3.14
88
- Use [uv](https://docs.astral.sh/uv/)
99
- Launch tests with `pytest`, config is in setup.cfg
1010
- `ruff` runs through `pre-commit`, so you can install hooks with `pre-commit install`.
@@ -78,6 +78,7 @@ In case "branch coverage" is enabled, the coverage rate is
7878
`(covered_lines + covered_branches) / (total_lines + total_branches)`.
7979
In order to display coverage rates, we need to round the values. Depending on
8080
the situation, we either round to 0 or 2 decimal places. Rounding rules are:
81+
8182
- We always round down (truncate) the value.
8283
- We don't display the trailing zeros in the decimal part (nor the decimal point
8384
if the decimal part is 0).

Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# - Dockerfile
33
# - .github/workflows/release.yml
44

5-
FROM python:3.12-slim
5+
FROM python:3.14-slim
66

77
RUN set -eux; \
88
apt-get update; \

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ jobs:
290290
291291
- name: Set up Python
292292
id: setup-python
293-
uses: actions/setup-python@v4
293+
uses: actions/setup-python@v6
294294
with:
295295
python-version: ${{ matrix.python_version }}
296296
@@ -350,37 +350,37 @@ jobs:
350350
351351
The action makes available some data for downstream processing.
352352
353-
| Name | Description |
354-
| --- | --- |
353+
| Name | Description |
354+
| -------------- | --------------------------------------------------------------------------------------------------- |
355355
| `activity_run` | The type of activity that was run. One of `process_pr`, `post_comment`, `save_coverage_data_files`. |
356356

357357
All the following outputs are only available when running in PR mode.
358358

359-
| Name | Description |
360-
| --- | --- |
361-
| `comment_file_written` | A boolean indicating whether a comment file was written to `COMMENT_FILENAME` or not. |
362-
| `new_covered_lines` | The number of covered lines in the pull request. |
363-
| `new_num_statements` | The number of statements in the pull request. |
364-
| `new_percent_covered` | The coverage percentage of the pull request. |
365-
| `new_missing_lines` | The number of lines with missing coverage in the pull request. |
366-
| `new_excluded_lines` | The number of excluded lines in the pull request. |
367-
| `new_num_branches` | The number of branches in the pull request. |
368-
| `new_num_partial_branches` | The number of partial branches in the pull request. |
369-
| `new_covered_branches` | The number of covered branches in the pull request. |
370-
| `new_missing_branches` | The number of branches with missing coverage in the pull request. |
371-
| `reference_covered_lines` | The number of covered lines in the base branch. |
372-
| `reference_num_statements` | The number of statements in the base branch. |
373-
| `reference_percent_covered` | The coverage percentage of the base branch. |
374-
| `reference_missing_lines` | The number of lines with missing coverage in the base branch. |
375-
| `reference_excluded_lines` | The number of excluded lines in the base branch. |
376-
| `reference_num_branches` | The number of branches in the base branch. |
377-
| `reference_num_partial_branches` | The number of partial branches in the base branch. |
378-
| `reference_covered_branches` | The number of covered branches in the base branch. |
379-
| `reference_missing_branches` | The number of branches with missing coverage in the base branch. |
380-
| `diff_total_num_lines` | The total number of lines in the diff. |
381-
| `diff_total_num_violations` | The total number of lines with missing coverage in the diff. |
382-
| `diff_total_percent_covered` | The coverage percentage of the diff. |
383-
| `diff_num_changed_lines` | The number of changed lines in the diff. |
359+
| Name | Description |
360+
| -------------------------------- | ------------------------------------------------------------------------------------- |
361+
| `comment_file_written` | A boolean indicating whether a comment file was written to `COMMENT_FILENAME` or not. |
362+
| `new_covered_lines` | The number of covered lines in the pull request. |
363+
| `new_num_statements` | The number of statements in the pull request. |
364+
| `new_percent_covered` | The coverage percentage of the pull request. |
365+
| `new_missing_lines` | The number of lines with missing coverage in the pull request. |
366+
| `new_excluded_lines` | The number of excluded lines in the pull request. |
367+
| `new_num_branches` | The number of branches in the pull request. |
368+
| `new_num_partial_branches` | The number of partial branches in the pull request. |
369+
| `new_covered_branches` | The number of covered branches in the pull request. |
370+
| `new_missing_branches` | The number of branches with missing coverage in the pull request. |
371+
| `reference_covered_lines` | The number of covered lines in the base branch. |
372+
| `reference_num_statements` | The number of statements in the base branch. |
373+
| `reference_percent_covered` | The coverage percentage of the base branch. |
374+
| `reference_missing_lines` | The number of lines with missing coverage in the base branch. |
375+
| `reference_excluded_lines` | The number of excluded lines in the base branch. |
376+
| `reference_num_branches` | The number of branches in the base branch. |
377+
| `reference_num_partial_branches` | The number of partial branches in the base branch. |
378+
| `reference_covered_branches` | The number of covered branches in the base branch. |
379+
| `reference_missing_branches` | The number of branches with missing coverage in the base branch. |
380+
| `diff_total_num_lines` | The total number of lines in the diff. |
381+
| `diff_total_num_violations` | The total number of lines with missing coverage in the diff. |
382+
| `diff_total_percent_covered` | The coverage percentage of the diff. |
383+
| `diff_num_changed_lines` | The number of changed lines in the diff. |
384384

385385
Usage may look like this
386386

coverage_comment/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from coverage_comment import main
44

55

6-
def main_call(name):
6+
def main_call(name: str):
77
if name == "__main__":
88
main.main()
99

coverage_comment/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ActivityNotFound(Exception):
1616
def find_activity(
1717
event_name: str,
1818
is_default_branch: bool,
19-
event_type: str,
19+
event_type: str | None,
2020
is_pr_merged: bool,
2121
) -> str:
2222
"""Find the activity to perform based on the event type and payload."""

coverage_comment/coverage.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import pathlib
88
from collections.abc import Sequence
9+
from typing import Any
910

1011
from coverage_comment import log, subprocess
1112

@@ -21,20 +22,19 @@ class CoverageMetadata:
2122
show_contexts: bool
2223

2324

24-
class OutputMixin:
25-
def as_output(self, prefix: str) -> dict:
26-
data = dataclasses.asdict(self)
27-
output = {}
28-
for key, value in data.items():
29-
if value is not None and not isinstance(value, dict):
30-
output[f"{prefix}_{key}"] = (
31-
float(value) if isinstance(value, decimal.Decimal) else value
32-
)
33-
return output
25+
def as_output(obj: Any, prefix: str) -> dict[str, Any]:
26+
data = dataclasses.asdict(obj)
27+
output: dict[str, Any] = {}
28+
for key, value in data.items():
29+
if value is not None and not isinstance(value, dict):
30+
output[f"{prefix}_{key}"] = (
31+
float(value) if isinstance(value, decimal.Decimal) else value
32+
)
33+
return output
3434

3535

3636
@dataclasses.dataclass(kw_only=True)
37-
class CoverageInfo(OutputMixin):
37+
class CoverageInfo:
3838
covered_lines: int
3939
num_statements: int
4040
percent_covered: decimal.Decimal
@@ -88,7 +88,7 @@ def violation_lines(self) -> list[int]:
8888

8989

9090
@dataclasses.dataclass(kw_only=True)
91-
class DiffCoverage(OutputMixin):
91+
class DiffCoverage:
9292
total_num_lines: int
9393
total_num_violations: int
9494
total_percent_covered: decimal.Decimal
@@ -112,7 +112,7 @@ def compute_coverage(
112112

113113
def get_coverage_info(
114114
merge: bool, coverage_path: pathlib.Path
115-
) -> tuple[dict, Coverage]:
115+
) -> tuple[dict[str, Any], Coverage]:
116116
try:
117117
if merge:
118118
subprocess.run("coverage", "combine", path=coverage_path)
@@ -160,7 +160,7 @@ def generate_coverage_markdown(coverage_path: pathlib.Path) -> str:
160160
)
161161

162162

163-
def _make_coverage_info(data: dict) -> CoverageInfo:
163+
def _make_coverage_info(data: dict[str, Any]) -> CoverageInfo:
164164
"""Build a CoverageInfo object from a "summary" or "totals" key."""
165165
return CoverageInfo(
166166
covered_lines=data["covered_lines"],
@@ -180,7 +180,7 @@ def _make_coverage_info(data: dict) -> CoverageInfo:
180180
)
181181

182182

183-
def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage:
183+
def extract_info(data: dict[str, Any], coverage_path: pathlib.Path) -> Coverage:
184184
"""
185185
{
186186
"meta": {
@@ -246,7 +246,7 @@ def extract_info(data: dict, coverage_path: pathlib.Path) -> Coverage:
246246
def get_diff_coverage_info(
247247
added_lines: dict[pathlib.Path, list[int]], coverage: Coverage
248248
) -> DiffCoverage:
249-
files = {}
249+
files: dict[pathlib.Path, FileDiffCoverage] = {}
250250
total_num_lines = 0
251251
total_num_violations = 0
252252
num_changed_lines = 0

0 commit comments

Comments
 (0)