name: CI

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: fmt, clippy, test, doc
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2
      - name: Format
        run: cargo fmt --all --check
      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings
      - name: Test
        run: cargo test
      - name: Docs
        run: cargo doc --no-deps
        env:
          RUSTDOCFLAGS: -D warnings

  integration:
    name: integration (RediSearch)
    runs-on: ubuntu-latest
    # Integration tests are best-effort; do not block CI if the service is unavailable.
    continue-on-error: true
    services:
      redis:
        image: redis/redis-stack-server:latest
        ports:
          - 6379:6379
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Integration tests
        env:
          REDIS_URL: redis://127.0.0.1:6379
        run: cargo test --test integration_tests -- --ignored
