name: CodSpeed

on:
  push:
    branches:
      - main
  pull_request:
  # `workflow_dispatch` allows CodSpeed to trigger backtest
  # performance analysis in order to generate initial data.
  workflow_dispatch:

permissions:
  contents: read
  id-token: write  # for OpenID Connect authentication with CodSpeed

concurrency:
  group: codspeed-${{ github.ref }}
  cancel-in-progress: true

jobs:
  codspeed:
    name: Run benchmarks
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup rust toolchain, cache and cargo-codspeed binary
        uses: moonrepo/setup-rust@v0
        with:
          cache-target: release
          bins: cargo-codspeed

      - name: Build the benchmark target(s)
        run: cargo codspeed build --features stream

      - name: Run the benchmarks
        uses: CodSpeedHQ/action@v4
        with:
          mode: simulation
          run: cargo codspeed run
