feat(build): Add benchmarks framework #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Benchmarks | |
| on: | |
| pull_request: | |
| types: [labeled, synchronize] | |
| push: | |
| branches: [main] | |
| jobs: | |
| benchmark-cpu: | |
| # Only run on PRs with 'run-benchmarks' label OR on main branch | |
| if: | | |
| github.event_name == 'push' || | |
| contains(github.event.pull_request.labels.*.name, 'run-benchmarks') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install hatch | |
| run: pip install hatch | |
| - name: Run benchmarks with CodSpeed | |
| uses: CodSpeedHQ/action@v3 | |
| with: | |
| token: ${{ secrets.CODSPEED_TOKEN }} | |
| run: hatch run benchmark:run --codspeed -m "not slow and not integration" | |
| - name: Generate benchmark JSON (fallback) | |
| if: always() | |
| run: | | |
| hatch run benchmark:run \ | |
| --benchmark-only \ | |
| --benchmark-json=benchmark-results.json \ | |
| -m "not slow and not integration" || true | |
| - name: Upload benchmark results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: benchmark-results | |
| path: benchmark-results.json | |
| retention-days: 30 | |
| benchmark-memory: | |
| # Only run on PRs with 'run-benchmarks' label | |
| if: contains(github.event.pull_request.labels.*.name, 'run-benchmarks') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install hatch | |
| run: pip install hatch | |
| - name: Run memory benchmarks | |
| run: | | |
| hatch run benchmark:memory \ | |
| --memray-bin-path=memray-results \ | |
| -m "not slow and not integration" | |
| - name: Upload memory results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: memory-results | |
| path: memray-results/ | |
| retention-days: 30 |