name: KASL Compiler CI

on:
    push:
        branches: ["main", "kasl"]
    pull_request:
        branches: ["main", "kasl"]

jobs:
    test:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout repository
              uses: actions/checkout@v4

            - name: Cache cargo registry and build
              uses: actions/cache@v4
              with:
                  path: |
                      ~/.cargo/registry
                      ~/.cargo/git
                      target
                  key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
                  restore-keys: |
                      ${{ runner.os }}-cargo-

            - name: Install system packages (for native deps)
              run: |
                  sudo apt-get update
                  sudo apt-get install -y pkg-config libasound2-dev

            - name: Install Rust toolchain (stable)
              uses: actions-rs/toolchain@v1
              with:
                  toolchain: stable
                  profile: minimal
                  override: true

            - name: Install rustfmt and clippy
              run: rustup component add rustfmt clippy

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

            - name: Build (debug) and run tests
              run: |
                  rustc --version
                  cargo test --workspace --all-features --locked --verbose
