name: ci

on:
  push:
    branches: ["main", "master"]
  pull_request:

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  rust:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2

      - name: fmt
        run: cargo fmt --check

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

      - name: test
        run: cargo test --all-targets --all-features

      - name: build rankops-wasm (wasm32)
        run: |
          rustup target add wasm32-unknown-unknown
          cargo build --manifest-path crates/rankops-wasm/Cargo.toml --target wasm32-unknown-unknown

      - name: Semver check
        if: github.event_name == 'pull_request'
        run: |
          cargo install cargo-semver-checks --locked || true
          cargo semver-checks

  python:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Install uv
        uses: astral-sh/setup-uv@v6
      - name: Build and test Python bindings
        working-directory: rankops-python
        run: |
          uv sync --dev
          uv run pytest tests/ -v
