name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: Check & Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - uses: Swatinem/rust-cache@v2
        continue-on-error: true

      - name: Install Opus (Linux)
        run: sudo apt-get update && sudo apt-get install -y libopus-dev

      - name: Check format
        run: cargo fmt --check

      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2
        continue-on-error: true

      - name: Install Opus (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y libopus-dev

      - name: Test
        run: cargo test --all-targets

      - name: Test with Opus feature
        if: runner.os == 'Linux'
        run: cargo test --features opus --all-targets

  doc:
    name: Doc
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2
        continue-on-error: true

      - name: Build docs
        run: cargo doc --no-deps --document-private-items
        env:
          RUSTDOCFLAGS: -D warnings
