name: ci

on:
  pull_request:
  push:
    branches: [main]
    paths-ignore:
      - "**/*.md"
      - "docs/**"
      - "LICENSE"
  workflow_dispatch:

concurrency:
  group: ci-${{ github.head_ref || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: "0"
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
  lint:
    name: fmt + clippy + check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Install build deps
        run: |
          sudo apt-get update
          sudo apt-get install -y cmake clang libasound2-dev pkg-config
      - uses: Swatinem/rust-cache@v2
        with:
          key: lint
      - run: cargo fmt --all -- --check
      - run: cargo clippy --all-targets --no-deps
      # `check --all-targets` validates the bin compiles too, so we don't
      # need a dedicated bin job.
      - run: cargo check --all-targets

  # Cross-platform napi build only on PR (main pushes are covered by release.yml).
  build:
    if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
    uses: ./.github/workflows/_build.yml
