name: CodSpeed

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

permissions:
  id-token: write
  contents: read

jobs:
  benchmarks:
    name: Run benchmarks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
        with:
          python-version: "3.13"
          enable-cache: true

      - name: Install dependencies
        run: scripts/install
        shell: bash

      - name: Run the benchmarks
        uses: CodSpeedHQ/action@f99becdce5e5d51fd556489ebef684f4ecfd6286 # v4.18.5
        with:
          mode: instrumentation
          run: uv run pytest tests/test_benchmark.py --codspeed

  memory-benchmarks:
    name: Run memory benchmarks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
        with:
          python-version: "3.13"
          enable-cache: true

      - name: Install dependencies
        run: scripts/install
        shell: bash

      - name: Run the benchmarks
        uses: CodSpeedHQ/action@f99becdce5e5d51fd556489ebef684f4ecfd6286 # v4.18.5
        with:
          mode: memory
          run: uv run pytest tests/test_benchmark_memory.py --codspeed
