leankg 0.19.13

Lightweight Knowledge Graph for AI-Assisted Development
name: Release

on:
  push:
    tags:
      - 'v*'  # Trigger on version tags like v1.0.0, v0.0.1
  # Manual retry: re-run the build/upload for an already-released tag.
  # Used when release-please pushed a lightweight tag (no `push` event
  # would fire and binaries were never attached), or when the build
  # failed after the GitHub Release was created (binaries missing).
  workflow_dispatch:
    inputs:
      tag:
        description: 'Tag to publish binaries for (e.g. v0.19.11)'
        required: true

permissions:
  contents: write

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

      - name: Install Rust
        run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

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

  build:
    strategy:
      matrix:
        include:
          - runs-on: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact: leankg-linux-x64.tar.gz
          - runs-on: macos-latest
            target: aarch64-apple-darwin
            artifact: leankg-macos-arm64.tar.gz
          - runs-on: macos-latest
            target: x86_64-apple-darwin
            artifact: leankg-macos-x64.tar.gz
          - runs-on: windows-latest
            target: x86_64-pc-windows-msvc
            artifact: leankg-windows-x64.tar.gz
    runs-on: ${{ matrix.runs-on }}
    steps:
      - uses: actions/checkout@v4

      - name: Install Bun
        uses: oven-sh/setup-bun@v2

      - name: Install Rust
        run: |
          curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
          rustup target add ${{ matrix.target }}

      - name: Build Vite UI (ui-v2 → rust_embed)
        shell: bash
        run: |
          cd ui-v2
          npm ci
          npm run build
          rm -rf ../src/embed/*
          cp -r dist/* ../src/embed/
          test -f ../src/embed/index.html
          grep -q '<title>LeanKG</title>' ../src/embed/index.html
          # RC3 guard: src/graph/export.rs `include_str!`s vis-network.min.js.
          # Fail loudly at the UI-build step (not deep inside `cargo build`)
          # when the Vite build no longer emits it.
          if ! test -f ../src/embed/vis-network.min.js; then
            echo "ERROR: vis-network.min.js missing from ui-v2 build."
            echo "  src/graph/export.rs:72 requires it via include_str!."
            echo "  Add vis-network to ui-v2/package.json deps or vendor a copy here."
            exit 1
          fi
          printf '%s\n' '{"ui":"ui-v2","source":"release.yml"}' > ../src/embed/ui-build.json

      - name: Build
        run: cargo build --release --target ${{ matrix.target }}

      - name: Package
        run: |
          mkdir -p release
          EXT=""
          if [ "${{ matrix.runs-on }}" = "windows-latest" ]; then
            EXT=".exe"
          fi
          cp target/${{ matrix.target }}/release/leankg$EXT release/leankg
          tar -czf release/${{ matrix.artifact }} -C release leankg
          # Sanity: refuse to upload a zero-byte artifact (catches tar/empty-target bugs).
          if [ ! -s "release/${{ matrix.artifact }}" ]; then
            echo "ERROR: release/${{ matrix.artifact }} is empty"
            exit 1
          fi
        shell: bash

      - uses: softprops/action-gh-release@v2
        with:
          # workflow_dispatch supplies an arbitrary tag; tag-push runs use
          # github.ref_name (refs/tags/v0.19.12 → v0.19.12).
          tag_name: ${{ inputs.tag || github.ref_name }}
          generate_release_notes: true
          files: release/${{ matrix.artifact }}