moadim 0.17.0

Loop engine for AI agents — cron jobs and routines over REST, MCP, and a built-in web UI
name: Publish to crates.io

# Publish the crate. Triggered two ways:
#   * `workflow_call` from auto-release.yml on a version bump (automated path).
#   * a manual `v*` tag push (escape hatch for hotfixes cut by hand).

on:
  push:
    tags:
      - 'v*'
  workflow_call:
    inputs:
      tag:
        description: Tag to publish (e.g. v0.14.0)
        required: true
        type: string

jobs:
  publish:
    name: Publish
    runs-on: ubuntu-latest
    env:
      TAG: ${{ inputs.tag || github.ref_name }}
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

      - name: Install Rust
        uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
        with:
          toolchain: stable
          targets: wasm32-unknown-unknown

      - name: Cache cargo registry (registry only, not target)
        uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-

      - name: Install trunk
        run: cargo install --locked trunk

      - name: Build UI
        run: cargo check
        # Runs build.rs fresh (no target cache) → trunk inlines Yew UI → writes prebuilt.html
        # at the package root (not ui/): ui/ is a separate workspace member and
        # cargo publish strips it from the moadim tarball.

      - name: Verify prebuilt UI was generated
        run: test -s prebuilt.html || (echo "prebuilt.html missing or empty" && exit 1)

      - name: Verify prebuilt UI ships in the published tarball
        run: cargo package --list --allow-dirty | grep -qx prebuilt.html || (echo "prebuilt.html not in package tarball" && exit 1)

      - name: Commit prebuilt UI so cargo publish includes it
        run: |
          git config user.email "actions@github.com"
          git config user.name "GitHub Actions"
          git add prebuilt.html
          git commit -m "ci: bundle prebuilt UI"

      - name: Verify tag matches Cargo.toml version
        run: |
          CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
          TAG_VERSION=${TAG#v}
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "Version mismatch: Cargo.toml=$CARGO_VERSION, tag=$TAG_VERSION"
            exit 1
          fi

      - name: Publish
        run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --allow-dirty