name: Benchmark

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch:

jobs:
  bench:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
    permissions:
      checks: write
    steps:
      - uses: actions/checkout@v4
      - name: Install Nix
        uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f

      - name: Restore binary cache
        uses: asa1984/infra/.github/actions/binary-cache@44165003348ea3578a66f8c879bfaf23a3c7cc18
        with:
          package: .#ci

      - run: nix profile install .#ci

      - uses: Swatinem/rust-cache@v2

      - run: cargo codspeed build

      - name: Run the benchmarks
        uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d
        with:
          run: cargo codspeed run
          token: ${{ secrets.CODSPEED_TOKEN }}
