name: publish

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      dry-run-only:
        description: "Run xtask publish in dry-run mode (no publish)"
        type: boolean
        required: false
        default: false

jobs:
  publish-burn-rl:
    needs:
      - publish-burn-core
      - publish-burn-optim
      # dev dependencies
      - publish-burn-flex
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-rl
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-vision:
    needs:
      - publish-burn-autodiff
      - publish-burn-candle
      - publish-burn-fusion
      - publish-burn-cubecl-fusion
      - publish-burn-cubecl
      - publish-burn-flex
      - publish-burn-tch
      - publish-burn-core
      - publish-burn-ir
      - publish-burn-store
      # dev dependencies
      - publish-burn-wgpu
      - publish-burn-cuda
      - publish-burn-backend-extension
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-vision
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-router:
    needs:
      - publish-burn-ir
      - publish-burn-std
      - publish-burn-tensor
      # dev dependencies
      - publish-burn-autodiff
      - publish-burn-flex
      - publish-burn-wgpu
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-router
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-remote:
    needs:
      - publish-burn-ir
      - publish-burn-std
      - publish-burn-tensor
      - publish-burn-router
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-remote
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-derive:
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-derive
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-dataset:
    needs:
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-dataset
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-std:
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-std
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-backend-extension:
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-backend-extension
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-tensor:
    needs:
      - publish-burn-std
      - publish-burn-backend
      - publish-burn-dispatch
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-tensor
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-backend:
    needs:
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-backend
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-ir:
    needs:
      - publish-burn-tensor
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-ir
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-fusion:
    needs:
      - publish-burn-ir
      - publish-burn-tensor
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-fusion
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-cubecl-fusion:
    needs:
      - publish-burn-ir
      - publish-burn-std
      - publish-burn-fusion
      - publish-burn-tensor
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-cubecl-fusion
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-cubecl:
    needs:
      - publish-burn-ir
      - publish-burn-std
      - publish-burn-fusion
      - publish-burn-cubecl-fusion
      - publish-burn-tensor
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-cubecl
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-autodiff:
    needs:
      - publish-burn-backend
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-autodiff
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-tch:
    needs:
      - publish-burn-tensor
      - publish-burn-autodiff
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-tch
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-ndarray:
    needs:
      - publish-burn-ir
      - publish-burn-tensor
      - publish-burn-autodiff
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-ndarray
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-flex:
    needs:
      - publish-burn-backend
      - publish-burn-ir
      - publish-burn-std
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-flex
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-wgpu:
    needs:
      - publish-burn-tensor
      - publish-burn-autodiff
      - publish-burn-std
      - publish-burn-cubecl
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-wgpu
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-cpu:
    needs:
      - publish-burn-tensor
      - publish-burn-fusion
      - publish-burn-cubecl
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-cpu
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-cuda:
    needs:
      - publish-burn-tensor
      - publish-burn-autodiff
      - publish-burn-std
      - publish-burn-cubecl
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-cuda
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-rocm:
    needs:
      - publish-burn-tensor
      - publish-burn-autodiff
      - publish-burn-std
      - publish-burn-cubecl
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-rocm
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-candle:
    needs:
      - publish-burn-tensor
      - publish-burn-autodiff
      - publish-burn-tch
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-candle
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  # publish-burn-collective:
  #   needs:
  #     - publish-burn-std
  #     - publish-burn-tensor
  #     - publish-burn-communication
  #     # dev dependencies
  #     - publish-burn-wgpu
  #     - publish-burn-flex
  #     - publish-burn-cuda
  #   uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
  #   with:
  #     crate: burn-collective
  #     dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
  #   secrets:
  #     CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-communication:
    needs:
      - publish-burn-std
      - publish-burn-tensor
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-communication
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-core:
    needs:
      - publish-burn-dataset
      - publish-burn-std
      - publish-burn-derive
      - publish-burn-tensor
      # dev dependencies
      - publish-burn-autodiff
      - publish-burn-wgpu
      - publish-burn-tch
      - publish-burn-cuda
      - publish-burn-flex
      - publish-burn-candle
      - publish-burn-remote
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-core
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-nn:
    needs:
      - publish-burn-core
      # dev dependencies
      - publish-burn-autodiff
      - publish-burn-wgpu
      - publish-burn-tch
      - publish-burn-flex
      - publish-burn-candle
      - publish-burn-remote
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-nn
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-optim:
    needs:
      - publish-burn-core
      - publish-burn-collective
      # dev dependencies
      - publish-burn-autodiff
      - publish-burn-wgpu
      - publish-burn-tch
      - publish-burn-flex
      - publish-burn-candle
      - publish-burn-remote
      - publish-burn-nn
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-optim
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-train:
    needs:
      - publish-burn-core
      - publish-burn-optim
      - publish-burn-collective
      - publish-burn-rl
      - publish-burn-flex
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-train
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-dispatch:
    needs:
      - publish-burn-std
      - publish-burn-backend
      - publish-burn-backend-extension
      - publish-burn-autodiff
      - publish-burn-cpu
      - publish-burn-cuda
      - publish-burn-rocm
      - publish-burn-wgpu
      - publish-burn-flex
      - publish-burn-ndarray
      - publish-burn-tch
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-dispatch
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn:
    needs:
      - publish-burn-core
      - publish-burn-nn
      - publish-burn-optim
      - publish-burn-collective
      - publish-burn-store
      - publish-burn-train
      - publish-burn-cpu
      - publish-burn-dispatch
      - publish-burn-flex
      - publish-burn-vision
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

  publish-burn-store:
    needs:
      - publish-burn-core
      - publish-burn-nn
      - publish-burn-tensor
    uses: tracel-ai/github-actions/.github/workflows/publish-crate.yml@v9
    with:
      crate: burn-store
      dry-run-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run-only || false }}
    secrets:
      CRATES_IO_API_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}
