name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  fmt:
    name: Format
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt

      - name: Format
        run: cargo +nightly fmt --check

  test:
    name: Test
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

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

      - name: Install system dependencies
        run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev

      - name: Cache Cargo
        uses: Swatinem/rust-cache@v2

      - name: Test
        run: cargo test

      - name: Clippy
        run: cargo clippy --all-targets --no-deps -- -D warnings
