polyvoice 0.6.7

Speaker diarization for Rust — who spoke when. ONNX-powered: Silero VAD, WeSpeaker embeddings, Pyannote segmentation, K-means/AHC clustering, overlap detection.
Documentation
name: CI

on:
  push:
    branches: [master, main]
    tags: ["v*"]
  pull_request:
    branches: [master, main]
  schedule:
    - cron: "0 2 * * *"
  workflow_dispatch:

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

permissions: {}

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            flags: --all-targets --all-features
          - os: macos-latest
            flags: --all-targets --features onnx,ffi,cli
          - os: windows-latest
            flags: --all-targets --features onnx,ffi,cli
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check ${{ matrix.flags }}

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --check

  clippy:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            flags: --all-targets --all-features
          - os: macos-latest
            flags: --all-targets --features onnx,ffi,cli
          - os: windows-latest
            flags: --all-targets --features onnx,ffi,cli
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
        with:
          key: clippy-${{ matrix.os }}-${{ hashFiles('Cargo.toml', '**/Cargo.toml', '**/Cargo.lock') }}
          cache-on-failure: false
      - shell: bash
        run: cargo clippy ${{ matrix.flags }} -- -D warnings 2>&1 | tee clippy.log
      - if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: clippy-log-${{ matrix.os }}
          path: clippy.log

  test:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            flags: --all-features
          - os: macos-latest
            flags: --features onnx,ffi,cli
          - os: windows-latest
            flags: --features onnx,ffi,cli
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-nextest
      - run: cargo nextest run --profile ci ${{ matrix.flags }}

  doc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: "-D warnings"

  coverage:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-nextest
      - run: cargo llvm-cov nextest --profile ci --all-features --cobertura --output-path cobertura.xml --fail-under-lines 70
      - if: always()
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: cobertura.xml
      - uses: codecov/codecov-action@v4
        with:
          files: ./cobertura.xml
          fail_ci_if_error: false
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  miri:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    continue-on-error: true
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: miri
      - uses: Swatinem/rust-cache@v2
      - run: |
          cargo miri test --features ffi --test ffi_smoke_test ffi_create
          cargo miri test --features resegmentation --test miri_resegmentation
          cargo miri test --features ffi --test test_ahc
        env:
          MIRIFLAGS: "-Zmiri-disable-isolation"

  valgrind:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get update && sudo apt-get install -y valgrind
      - run: cargo test --features ffi --test ffi_smoke_test --no-run
      - name: Run under valgrind
        run: |
          BIN=$(find target/debug/deps -maxdepth 1 -name 'ffi_smoke_test-*' -type f -executable | head -1)
          valgrind --leak-check=full --errors-for-leak-kinds=definite --error-exitcode=1 \
            "$BIN" ffi_create_invalid_profile_returns_invalid_arg ffi_create_null_out_handle_returns_error

  loom:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --test loom_pool
        env:
          LOOM_MAX_PREEMPTIONS: 3

  semver-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-semver-checks
      - run: cargo semver-checks check-release

  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-audit
      - run: cargo audit

  deny:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-deny
      - run: cargo deny check advisories licenses

  hack:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-hack
      - run: cargo hack check --feature-powerset --depth 2 --lib --bins

  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.85.0
      - uses: Swatinem/rust-cache@v2
      # MSRV applies to the core library (default features). ONNX-dependent
      # features pull ort which requires a newer Rust compiler.
      - run: cargo check --lib

  machete:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-machete
      - run: cargo machete

  kani:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: model-checking/kani-github-action@v1
        with:
          args: "--lib"

  cross-aarch64-linux:
    runs-on: ubuntu-latest
    env:
      CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: aarch64-unknown-linux-gnu
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
      - run: cargo check --target aarch64-unknown-linux-gnu
      - run: cargo check --target aarch64-unknown-linux-gnu --features download

  wasm32-smoke:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --target wasm32-unknown-unknown --no-default-features --lib

  e2e-smoke:
    runs-on: ubuntu-latest
    needs: [test]
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: actions/cache@v4
        with:
          path: ~/.cache/polyvoice/models
          key: models-balanced-${{ hashFiles('src/models/manifest.rs') }}
      - name: Download ONNX models
        run: cargo run --features cli --bin polyvoice -- download-models --profile balanced
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-nextest
      - name: Run E2E smoke test
        run: cargo nextest run --profile ci --run-ignored only --test e2e_smoke_test --features "onnx download" --nocapture

  e2e-der-regression:
    runs-on: ubuntu-latest
    needs: [test]
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: legacy-e2e-smoke
            test: der_regression_e2e_smoke
            test_flags: "--test der_regression_test --features onnx,download"
            data_key: e2e-smoke-bundled
            data_path: tests/data/e2e-smoke
          - name: legacy-voxconverse-10
            test: der_regression_voxconverse_10_file_subset
            test_flags: "--test der_regression_test --features onnx,download"
            data_script: scripts/download-voxconverse-test.sh
            data_key: voxconverse-test
            data_path: data/voxconverse-test
          - name: legacy-ami-single
            test: der_regression_ami_test_single
            test_flags: "--test der_regression_test --features onnx,download"
            data_script: scripts/download-ami-test-single.sh
            data_key: ami-test-single
            data_path: data/ami-test-single
          - name: pipeline-v2
            test_flags: "--test pipeline_v2_integration --features onnx,segmentation,embedder,clusterer,resegmentation,download"
            data_key: e2e-smoke-bundled
            data_path: tests/data/e2e-smoke
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: actions/cache@v4
        with:
          path: ~/.cache/polyvoice/models
          key: models-balanced-${{ hashFiles('src/models/manifest.rs') }}
      - uses: actions/cache@v4
        if: matrix.data_script
        with:
          path: ${{ matrix.data_path }}
          key: ${{ matrix.data_key }}-${{ hashFiles(format('{0}.sh', matrix.data_script)) }}
      - name: Download external test data
        if: matrix.data_script
        run: bash ${{ matrix.data_script }}
      - name: Download ONNX models
        run: cargo run --features cli --bin polyvoice -- download-models --profile balanced
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-nextest
      - name: Run DER regression — ${{ matrix.name }}
        shell: bash
        run: cargo nextest run --profile ci --run-ignored only ${{ matrix.test_flags }} ${{ matrix.test }} --nocapture 2>&1 | tee der-regression.log
      - if: failure() || cancelled()
        uses: actions/upload-artifact@v4
        with:
          name: der-regression-log-${{ matrix.name }}
          path: der-regression.log
        continue-on-error: true

  perf-regression:
    runs-on: ubuntu-latest
    needs: [test]
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: actions/cache@v4
        with:
          path: data/voxconverse-test
          key: voxconverse-test-${{ hashFiles('scripts/download-voxconverse-test.sh') }}
      - uses: actions/cache@v4
        with:
          path: ~/.cache/polyvoice/models
          key: models-balanced-${{ hashFiles('src/models/manifest.rs') }}
      - run: bash scripts/download-voxconverse-test.sh
      - run: cargo run --features cli --bin polyvoice -- download-models --profile balanced
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-nextest
      - name: Run perf regression test
        shell: bash
        run: cargo nextest run --profile ci --run-ignored only --test perf_regression_test --features "onnx download" --nocapture 2>&1 | tee perf-regression.log
      - if: always()
        uses: actions/upload-artifact@v4
        with:
          name: perf-regression-log
          path: perf-regression.log

  sign-manifest-dry-run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: |
          sudo apt-get update && sudo apt-get install -y minisign
      - run: ./scripts/sign-models.sh --dry-run