name: Publish Crate

on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt
      - name: Check formatting
        run: cargo fmt --check
      - name: Run tests
        run: cargo test --all-targets --locked
      - name: Run doc tests
        run: cargo test --doc --locked
      - name: Run Clippy
        run: cargo clippy --all-targets --all-features --locked -- -D warnings
      - name: Package crate
        run: cargo package --locked
      - name: Publish crate
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked
