name: CI

on:
  pull_request:
  push:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  WGPU_VALIDATION: "0"

jobs:
  verify:
    name: Format, lint, test, build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Linux dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            clang \
            mold \
            pkg-config \
            libasound2-dev \
            libudev-dev \
            libwayland-dev \
            libx11-dev \
            libxkbcommon-dev \
            libxi-dev \
            libxcursor-dev \
            libxrandr-dev \
            libxinerama-dev \
            libgl1-mesa-dev \
            libvulkan-dev

      - name: Install Rust toolchain
        run: rustup show

      - name: Check formatting
        run: cargo fmt --all --check

      - name: Check workspace
        run: cargo check --workspace --all-targets

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

      - name: Test workspace
        run: cargo test --workspace

      - name: Validate level scenes
        run: cargo validate-levels

      - name: Clippy launch feature matrix
        run: cargo clippy -p editor -p game --bins --features dev,hot-reload -- -D warnings

      - name: Build binaries
        run: |
          cargo build -p game
          cargo build -p editor
