openpencil/.github/workflows/web-sdk-bundle.yml
Kayshen-X d023dbf1de feat(web): fetch scene templates and the icon catalog at runtime
The 58 template documents and the core iconify catalog follow the
previews out of the wasm binary behind the same asset seam: templates
resolve by id on both platforms but carry bytes only natively, so the
wasm boot check validates routes instead of rejecting the catalogue,
and a click on an unfetched card requests the asset and instantiates
on the install edge (failure raises the retryable toast). The icon
picker prefetches while open, distinguishes "still loading" from "no
match", and keys its search memo on catalog readiness so the empty
pre-fetch result cannot be memoized for the session. The split is a
feature (runtime-icon-catalog) enabled only by op-host-web — the
web-sdk viewer has no daemon to fetch from and keeps the embed, which
a first cut silently broke. Bundle: 5.10 → 4.93 MiB gzip; the sdk
bundle (5.20 MiB measured) gets a calibrated 6 MiB tripwire.
2026-08-09 12:26:39 +08:00

117 lines
5 KiB
YAML

name: op-web-sdk bundle build + size gate
# Builds the op-web-sdk WASM package (canvaskit feature), asserts 0 env.*
# imports and gzip size <= 6 MiB (this viewer bundle's own measured tripwire —
# 5 200 519 bytes + ~20% headroom), then uploads pkg/ as the `op-web-sdk-bundle`
# artifact. This is the CI counterpart of the local
# `crates/op-web-sdk/tools/build-wasm.sh` developer gate.
#
# Mirrors `wasm-bundle-build.yml` (op-host-web gate) verbatim except for the
# crate path, artifact name, and env-var ceiling override name. In particular,
# this job does NOT use wasm-pack: wasm-pack 0.13.1 is broken on stable Rust
# (schema mismatch) and introduces a floating binary install risk. Instead we
# use the same cargo + wasm-bindgen-cli (version-pinned from Cargo.lock) +
# wasm-opt pipeline that `wasm-bundle-build.yml` uses.
#
# Authoritative recipe mirrored from `crates/op-web-sdk/tools/build-wasm.sh`:
# prerequisites: cargo, wasm-bindgen, wasm-opt, node, gzip (NO wasm-pack, NO EMSDK)
# 1. cargo build -p op-web-sdk --target wasm32-unknown-unknown
# --features canvaskit --release
# 2. wasm-bindgen --target web --out-dir crates/op-web-sdk/pkg <target.wasm>
# 3. assert 0 env.* imports (LinkError guard)
# 4. wasm-opt -Oz with rustc-emitted WebAssembly feature flags, then
# gzip size <= ceiling (default 6291456 bytes = 6 MiB, overridable via
# OP_WEB_SDK_WASM_GZIP_LIMIT_BYTES)
# The job calls the script directly — it is the single source of truth for the
# gate logic.
on:
pull_request:
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'crates/op-web-sdk/**'
- 'deny.toml'
- '.github/workflows/web-sdk-bundle.yml'
push:
branches: ['**']
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'crates/op-web-sdk/**'
- '.github/workflows/web-sdk-bundle.yml'
# Allow on-demand runs so a release can produce the artifact without a code
# change (e.g. to re-bundle against an updated toolchain).
workflow_dispatch:
jobs:
build-web-sdk-bundle:
name: build + size-gate op-web-sdk wasm bundle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: '1.94'
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
with:
shared-key: web-sdk-bundle
- name: Install wasm-bindgen-cli (pinned to the locked version)
run: |
# Pin the CLI to the same version as the `wasm-bindgen` crate in
# Cargo.lock so the generated JS glue matches the linked runtime —
# a version skew between the two causes a "schema version mismatch"
# panic at mount time. Read the locked version straight out of
# Cargo.lock (the [[package]] block whose name is exactly `wasm-bindgen`).
# This mirrors wasm-bundle-build.yml exactly (same awk extractor).
version="$(awk '/^name = "wasm-bindgen"$/{found=1; next} found && /^version = /{gsub(/[" ]/,"",$3); print $3; exit}' Cargo.lock)"
if [ -z "$version" ]; then
echo "::error::could not resolve wasm-bindgen version from Cargo.lock"
exit 1
fi
echo "Installing wasm-bindgen-cli $version"
cargo install wasm-bindgen-cli --version "$version" --locked
- name: Install binaryen (pinned modern release)
run: |
# Ubuntu's apt `binaryen` is v108 — too old for rustc 1.94's wasm
# (memory.copy/fill from bulk-memory-opt), so `wasm-opt` rejects the
# bundle with "all used features should be allowed". Pin a modern
# release matching the local dev toolchain / wasm-bundle-build.yml.
BINARYEN_VERSION=version_123
curl -fsSL \
"https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
| tar -xz
echo "${GITHUB_WORKSPACE}/binaryen-${BINARYEN_VERSION}/bin" >> "$GITHUB_PATH"
"${GITHUB_WORKSPACE}/binaryen-${BINARYEN_VERSION}/bin/wasm-opt" --version
- name: Verify node + gzip are present (script prerequisites)
run: |
node --version
gzip --version | head -n1
wasm-bindgen --version
# Single source of truth: run the crate-local gate script verbatim. It
# runs cargo build (canvaskit) -> wasm-bindgen --target web ->
# 0-env-import assert -> wasm-opt -Oz -> gzip size <= ceiling, and exits
# non-zero on any breach.
- name: Build + size-gate the op-web-sdk bundle
run: bash crates/op-web-sdk/tools/build-wasm.sh
- name: Upload op-web-sdk-bundle artifact
uses: actions/upload-artifact@v4
with:
name: op-web-sdk-bundle
# Upload the full wasm-pack output directory: wasm + JS glue + .d.ts.
path: crates/op-web-sdk/pkg
if-no-files-found: error
# Keep briefly so a downstream release / Docker build can pull it
# without rebuilding.
retention-days: 14