name: CI

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

# Minimal token scope. Read-only by default; no secrets exposed to fork PRs.
permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  # Fail the build if `cargo` itself emits warnings on dependency resolution.
  CARGO_INCREMENTAL: 0

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

  check:
    name: Clippy + Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwebkit2gtk-4.1-dev \
            libgtk-3-dev \
            libsoup-3.0-dev \
            libappindicator3-dev \
            librsvg2-dev \
            cmake \
            nasm

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

      - uses: Swatinem/rust-cache@v2

      - name: Fetch nushell sidecar
        # tauri-build resolves `externalBin` paths during regular builds,
        # so the sidecar must exist before clippy runs.
        run: bash scripts/fetch-nushell.sh

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

      - name: Tests
        run: cargo test --workspace
