Skip to content

🧩 WASM Assets #42

🧩 WASM Assets

🧩 WASM Assets #42

Workflow file for this run

name: 🧱 Build WASM Assets
on:
workflow_call:
inputs:
force:
description: 'Force rebuild (ignore cache)'
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
force:
description: 'Force rebuild (ignore cache)'
required: false
type: boolean
default: false
# Removed push/pull_request triggers to avoid runner contention.
# WASM assets are cached and used by socketbin builds.
# Run manually via workflow_dispatch when WASM sources change.
permissions:
contents: read
concurrency:
group: build-wasm-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build-yoga-layout:
name: 🧘 Build Yoga Layout WASM
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 22
- name: Setup pnpm
uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0
with:
version: ^10.16.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate yoga build cache key
id: yoga-cache-key
run: |
HASH=$(find packages/yoga-layout -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.mjs" -o -name "CMakeLists.txt" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
- name: Restore yoga output cache
id: yoga-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/yoga-layout/build/wasm
key: yoga-wasm-${{ steps.yoga-cache-key.outputs.hash }}
restore-keys: yoga-wasm-
enableCrossOsArchive: true
- name: Restore yoga build cache
id: yoga-build-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/yoga-layout/build
key: yoga-build-${{ steps.yoga-cache-key.outputs.hash }}
restore-keys: |
yoga-build-
- name: Verify cached artifacts
id: yoga-cache-valid
run: |
if [ -f "packages/yoga-layout/build/wasm/yoga.wasm" ] && [ -f "packages/yoga-layout/build/wasm/yoga.js" ]; then
echo "valid=true" >> $GITHUB_OUTPUT
echo "Cache hit: artifacts found"
ls -lh packages/yoga-layout/build/wasm/
else
echo "valid=false" >> $GITHUB_OUTPUT
echo "Cache miss or incomplete: forcing rebuild"
ls -lh packages/yoga-layout/build/wasm/ 2>/dev/null || echo "Directory does not exist"
fi
- name: Install Emscripten
if: steps.yoga-cache-valid.outputs.valid != 'true' || inputs.force
run: |
echo "::group::Installing Emscripten"
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
echo "::endgroup::"
- name: Build Yoga Layout WASM
if: steps.yoga-cache-valid.outputs.valid != 'true' || inputs.force
run: |
echo "::group::Building Yoga Layout WASM"
source emsdk/emsdk_env.sh
if [ "${{ inputs.force }}" = "true" ]; then
pnpm --filter @socketsecurity/yoga-layout run build -- --force
else
pnpm --filter @socketsecurity/yoga-layout run build
fi
echo "Build exit code: $?"
echo "Checking for build artifacts..."
ls -lh packages/yoga-layout/build/wasm/ || echo "wasm directory not found"
ls -lh packages/yoga-layout/build/cmake/ || echo "cmake directory not found"
echo "::endgroup::"
- name: Verify build artifacts
run: |
echo "=== Yoga Layout Build Artifacts ==="
if [ ! -f "packages/yoga-layout/build/wasm/yoga.wasm" ] || [ ! -f "packages/yoga-layout/build/wasm/yoga.js" ]; then
echo "ERROR: Required WASM artifacts not found!"
ls -lh packages/yoga-layout/build/wasm/ || echo "Directory does not exist"
exit 1
fi
ls -lh packages/yoga-layout/build/wasm/
echo ""
echo "yoga.wasm size: $(du -h packages/yoga-layout/build/wasm/yoga.wasm | cut -f1)"
echo "yoga.js size: $(du -h packages/yoga-layout/build/wasm/yoga.js | cut -f1)"
- name: Upload yoga artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: yoga-wasm
path: packages/yoga-layout/build/wasm/
retention-days: 7
build-ai-models:
name: πŸ€– Build AI Models WASM
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 22
- name: Setup pnpm
uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0
with:
version: ^10.16.0
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.11'
- name: Install Python dependencies (large packages without cache)
run: |
echo "::group::Installing large Python packages (torch, transformers)"
# Install large packages without caching to avoid cache service failures.
# torch (~700MB-2GB) and transformers (~500MB-1GB) are too large for
# GitHub's cache service and cause 400 errors.
pip install --no-cache-dir torch transformers
echo "::endgroup::"
- name: Install Python dependencies (smaller packages with cache)
run: |
echo "::group::Installing remaining Python dependencies"
# Install smaller packages normally (optimum, onnxruntime).
# These are cached by pip's default cache location.
pip install optimum[onnx] onnxruntime>=1.21.0
echo "::endgroup::"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate AI models cache key
id: ai-cache-key
run: |
HASH=$(find packages/socketbin-cli-ai -type f \( -name "*.mjs" -o -name "*.ts" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
- name: Restore AI models cache
id: ai-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/socketbin-cli-ai/dist
key: ai-models-${{ steps.ai-cache-key.outputs.hash }}
restore-keys: ai-models-
enableCrossOsArchive: true
- name: Verify cached artifacts
id: ai-cache-valid
run: |
if [ -f "packages/socketbin-cli-ai/dist/ai.bz" ] && [ -f "packages/socketbin-cli-ai/dist/ai.js" ]; then
echo "valid=true" >> $GITHUB_OUTPUT
echo "Cache hit: artifacts found"
ls -lh packages/socketbin-cli-ai/dist/
else
echo "valid=false" >> $GITHUB_OUTPUT
echo "Cache miss or incomplete: forcing rebuild"
ls -lh packages/socketbin-cli-ai/dist/ 2>/dev/null || echo "Directory does not exist"
fi
- name: Build AI models
if: steps.ai-cache-valid.outputs.valid != 'true' || inputs.force
run: |
echo "::group::Building AI models (this will take 10-15 minutes)"
if [ "${{ inputs.force }}" = "true" ]; then
pnpm --filter @socketbin/cli-ai run build -- --force
else
pnpm --filter @socketbin/cli-ai run build
fi
echo "Build exit code: $?"
echo "Checking for build artifacts..."
ls -lh packages/socketbin-cli-ai/dist/ || echo "dist directory not found"
echo "::endgroup::"
- name: Verify build artifacts
run: |
echo "=== AI Models Build Artifacts ==="
if [ ! -f "packages/socketbin-cli-ai/dist/ai.bz" ] || [ ! -f "packages/socketbin-cli-ai/dist/ai.js" ]; then
echo "ERROR: Required AI model artifacts not found!"
ls -lh packages/socketbin-cli-ai/dist/ || echo "Directory does not exist"
exit 1
fi
ls -lh packages/socketbin-cli-ai/dist/
echo ""
echo "ai.bz size: $(du -h packages/socketbin-cli-ai/dist/ai.bz | cut -f1)"
echo "ai.js size: $(du -h packages/socketbin-cli-ai/dist/ai.js | cut -f1)"
- name: Upload AI artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ai-models
path: packages/socketbin-cli-ai/dist/
retention-days: 7
build-onnx-runtime:
name: 🌐 Build ONNX Runtime WASM
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 22
- name: Setup pnpm
uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0
with:
version: ^10.16.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate ONNX Runtime cache key
id: onnx-cache-key
run: |
HASH=$(find packages/onnxruntime -type f \( -name "*.mjs" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
- name: Restore ONNX Runtime output cache
id: onnx-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/onnxruntime/build/wasm
key: onnx-runtime-${{ steps.onnx-cache-key.outputs.hash }}
restore-keys: onnx-runtime-
enableCrossOsArchive: true
- name: Restore ONNX Runtime build cache
id: onnx-build-cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/onnxruntime/build
key: onnx-runtime-build-${{ steps.onnx-cache-key.outputs.hash }}
restore-keys: |
onnx-runtime-build-
- name: Verify cached artifacts
id: onnx-cache-valid
run: |
if [ -f "packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.wasm" ] && [ -f "packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.js" ]; then
echo "valid=true" >> $GITHUB_OUTPUT
echo "Cache hit: artifacts found"
ls -lh packages/onnxruntime/build/wasm/
else
echo "valid=false" >> $GITHUB_OUTPUT
echo "Cache miss or incomplete: forcing rebuild"
ls -lh packages/onnxruntime/build/wasm/ 2>/dev/null || echo "Directory does not exist"
fi
- name: Install Emscripten
if: steps.onnx-cache-valid.outputs.valid != 'true' || inputs.force
run: |
echo "::group::Installing Emscripten"
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
echo "::endgroup::"
- name: Build ONNX Runtime WASM
if: steps.onnx-cache-valid.outputs.valid != 'true' || inputs.force
run: |
echo "::group::Building ONNX Runtime WASM (this will take 30-60 minutes)"
source emsdk/emsdk_env.sh
if [ "${{ inputs.force }}" = "true" ]; then
pnpm --filter @socketsecurity/onnxruntime run build -- --force
else
pnpm --filter @socketsecurity/onnxruntime run build
fi
echo "Build exit code: $?"
echo "Checking for build artifacts..."
ls -lh packages/onnxruntime/build/wasm/ || echo "wasm directory not found"
echo "::endgroup::"
- name: Save ONNX Runtime build cache
if: always() && (steps.onnx-cache-valid.outputs.valid != 'true' || inputs.force)
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: packages/onnxruntime/build
key: onnx-runtime-build-${{ steps.onnx-cache-key.outputs.hash }}-${{ github.run_id }}
- name: Verify build artifacts
run: |
echo "=== ONNX Runtime Build Artifacts ==="
if [ ! -f "packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.wasm" ] || [ ! -f "packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.js" ]; then
echo "ERROR: Required ONNX Runtime WASM artifacts not found!"
ls -lh packages/onnxruntime/build/wasm/ || echo "Directory does not exist"
exit 1
fi
ls -lh packages/onnxruntime/build/wasm/
echo ""
echo "ort-wasm-simd-threaded.wasm size: $(du -h packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.wasm | cut -f1)"
echo "ort-wasm-simd-threaded.js size: $(du -h packages/onnxruntime/build/wasm/ort-wasm-simd-threaded.js | cut -f1)"
- name: Upload ONNX Runtime artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: onnx-runtime
path: packages/onnxruntime/build/wasm/
retention-days: 7
summary:
name: πŸ“Š 🧱 WASM Build Summary
needs: [build-yoga-layout, build-ai-models, build-onnx-runtime]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
with:
path: artifacts
- name: Generate summary
run: |
echo "# 🧱 WASM Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## βœ… Build Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All WASM assets built successfully and cached." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“¦ Artifacts" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Asset | Files |" >> $GITHUB_STEP_SUMMARY
echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| 🧘 Yoga Layout | \`yoga.wasm\`, \`yoga.js\` |" >> $GITHUB_STEP_SUMMARY
echo "| πŸ€– AI Models | \`ai.bz\`, \`ai.js\` |" >> $GITHUB_STEP_SUMMARY
echo "| 🌐 ONNX Runtime | \`ort-wasm-simd-threaded.wasm\`, \`ort-wasm-simd-threaded.js\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🎯 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- These artifacts are now cached for CI builds" >> $GITHUB_STEP_SUMMARY
echo "- CLI builds will use these cached WASM assets" >> $GITHUB_STEP_SUMMARY
echo "- Cache is invalidated when source files change" >> $GITHUB_STEP_SUMMARY