name: codspeed-benchmarks

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:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: "3.7"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r robyn/test-requirements.txt
      - name: Add macos target
        if: matrix.os == 'macos'
        run: rustup target add aarch64-apple-darwin
      - name: Setup Rust part of the project
        run: |
          maturin build -i python --universal2 --out dist
          pip install --no-index --find-links=dist/ robyn

      - name: Run benchmarks
        uses: CodSpeedHQ/action@v1
        with:
          token: ${{ secrets.CODSPEED_TOKEN }}
          run: pytest integration_tests --codspeed
