name: Lint

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

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"

jobs:
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: https://codeberg.org/TheAwitworker/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - name: Install OpenBLAS
        run: sudo apt-get update -qq && sudo apt-get install -y libopenblas-dev libreadline-dev zlib1g-dev pkg-config

      - name: Clippy (workspace, excluding pg_infer extension)
        run: cargo clippy --workspace --exclude pg_infer -- -D warnings

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

  clippy-extension:
    name: Clippy (extension)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: https://codeberg.org/TheAwitworker/rust-toolchain@stable
        with:
          components: clippy

      - name: Install system deps
        run: |
          sudo apt-get update -qq && sudo apt-get install -y libopenblas-dev libreadline-dev zlib1g-dev pkg-config
          cargo install cargo-pgrx --version 0.17.0 --locked
          cargo pgrx init --pg18 download

      - name: Clippy (pg_infer extension)
        run: cargo clippy -p pg_infer -- -D warnings
