name: Rust CI

on:
  push:
    branches: [main]
    tags: ["v*"]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test
      # 🤓 wasm feature compiles to rlib on native — wasm32 target only needed for actual WASM artifact
      - run: cargo test --features wasm

  publish-crate:
    name: Publish to crates.io
    needs: test
    # 🤓 gate on tags (v*) — push a `git tag v0.1.0 && git push --tags` to trigger
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Publish
        # 🤓 CARGO_REGISTRY_TOKEN is the standard cargo env var — no --token flag needed
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish
