|
| 1 | +name: 🔧 Build WASM Bundle |
| 2 | + |
| 3 | +# Manual workflow for building the unified WASM bundle with AI models. |
| 4 | +# This creates a separate release (wasm-build-*) to keep WASM bundles |
| 5 | +# separate from regular Socket CLI releases. |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + force-rebuild: |
| 11 | + description: 'Force rebuild even if build already exists for this commit' |
| 12 | + required: false |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write # Required for creating releases and uploading assets |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-wasm: |
| 21 | + name: Build WASM Bundle |
| 22 | + runs-on: ubuntu-latest |
| 23 | + timeout-minutes: 60 |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 28 | + |
| 29 | + - name: Setup Node.js |
| 30 | + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 |
| 31 | + with: |
| 32 | + node-version: '22' |
| 33 | + |
| 34 | + - name: Setup pnpm |
| 35 | + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: pnpm install --frozen-lockfile |
| 39 | + |
| 40 | + - name: Setup Python |
| 41 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 42 | + with: |
| 43 | + python-version: '3.11' |
| 44 | + |
| 45 | + - name: Setup Rust |
| 46 | + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable |
| 47 | + with: |
| 48 | + toolchain: stable |
| 49 | + targets: wasm32-unknown-unknown |
| 50 | + |
| 51 | + - name: Install wasm-pack |
| 52 | + run: cargo install wasm-pack |
| 53 | + |
| 54 | + - name: Install wasm-opt (binaryen) |
| 55 | + run: | |
| 56 | + sudo apt-get update |
| 57 | + sudo apt-get install -y binaryen |
| 58 | +
|
| 59 | + - name: Generate build tag |
| 60 | + id: build-tag |
| 61 | + run: | |
| 62 | + BUILD_DATE=$(date +'%Y%m%d') |
| 63 | + SHORT_SHA=$(git rev-parse --short HEAD) |
| 64 | + BUILD_TAG="wasm-build-${BUILD_DATE}-${SHORT_SHA}" |
| 65 | + echo "tag=${BUILD_TAG}" >> $GITHUB_OUTPUT |
| 66 | + echo "date=${BUILD_DATE}" >> $GITHUB_OUTPUT |
| 67 | + echo "sha=${SHORT_SHA}" >> $GITHUB_OUTPUT |
| 68 | +
|
| 69 | + - name: Check if release exists |
| 70 | + id: check-release |
| 71 | + run: | |
| 72 | + TAG="${{ steps.build-tag.outputs.tag }}" |
| 73 | + if gh release view "$TAG" >/dev/null 2>&1; then |
| 74 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 75 | + echo "Release $TAG already exists" |
| 76 | + else |
| 77 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 78 | + echo "Release $TAG does not exist" |
| 79 | + fi |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ github.token }} |
| 82 | + |
| 83 | + - name: Exit if release exists and not force rebuild |
| 84 | + if: steps.check-release.outputs.exists == 'true' && !inputs.force-rebuild |
| 85 | + run: | |
| 86 | + echo "❌ Release ${{ steps.build-tag.outputs.tag }} already exists" |
| 87 | + echo " Use 'force-rebuild' option to rebuild anyway" |
| 88 | + exit 1 |
| 89 | +
|
| 90 | + - name: Build WASM bundle |
| 91 | + run: node scripts/wasm.mjs --build |
| 92 | + env: |
| 93 | + CI: true |
| 94 | + |
| 95 | + - name: Verify build output |
| 96 | + run: | |
| 97 | + if [ ! -f external/socket-ai-sync.mjs ]; then |
| 98 | + echo "❌ Build output not found: external/socket-ai-sync.mjs" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + FILE_SIZE=$(stat -f%z external/socket-ai-sync.mjs 2>/dev/null || stat -c%s external/socket-ai-sync.mjs) |
| 103 | + FILE_SIZE_MB=$((FILE_SIZE / 1024 / 1024)) |
| 104 | +
|
| 105 | + echo "✓ Build output verified" |
| 106 | + echo " Size: ${FILE_SIZE_MB} MB" |
| 107 | +
|
| 108 | + if [ "$FILE_SIZE_MB" -lt 50 ]; then |
| 109 | + echo "❌ Build output too small (expected ~115MB)" |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | +
|
| 113 | + - name: Create release |
| 114 | + if: steps.check-release.outputs.exists == 'false' || inputs.force-rebuild |
| 115 | + run: | |
| 116 | + TAG="${{ steps.build-tag.outputs.tag }}" |
| 117 | + DATE="${{ steps.build-tag.outputs.date }}" |
| 118 | + SHA="${{ steps.build-tag.outputs.sha }}" |
| 119 | +
|
| 120 | + gh release create "$TAG" \ |
| 121 | + --title "WASM Bundle Build ${DATE}" \ |
| 122 | + --notes "## WASM Bundle Build |
| 123 | +
|
| 124 | + **Automated build of unified WASM bundle for Socket CLI AI features.** |
| 125 | +
|
| 126 | + ### Build Information |
| 127 | + - **Date**: $(date +'%Y-%m-%d %H:%M:%S UTC') |
| 128 | + - **Commit**: ${SHA} |
| 129 | + - **Tag**: ${TAG} |
| 130 | +
|
| 131 | + ### Contents |
| 132 | + - ONNX Runtime (~2-5MB) |
| 133 | + - MiniLM model (~17MB int8) |
| 134 | + - CodeT5 encoder (~30MB int4) |
| 135 | + - CodeT5 decoder (~60MB int4) |
| 136 | + - Tokenizers (~1MB) |
| 137 | + - Yoga Layout (~95KB) |
| 138 | +
|
| 139 | + ### INT4 Quantization |
| 140 | + - CodeT5 models use INT4 (4-bit weights) for 50% size reduction |
| 141 | + - Only 1-2% quality loss compared to INT8 |
| 142 | + - Total bundle size: ~115MB (vs ~145MB with INT8) |
| 143 | +
|
| 144 | + ### Download |
| 145 | + \`\`\`bash |
| 146 | + node scripts/wasm.mjs --download |
| 147 | + \`\`\` |
| 148 | +
|
| 149 | + ### Build from Source |
| 150 | + \`\`\`bash |
| 151 | + node scripts/wasm.mjs --build |
| 152 | + \`\`\` |
| 153 | +
|
| 154 | + --- |
| 155 | +
|
| 156 | + This is a pre-release for internal development use." \ |
| 157 | + --prerelease \ |
| 158 | + external/socket-ai-sync.mjs |
| 159 | + env: |
| 160 | + GH_TOKEN: ${{ github.token }} |
| 161 | + |
| 162 | + - name: Upload artifact (for debugging) |
| 163 | + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 |
| 164 | + with: |
| 165 | + name: wasm-bundle-${{ steps.build-tag.outputs.tag }} |
| 166 | + path: external/socket-ai-sync.mjs |
| 167 | + retention-days: 7 |
| 168 | + |
| 169 | + - name: Build summary |
| 170 | + run: | |
| 171 | + FILE_SIZE=$(stat -f%z external/socket-ai-sync.mjs 2>/dev/null || stat -c%s external/socket-ai-sync.mjs) |
| 172 | + FILE_SIZE_MB=$((FILE_SIZE / 1024 / 1024)) |
| 173 | +
|
| 174 | + echo "## ✅ WASM Bundle Build Complete" >> $GITHUB_STEP_SUMMARY |
| 175 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 176 | + echo "**Tag**: \`${{ steps.build-tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY |
| 177 | + echo "**Size**: ${FILE_SIZE_MB} MB" >> $GITHUB_STEP_SUMMARY |
| 178 | + echo "**Date**: $(date +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY |
| 179 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 180 | + echo "### Download" >> $GITHUB_STEP_SUMMARY |
| 181 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "node scripts/wasm.mjs --download" >> $GITHUB_STEP_SUMMARY |
| 183 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
0 commit comments