name: CI

on:
  push:
    branches:
      - main
      - 'feature-**'

jobs:
  test:
    name: Build and Test
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          lfs: true

      - name: Setup Rust toolchain
        run: |
          rustup update
          rustup component add clippy rustfmt
          rustup install nightly
          
      - name: Display toolchain info
        run: |
          cargo --version --verbose
          rustc --version
          cargo clippy --version

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

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

      - name: Run clippy
        run: cargo clippy -- -D warnings

      - name: Check build
        run: cargo check

      - name: Run tests
        run: cargo test --all
