π§© WASM Assets #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| node-version: 22 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.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 build 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- | |
| - 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 | |
| pnpm --filter @socketsecurity/yoga-layout run build | |
| 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@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
| 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@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| node-version: 22 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 | |
| with: | |
| version: ^10.16.0 | |
| - name: Setup Python | |
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| cache-dependency-path: 'packages/socketbin-cli-ai/requirements.txt' | |
| - name: Install Python dependencies | |
| run: | | |
| echo "::group::Installing Python dependencies" | |
| pip install --upgrade pip | |
| pip install -r packages/socketbin-cli-ai/requirements.txt | |
| 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- | |
| - 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)" | |
| pnpm --filter @socketbin/cli-ai run build | |
| 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@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
| 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@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 | |
| with: | |
| node-version: 22 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.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/onnx-runtime-builder -type f \( -name "*.mjs" -o -name "*.patch" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1) | |
| echo "hash=$HASH" >> $GITHUB_OUTPUT | |
| - name: Restore ONNX Runtime cache | |
| id: onnx-cache | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: packages/onnx-runtime-builder/dist | |
| key: onnx-runtime-${{ steps.onnx-cache-key.outputs.hash }} | |
| restore-keys: onnx-runtime- | |
| - name: Verify cached artifacts | |
| id: onnx-cache-valid | |
| run: | | |
| if [ -f "packages/onnx-runtime-builder/dist/onnxruntime-web.wasm" ]; then | |
| echo "valid=true" >> $GITHUB_OUTPUT | |
| echo "Cache hit: artifacts found" | |
| ls -lh packages/onnx-runtime-builder/dist/ | |
| else | |
| echo "valid=false" >> $GITHUB_OUTPUT | |
| echo "Cache miss or incomplete: forcing rebuild" | |
| ls -lh packages/onnx-runtime-builder/dist/ 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 20-30 minutes)" | |
| source emsdk/emsdk_env.sh | |
| pnpm --filter @socketsecurity/onnx-runtime-builder run build | |
| echo "Build exit code: $?" | |
| echo "Checking for build artifacts..." | |
| ls -lh packages/onnx-runtime-builder/dist/ || echo "dist directory not found" | |
| echo "::endgroup::" | |
| - name: Verify build artifacts | |
| run: | | |
| echo "=== ONNX Runtime Build Artifacts ===" | |
| if [ ! -f "packages/onnx-runtime-builder/dist/onnxruntime-web.wasm" ]; then | |
| echo "ERROR: Required ONNX Runtime WASM artifact not found!" | |
| ls -lh packages/onnx-runtime-builder/dist/ || echo "Directory does not exist" | |
| exit 1 | |
| fi | |
| ls -lh packages/onnx-runtime-builder/dist/ | |
| echo "" | |
| echo "onnxruntime-web.wasm size: $(du -h packages/onnx-runtime-builder/dist/onnxruntime-web.wasm | cut -f1)" | |
| - name: Upload ONNX Runtime artifacts | |
| uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
| with: | |
| name: onnx-runtime | |
| path: packages/onnx-runtime-builder/dist/ | |
| 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@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
| 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.wasm\` |" >> $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 |