name: CI

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

env:
  CARGO_TERM_COLOR: always
  RUST_TOOLCHAIN: nightly-2025-12-04

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: Check omendb dependency
        run: |
          if cargo metadata --format-version 1 \
            | jq -e '.packages[] | select(.name == "omendb" and .source == null)' >/dev/null; then
            echo "::error::omendb must resolve from crates.io in CI"
            exit 1
          fi

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

      - name: Build
        run: cargo build --release

      - name: Test
        run: cargo test

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