# Publish to crates.io after a release is created

name: Publish to crates.io

on:
  workflow_call:
  workflow_dispatch:

jobs:
  publish-crates-io:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

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

      - name: Remove unpublishable gui dep from fresh-editor
        run: |
          # fresh-gui is publish = false (GUI backend, not part of the published
          # editor surface), so it isn't on crates.io. Strip the gui feature and
          # fresh-gui dep so fresh-editor can be published.
          cd crates/fresh-editor
          sed -i '/fresh-gui/d; /fresh_gui/d' Cargo.toml
          sed -i '/^gui = \[/,/^\]/d' Cargo.toml

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --allow-dirty
