name: Publish Rust crate

on:
  push:
    tags: 
      - "v*.*.*"

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v5
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - run: rustup component add clippy
      - run: cargo install cargo-machete

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

  publish-crate:
    needs: lint
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v5
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      
      - name: Publish to crates.io
        run: cargo publish --verbose
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}