name: bench-baseline-update

# SDD-120 §7 / SAD-089 — manual-dispatch workflow that opens a PR
# updating the committed baseline JSON. This is the SOLE writer of
# `crates/chanora_audio/benches/baselines/<host>.json`. Triggered
# only on operator demand via workflow_dispatch.

on:
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  bench-baseline-update:
    name: bench-baseline-update
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: System deps (cpal / Opus)
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libasound2-dev libpulse-dev pkg-config \
            libopus-dev
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Run benchmarks
        run: |
          cargo bench -p chanora_audio \
            --bench realtime_capture \
            --bench opus_codec \
            --bench resampler
      - name: Emit current baseline JSON
        run: cargo run --example emit_baseline -p chanora_audio
      - name: Copy current to baseline path
        run: cp current.json crates/chanora_audio/benches/baselines/x86_64-unknown-linux-gnu.json
      - name: Create pull request
        uses: peter-evans/create-pull-request@v6
        with:
          branch: bench/baseline-update-${{ github.run_id }}
          base: product/scaffold-v0
          title: "chore(bench): update realtime audio baselines"
          body: |
            Automated baseline update produced by manual dispatch of
            `bench-baseline-update.yml`.

            Run: ${{ github.run_id }}
            Triggered by: ${{ github.actor }}
          commit-message: "chore(bench): update realtime audio baselines"
          add-paths: |
            crates/chanora_audio/benches/baselines/x86_64-unknown-linux-gnu.json
