name: Build

on:
  workflow_dispatch:
  push:
    tags: ["*"]
  pull_request:

jobs:
  build:
    name: Build on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Build (release)
        run: cargo build --release
        
  publish:
      name: Publish to crates.io
      runs-on: ubuntu-latest
      needs: build
      steps:
        - name: Checkout
          uses: actions/checkout@v4
        - name: Setup Rust
          uses: dtolnay/rust-toolchain@stable
        - name: Publish
          env:
            CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_API_KEY }}
          run: cargo publish