Skip to content

Commit de4a610

Browse files
Add CodSpeed performance benchmarks and CI workflow (#167)
Co-authored-by: codspeed-hq[bot] <117304815+codspeed-hq[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent da65980 commit de4a610

6 files changed

Lines changed: 505 additions & 3 deletions

File tree

.github/workflows/codspeed.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CodSpeed
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
# `workflow_dispatch` allows CodSpeed to trigger backtest
9+
# performance analysis in order to generate initial data.
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
jobs:
17+
benchmarks:
18+
name: Run benchmarks
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v5
26+
27+
- name: Set up Python
28+
run: uv python install 3.13
29+
30+
- name: Install dependencies
31+
run: uv sync --group dev --frozen
32+
33+
- name: Run benchmarks
34+
uses: CodSpeedHQ/action@v4
35+
with:
36+
mode: simulation
37+
run: uv run pytest -m benchmark --codspeed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<a href="https://results.pre-commit.ci/latest/github/Kilo59/ruff-sync/main"><img src="https://results.pre-commit.ci/badge/github/Kilo59/ruff-sync/main.svg" alt="pre-commit.ci status"></a>
1010
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
1111
<a href="https://wily.readthedocs.io/"><img src="https://img.shields.io/badge/%F0%9F%A6%8A%20wily-passing-brightgreen.svg" alt="Wily"></a>
12+
<a href="https://codspeed.io/Kilo59/ruff-sync?utm_source=badge"><img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed"/></a>
1213
</p>
1314

1415
# ruff-sync

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dev = [
5454
"pyfakefs>=5.4.1",
5555
"pytest>=8.0.0",
5656
"pytest-asyncio>=0.23.5",
57+
"pytest-codspeed>=4.3.0",
5758
"pytest-icdiff>=0.9",
5859
"pytest-textual-snapshot>=1.0.0",
5960
"respx>=0.21.1",
@@ -250,3 +251,6 @@ include = ["src/ruff_sync/*.py"]
250251

251252
[tool.pytest]
252253
log_level = "INFO"
254+
markers = [
255+
"benchmark: marks performance benchmarks (run separately for CodSpeed)",
256+
]

tests/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import logging
44
import os
55
import sys
6-
from typing import Literal, Protocol, runtime_checkable
6+
from typing import TYPE_CHECKING, Literal, Protocol, runtime_checkable
7+
8+
if TYPE_CHECKING:
9+
from collections.abc import Generator
710

811
import pytest
912
from typing_extensions import override
@@ -38,7 +41,7 @@ def emit(self, record):
3841

3942

4043
@pytest.fixture
41-
def configure_logging():
44+
def configure_logging() -> Generator[logging.Logger, None, None]:
4245
"""Configure ruff_sync logger for tests to ensure capsys can capture log output."""
4346
logger = logging.getLogger("ruff_sync")
4447
old_handlers = logger.handlers[:]
@@ -62,7 +65,7 @@ def configure_logging():
6265

6366

6467
@pytest.fixture
65-
def clear_ruff_sync_caches():
68+
def clear_ruff_sync_caches() -> None:
6669
"""Clear all lru_caches in ruff_sync."""
6770
ruff_sync.get_config.cache_clear()
6871
ruff_sync.Arguments.fields.cache_clear()

0 commit comments

Comments
 (0)