name: CI

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

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install system dependencies
        run: sudo apt-get update && sudo apt-get install -y libclang-dev

      - name: Install Rust 1.88
        uses: dtolnay/rust-toolchain@1.88
        with:
          components: rustfmt, clippy

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

      - name: Cache cargo tools
        uses: actions/cache@v5
        id: cache-tools
        with:
          path: ~/.cargo/bin
          key: ${{ runner.os }}-tools-just-cargo-audit-cargo-msrv-0.18.4

      - name: Install cargo-binstall
        if: steps.cache-tools.outputs.cache-hit != 'true'
        uses: cargo-bins/cargo-binstall@v1.17.9

      - name: Install tools
        if: steps.cache-tools.outputs.cache-hit != 'true'
        run: cargo binstall --no-confirm just cargo-audit cargo-msrv@0.18.4

      - name: Run CI
        run: just ci
