name: Build core.wasm
description: >-
  Install TinyGo (cached) and build ui/core to frontend/static/core.wasm
  and wasm_exec.js via `make -C ui wasm`. The binaries are no longer
  committed, so every workflow that builds or serves the frontend bundle
  (ui-test, dev-deploy, prod-build) runs this first. Requires Go to be
  set up by the caller — TinyGo shells out to the Go toolchain.

runs:
  using: composite
  steps:
    - name: Restore TinyGo cache
      uses: actions/cache@v4
      with:
        path: ~/.cache/galaxy-tinygo
        key: tinygo-0.41.1-linux-amd64

    - name: Install TinyGo
      shell: bash
      run: |
        set -euo pipefail
        version="0.41.1"
        root="$HOME/.cache/galaxy-tinygo/tinygo"
        if [ ! -x "$root/bin/tinygo" ]; then
          mkdir -p "$HOME/.cache/galaxy-tinygo"
          curl -fsSL "https://github.com/tinygo-org/tinygo/releases/download/v${version}/tinygo${version}.linux-amd64.tar.gz" \
            | tar -xz -C "$HOME/.cache/galaxy-tinygo"
        fi
        echo "$root/bin" >> "$GITHUB_PATH"

    - name: Build core.wasm
      shell: bash
      run: make -C ui wasm
