Skip to content

Self-improving AI Employees for everyone

v0.0.8 - Add cross-platform binary downloads for npm install

trohitg01804519f95e
diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml
new file mode 100644
index 00000000..b06588b2
--- /dev/null
+++ b/.github/workflows/build-binaries.yml
@@ -0,0 +1,97 @@
+# Build and release pre-compiled binaries for all platforms
+# Triggers on version tags (v*.*.*)
+# Uses native runners for CGO compilation (required for WhatsApp SQLite)
+
+name: Build Binaries
+
+on:
+ push:
+ tags:
+ - 'v*.*.*'
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+jobs:
+ build-go-binaries:
+ name: Build Go (${{ matrix.goos }}-${{ matrix.goarch }})
+ strategy:
+ matrix:
+ include:
+ - os: ubuntu-latest
+ goos: linux
+ goarch: amd64
+ suffix: ''
+ - os: macos-13
+ goos: darwin
+ goarch: amd64
+ suffix: ''
+ - os: macos-14
+ goos: darwin
+ goarch: arm64
+ suffix: ''
+ - os: windows-latest
+ goos: windows
+ goarch: amd64
+ suffix: '.exe'
+ runs-on: ${{ matrix.os }}
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: '1.24'
+ cache-dependency-path: server/whatsapp-rpc/go.sum
+
+ - name: Install GCC (Windows)
+ if: matrix.os == 'windows-latest'
+ run: choco install mingw -y
+
+ - name: Build WhatsApp RPC Server
+ working-directory: server/whatsapp-rpc
+ env:
+ CGO_ENABLED: 1
+ run: go build -ldflags="-s -w" -o whatsapp-rpc-server-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }} ./src/go/cmd/server
+
+ - name: Upload artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: whatsapp-rpc-server-${{ matrix.goos }}-${{ matrix.goarch }}
+ path: server/whatsapp-rpc/whatsapp-rpc-server-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}
+ retention-days: 1
+
+ release:
+ name: Create Release
+ needs: build-go-binaries
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Download all artifacts
+ uses: actions/download-artifact@v4
+ with:
+ path: binaries
+ merge-multiple: true
+
+ - name: Generate checksums
+ working-directory: binaries
+ run: |
+ sha256sum whatsapp-rpc-server-* > checksums-sha256.txt
+ cat checksums-sha256.txt
+
+ - name: Create GitHub Release
+ uses: softprops/action-gh-release@v1
+ with:
+ generate_release_notes: true
+ draft: false
+ prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
+ files: |
+ binaries/whatsapp-rpc-server-*
+ binaries/checksums-sha256.txt
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
deleted file mode 100644
index f0ef99b2..00000000
--- a/.github/workflows/release.yml
+++ /dev/null
@@ -1,49 +0,0 @@
-# Release workflow - creates GitHub Release when version tag is pushed
-# Generates release notes automatically from commit history
-
-name: Release
-
-on:
- push:
- tags:
- - 'v*.*.*'
-
-permissions:
- contents: write
-
-jobs:
- release:
- runs-on: ubuntu-latest
- steps:
- - name: Checkout
- uses: actions/checkout@v4
- with:
- fetch-depth: 0 # Needed for release notes generation
-
- - name: Setup Node.js
- uses: actions/setup-node@v4
- with:
- node-version: '20'
-
- - name: Setup Python
- uses: actions/setup-python@v5
- with:
- python-version: '3.12'
-
- - name: Setup Go
- uses: actions/setup-go@v5
- with:
- go-version: '1.21'
-
- - name: Install uv
- run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.cargo/bin" >> $GITHUB_PATH
-
- - name: Build all services
- run: npm run build
-
- - name: Create GitHub Release
- uses: softprops/action-gh-release@v1
- with:
- generate_release_notes: true
- draft: false
- prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
diff --git a/package.json b/package.json
index 1db7bd7f..63f62df9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "machinaos",
- "version": "0.0.7",
+ "version": "0.0.8",
"description": "Open source workflow automation platform with AI agents, React Flow, and n8n-inspired architecture",
"type": "module",
"keywords": [
@@ -71,7 +71,7 @@
"deploy": "bash deploy.sh",
"deploy:gcp": "bash deploy.sh",
"prepublishOnly": "node -e \"const p=require('./package.json'); if(!p.bin||!p.version){process.exit(1)}\"",
- "postinstall": "node scripts/build.js"
+ "postinstall": "node scripts/postinstall.js"
},
"dependencies": {
"concurrently": "^9.2.1",
diff --git a/scripts/build.js b/scripts/build.js
index 8e06c231..eb361ee2 100644
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -32,7 +32,6 @@ if (isCI && isPostInstall) {
process.exit(0);
}
-
// Ensure Python UTF-8 encoding
process.env.PYTHONUTF8 = '1';
diff --git a/scripts/download-binaries.js b/scripts/download-binaries.js
new file mode 100644
index 00000000..4a017190
--- /dev/null
+++ b/scripts/download-binaries.js
@@ -0,0 +1,178 @@
+#!/usr/bin/env node
+/**
+ * Optional binary download script for MachinaOS.
+ * Downloads pre-built WhatsApp RPC server binary from GitHub Releases.
+ *
+ * Skipped if:
+ * - MACHINAOS_SKIP_BINARY_DOWNLOAD=1
+ * - CI environment (CI=true)
+ * - Go is installed (can build from source)
+ *
+ * Force download even if Go installed:
+ * - MACHINAOS_FORCE_BINARY_DOWNLOAD=1
+ */
+import { execSync } from 'child_process';
+import { createWriteStream, existsSync, mkdirSync, chmodSync, readFileSync } from 'fs';
+import { resolve, dirname } from 'path';
+import { fileURLToPath } from 'url';
+import https from 'https';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const ROOT = resolve(__dirname, '..');
+const WHATSAPP_BIN_DIR = resolve(ROOT, 'server/whatsapp-rpc/bin');
+
+// Read version from package.json
+const pkg = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf-8'));
+const VERSION = pkg.version;
+
+// GitHub release URL
+const GITHUB_REPO = 'trohitg/MachinaOS';
+const BASE_URL = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}`;
+
+// Platform detection
+function getPlatformInfo() {
+ const osMap = { 'win32': 'windows', 'darwin': 'darwin', 'linux': 'linux' };
+ const archMap = { 'x64': 'amd64', 'arm64': 'arm64' };
+
+ const os = osMap[process.platform];
+ const goarch = archMap[process.arch];
+
+ if (!os || !goarch) {
+ return null;
+ }
+
+ const ext = process.platform === 'win32' ? '.exe' : '';
+ return { os, goarch, ext };
+}
+
+// Check if Go is installed
+function hasGo() {
+ try {
+ execSync('go version', { stdio: 'ignore' });
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+// Download file with redirect handling
+function downloadFile(url, dest) {
+ return new Promise((resolve, reject) => {
+ const request = (currentUrl, redirectCount = 0) => {
+ if (redirectCount > 5) {
+ reject(new Error('Too many redirects'));
+ return;
+ }
+
+ const client = currentUrl.startsWith('https') ? https : require('http');
+
+ client.get(currentUrl, (response) => {
+ // Handle redirects (GitHub releases redirect to CDN)
+ if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
+ request(response.headers.location, redirectCount + 1);
+ return;
+ }
+
+ if (response.statusCode !== 200) {
+ reject(new Error(`HTTP ${response.statusCode}`));
+ return;
+ }
+
+ const file = createWriteStream(dest);
+ const totalBytes = parseInt(response.headers['content-length'], 10);
+ let downloadedBytes = 0;
+
+ response.on('data', (chunk) => {
+ downloadedBytes += chunk.length;
+ if (totalBytes) {
+ const percent = ((downloadedBytes / totalBytes) * 100).toFixed(1);
+ process.stdout.write(`\r Downloading: ${percent}%`);
+ }
+ });
+
+ response.pipe(file);
+ file.on('finish', () => {
+ file.close();
+ console.log(' Done');
+ resolve();
+ });
+ file.on('error', (err) => {
+ file.close();
+ reject(err);
+ });
+ }).on('error', reject);
+ };
+
+ request(url);
+ });
+}
+
+// Main
+async function main() {
+ // Skip conditions
+ if (process.env.MACHINAOS_SKIP_BINARY_DOWNLOAD === '1') {
+ console.log('Skipping binary download (MACHINAOS_SKIP_BINARY_DOWNLOAD=1)');
+ return;
+ }
+
+ if (process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') {
+ console.log('Skipping binary download (CI environment)');
+ return;
+ }
+
+ // Check if Go is installed - prefer source build
+ if (hasGo()) {
+ if (process.env.MACHINAOS_FORCE_BINARY_DOWNLOAD !== '1') {
+ console.log('Go is installed - will build from source');
+ return;
+ }
+ console.log('Go is installed but MACHINAOS_FORCE_BINARY_DOWNLOAD=1, downloading anyway');
+ }
+
+ const platformInfo = getPlatformInfo();
+ if (!platformInfo) {
+ console.log(`Unsupported platform: ${process.platform}/${process.arch}`);
+ return;
+ }
+
+ const { os, goarch, ext } = platformInfo;
+ const binaryName = `whatsapp-rpc-server-${os}-${goarch}${ext}`;
+ const downloadUrl = `${BASE_URL}/${binaryName}`;
+ const destPath = resolve(WHATSAPP_BIN_DIR, `whatsapp-rpc-server${ext}`);
+
+ console.log(`\nDownloading pre-built WhatsApp RPC binary...`);
+ console.log(` Version: v${VERSION}`);
+ console.log(` Platform: ${os}/${goarch}`);
+
+ // Create bin directory
+ if (!existsSync(WHATSAPP_BIN_DIR)) {
+ mkdirSync(WHATSAPP_BIN_DIR, { recursive: true });
+ }
+
+ // Check if binary already exists
+ if (existsSync(destPath)) {
+ console.log(` Binary already exists: ${destPath}`);
+ return;
+ }
+
+ // Download binary
+ try {
+ await downloadFile(downloadUrl, destPath);
+ } catch (error) {
+ console.error(`\nFailed to download binary: ${error.message}`);
+ console.log('Will attempt to build from source instead.');
+ return;
+ }
+
+ // Set executable permission (Unix only)
+ if (process.platform !== 'win32') {
+ chmodSync(destPath, 0o755);
+ }
+
+ console.log(`Binary downloaded: ${destPath}`);
+}
+
+main().catch((err) => {
+ // Don't fail the install - just log and continue
+ console.error('Binary download error:', err.message);
+});
diff --git a/scripts/postinstall.js b/scripts/postinstall.js
new file mode 100644
index 00000000..761bfa6e
--- /dev/null
+++ b/scripts/postinstall.js
@@ -0,0 +1,100 @@
+#!/usr/bin/env node
+/**
+ * Postinstall script for MachinaOS.
+ * Outputs to stderr so npm shows the progress (npm suppresses stdout during postinstall).
+ *
+ * Scenarios:
+ * 1. npm install -g machinaos → Run full install with output
+ * 2. npm install (local) → Run full install with output
+ * 3. GitHub Actions CI → Skip (workflow handles build separately)
+ *
+ * Runs:
+ * 1. download-binaries.js (optional binary download)
+ * 2. build.js (full build)
+ */
+import { spawn } from 'child_process';
+import { resolve, dirname } from 'path';
+import { fileURLToPath } from 'url';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const ROOT = resolve(__dirname, '..');
+
+// Output to stderr so npm shows it during install
+const print = (msg) => process.stderr.write(msg + '\n');
+
+// Environment detection
+const isCI = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
+
+// Skip in CI - GitHub Actions workflow handles build separately
+if (isCI) {
+ print('CI environment detected, skipping postinstall.');
+ process.exit(0);
+}
+
+print('');
+print('========================================');
+print(' MachinaOS - Installing...');
+print('========================================');
+print('');
+
+// Run a script and pipe output to stderr
+function runScript(scriptPath) {
+ return new Promise((resolve, reject) => {
+ const child = spawn(process.execPath, [scriptPath], {
+ cwd: ROOT,
+ stdio: ['inherit', process.stderr, 'inherit'],
+ env: { ...process.env, FORCE_COLOR: '1' }
+ });
+
+ child.on('error', reject);
+ child.on('close', (code) => {
+ if (code === 0) {
+ resolve();
+ } else {
+ reject(new Error(`Script exited with code ${code}`));
+ }
+ });
+ });
+}
+
+async function main() {
+ try {
+ // Step 1: Try to download pre-built binaries (optional, non-fatal)
+ print('[1/2] Checking for pre-built binaries...');
+ try {
+ await runScript(resolve(__dirname, 'download-binaries.js'));
+ } catch (e) {
+ print(' Binary download skipped or failed, will build from source.');
+ }
+
+ // Step 2: Run the full build
+ print('');
+ print('[2/2] Building MachinaOS...');
+ print('');
+ await runScript(resolve(__dirname, 'build.js'));
+
+ print('');
+ print('========================================');
+ print(' MachinaOS installed successfully!');
+ print('========================================');
+ print('');
+ print('Run: machinaos start');
+ print('Open: http://localhost:3000');
+ print('');
+
+ } catch (err) {
+ print('');
+ print('========================================');
+ print(' Installation failed!');
+ print('========================================');
+ print('');
+ print(`Error: ${err.message}`);
+ print('');
+ print('Try running manually:');
+ print(' machinaos build');
+ print('');
+ process.exit(1);
+ }
+}
+
+main();
diff --git a/server/whatsapp-rpc/scripts/cli.js b/server/whatsapp-rpc/scripts/cli.js
index 5be2dea6..8ffb0e6c 100644
--- a/server/whatsapp-rpc/scripts/cli.js
+++ b/server/whatsapp-rpc/scripts/cli.js
@@ -97,13 +97,22 @@ async function status() {
}
async function build() {
+ const bin = join(BIN_DIR, BIN);
+
+ // Skip if binary already exists (e.g., downloaded from GitHub Releases)
+ if (existsSync(bin)) {
+ log(`Binary already exists: ${BIN} (${(statSync(bin).size / 1024 / 1024).toFixed(1)}MB)`, 'green');
+ return;
+ }
+
+ // Build from source requires Go
if (!hasGo()) {
- log('Go is not installed. Install from: https://go.dev/dl/', 'red');
+ log('Go is not installed and no pre-built binary found.', 'red');
+ log('Install Go from: https://go.dev/dl/', 'yellow');
process.exit(1);
}
- const bin = join(BIN_DIR, BIN);
+
if (!existsSync(BIN_DIR)) { await execa('mkdir', ['-p', BIN_DIR]); }
- if (existsSync(bin)) unlinkSync(bin);
await execa('go', ['build', '-o', bin, './src/go/cmd/server'], { cwd: ROOT, stdio: 'inherit' });
log(`Built: ${BIN} (${(statSync(bin).size / 1024 / 1024).toFixed(1)}MB)`, 'green');
}