name: Publish to crates.io

on:
  workflow_dispatch:  # Manual trigger only
    inputs:
      dry-run:
        description: 'Perform a dry run (no actual publish)'
        type: boolean
        default: true

permissions:
  contents: read
  id-token: write

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

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

      - name: Verify version
        run: |
          VERSION=$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)
          echo "Publishing version: $VERSION"
          echo "Dry run: ${{ inputs.dry-run }}"

      - name: Run tests
        run: cargo test --all-features

      - name: Check package
        run: cargo package --allow-dirty

      - name: Publish (dry run)
        if: inputs.dry-run == true
        run: cargo publish --dry-run

      - name: Publish to crates.io
        if: inputs.dry-run == false
        run: cargo publish