name: Publish to crates.io

on:
  workflow_dispatch:

jobs:
  crates-io:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Publish kagi-domain
        run: cargo publish -p kagi-domain --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-crypto
        run: cargo publish -p kagi-crypto --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-sync
        run: cargo publish -p kagi-sync --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-store
        run: cargo publish -p kagi-store --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-server
        run: cargo publish -p kagi-server --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-app
        run: cargo publish -p kagi-app --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Wait for index propagation
        run: sleep 45

      - name: Publish kagi-vault
        run: cargo publish -p kagi-vault --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
