From f872a2683138795e5c76becf219adbac68af8d56 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 4 Jul 2025 13:05:37 +0000 Subject: [PATCH] feat: support codspeed --- .github/workflows/codspeed.yml | 29 +++++++++++++++++++++++++++++ .gitignore | 3 +++ pyproject.toml | 1 + tests/test_clang_format.py | 5 +++++ tests/test_clang_tidy.py | 2 ++ tests/test_util.py | 1 + 6 files changed, 41 insertions(+) create mode 100644 .github/workflows/codspeed.yml diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..7fe8ab7 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,29 @@ +name: CodSpeed + +on: + push: + branches: + - "main" # or "master" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + benchmarks: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install dependencies + run: pip install -e .[dev] + + - name: Run benchmarks + uses: CodSpeedHQ/action@v3 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: pytest tests/ --codspeed diff --git a/.gitignore b/.gitignore index 7c7d014..c7a7c37 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ clang-tidy-1* clang-tidy-2* clang-format-1* clang-format-2* + +# Ignore CodeSpeed folder +.codspeed/ diff --git a/pyproject.toml b/pyproject.toml index 8ad28ab..014ca91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ dev = [ "coverage", "pre-commit", "pytest", + "pytest-codspeed", ] [tool.setuptools] diff --git a/tests/test_clang_format.py b/tests/test_clang_format.py index e7ed8ee..314e87f 100644 --- a/tests/test_clang_format.py +++ b/tests/test_clang_format.py @@ -4,6 +4,7 @@ from cpp_linter_hooks.clang_format import run_clang_format +@pytest.mark.benchmark @pytest.mark.parametrize( ("args", "expected_retval"), ( @@ -24,6 +25,7 @@ def test_run_clang_format_valid(args, expected_retval, tmp_path): assert test_file.read_text() == Path("testing/good.c").read_text() +@pytest.mark.benchmark @pytest.mark.parametrize( ("args", "expected_retval"), ( @@ -48,6 +50,7 @@ def test_run_clang_format_invalid(args, expected_retval, tmp_path): assert ret == expected_retval +@pytest.mark.benchmark @pytest.mark.parametrize( ("args", "expected_retval"), ( @@ -66,6 +69,7 @@ def test_run_clang_format_dry_run(args, expected_retval, tmp_path): assert ret == -1 # Dry run should not fail +@pytest.mark.benchmark def test_run_clang_format_verbose(tmp_path): """Test that verbose option works and provides detailed output.""" # copy test file to tmp_path to prevent modifying repo data @@ -82,6 +86,7 @@ def test_run_clang_format_verbose(tmp_path): assert test_file.read_text() == Path("testing/good.c").read_text() +@pytest.mark.benchmark def test_run_clang_format_verbose_error(tmp_path): """Test that verbose option provides useful error information.""" test_file = tmp_path / "main.c" diff --git a/tests/test_clang_tidy.py b/tests/test_clang_tidy.py index 2dfb4a8..887fd00 100644 --- a/tests/test_clang_tidy.py +++ b/tests/test_clang_tidy.py @@ -12,6 +12,7 @@ def generate_compilation_database(): subprocess.run(["cmake", "-Bbuild", "testing/"]) +@pytest.mark.benchmark @pytest.mark.parametrize( ("args", "expected_retval"), ( @@ -32,6 +33,7 @@ def test_run_clang_tidy_valid(args, expected_retval): print(output) +@pytest.mark.benchmark @pytest.mark.parametrize( ("args", "expected_retval"), ( diff --git a/tests/test_util.py b/tests/test_util.py index 415a502..842ccaa 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -10,6 +10,7 @@ TOOLS = ["clang-format", "clang-tidy"] +@pytest.mark.benchmark @pytest.mark.parametrize(("tool", "version"), list(product(TOOLS, VERSIONS))) def test_ensure_installed(tool, version, tmp_path, monkeypatch, caplog): bin_path = tmp_path / "bin"