name: Publish to crates.io

on:
  push:
    tags:
      - "v[0-9]*"

permissions:
  contents: read

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

      - uses: dtolnay/rust-toolchain@stable

      # Publish in dependency order: affn-derive → affn
      - name: Publish affn-derive
        run: cargo publish -p affn-derive --no-verify
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for crates.io to index affn-derive
        run: sleep 30

      - name: Publish affn
        run: cargo publish -p affn --no-verify
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
