name: Benchmark

permissions: {}

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

env:
  CARGO_TERM_COLOR: always
  RUSTC_WRAPPER: "sccache"
  RUSTFLAGS: -Csymbol-mangling-version=v0

jobs:
  codspeed:
    runs-on: depot-ubuntu-latest
    permissions:
      contents: read
    environment: codspeed
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - name: Install LLVM
        run: .github/scripts/install_llvm.sh ubuntu
      - uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
      - uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
      - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
        with:
          cache-on-failure: true
          cache-bin: false
      - name: Install cargo-codspeed
        uses: taiki-e/install-action@41049aa56687c35e0afa74eed4f09cec4f9afabf # v2.85.2
        with:
          tool: cargo-codspeed
      - name: Build the benchmark target
        run: cargo codspeed build --profile profiling -p evm2-cli --features jit --bench evm
      - name: Run the benchmarks
        uses: CodSpeedHQ/action@f22792bfac16f3e14eb9fbea76f4a48e9cc22b93 # v4.19.1
        with:
          run: cargo codspeed run -p evm2-cli --bench evm
          mode: instrumentation
          token: ${{ secrets.CODSPEED_TOKEN }}
