name: CI

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

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  verify:
    name: Verify crate is publish-ready
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt

      - uses: Swatinem/rust-cache@v2

      - name: Rustfmt
        run: cargo fmt --all -- --check

      - name: Clippy (deny warnings)
        run: cargo clippy --workspace --all-targets --all-features -- -D warnings

      - name: Strict compile check
        env:
          RUSTFLAGS: "-D warnings"
        run: cargo check --workspace --all-targets --all-features

      - name: Tests (all features)
        run: cargo test --workspace --all-features

      - name: Tests (no default features)
        run: cargo test --workspace --no-default-features

      - name: Docs-backed examples
        run: |
          cargo run --example serialize --features versioned,json,decimal
          cargo run --example builder --features versioned,builder,json,decimal

      - name: Package check (publish dry-run)
        run: cargo publish --dry-run --locked
