|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Downloads the rules engine WASM binary from the schematic-api GitHub Release. |
| 5 | +# Reads the pinned version from WASM_VERSION at the repo root. |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 8 | +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 9 | +WASM_DIR="$REPO_ROOT/src/schematic/datastream/wasm" |
| 10 | +VERSION_FILE="$REPO_ROOT/WASM_VERSION" |
| 11 | +TARGET_FILE="$WASM_DIR/rulesengine.wasm" |
| 12 | + |
| 13 | +GITHUB_REPO="SchematicHQ/schematic-api" |
| 14 | + |
| 15 | +if [ ! -f "$VERSION_FILE" ]; then |
| 16 | + echo "ERROR: WASM_VERSION file not found at $VERSION_FILE" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +VERSION=$(tr -d '[:space:]' < "$VERSION_FILE") |
| 21 | +TAG="rulesengine/v${VERSION}" |
| 22 | + |
| 23 | +# Skip download if binary already exists and version matches |
| 24 | +if [ -f "$TARGET_FILE" ] && [ -f "$WASM_DIR/.wasm_version" ]; then |
| 25 | + CURRENT=$(tr -d '[:space:]' < "$WASM_DIR/.wasm_version") |
| 26 | + if [ "$CURRENT" = "$VERSION" ]; then |
| 27 | + echo "WASM binary already at version $VERSION, skipping download." |
| 28 | + exit 0 |
| 29 | + fi |
| 30 | +fi |
| 31 | + |
| 32 | +ASSET_NAME="rulesengine-wasm-python-v${VERSION}.tar.gz" |
| 33 | + |
| 34 | +echo "Downloading rules engine WASM v${VERSION}..." |
| 35 | +mkdir -p "$WASM_DIR" |
| 36 | + |
| 37 | +TMPDIR=$(mktemp -d) |
| 38 | +trap 'rm -rf "$TMPDIR"' EXIT |
| 39 | + |
| 40 | +if ! gh release download "$TAG" \ |
| 41 | + -R "$GITHUB_REPO" \ |
| 42 | + -p "$ASSET_NAME" \ |
| 43 | + -D "$TMPDIR" 2>/dev/null; then |
| 44 | + echo "ERROR: Failed to download WASM binary" |
| 45 | + echo "Tag: $TAG" |
| 46 | + echo "Asset: $ASSET_NAME" |
| 47 | + echo "" |
| 48 | + echo "If this is a new version, ensure a release exists at:" |
| 49 | + echo " https://github.com/${GITHUB_REPO}/releases/tag/${TAG}" |
| 50 | + echo "" |
| 51 | + echo "Ensure the GitHub CLI is authenticated: gh auth status" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +tar -xzf "$TMPDIR/$ASSET_NAME" -C "$TMPDIR" |
| 56 | + |
| 57 | +if [ ! -f "$TMPDIR/rulesengine.wasm" ]; then |
| 58 | + echo "ERROR: rulesengine.wasm not found in release archive" |
| 59 | + ls -la "$TMPDIR" |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +cp "$TMPDIR/rulesengine.wasm" "$TARGET_FILE" |
| 64 | +echo "$VERSION" > "$WASM_DIR/.wasm_version" |
| 65 | + |
| 66 | +echo "Downloaded rules engine WASM v${VERSION} to $TARGET_FILE" |
0 commit comments