Files
mcpctl/scripts/build-rpm.sh
Michal Rydlikowski c7c9f0923f
Some checks failed
CI/CD / lint (push) Successful in 47s
CI/CD / typecheck (push) Successful in 47s
CI/CD / test (push) Successful in 59s
CI/CD / smoke (push) Has started running
CI/CD / build (amd64) (push) Has started running
CI/CD / build (arm64) (push) Has been cancelled
CI/CD / publish-rpm (amd64) (push) Has been cancelled
CI/CD / publish-rpm (arm64) (push) Has been cancelled
CI/CD / publish-deb (amd64) (push) Has been cancelled
CI/CD / publish-deb (arm64) (push) Has been cancelled
feat: auto-install missing build dependencies (pnpm, bun, nfpm)
Build scripts now check for required tools before building and install
them automatically if missing. Handles both amd64 and arm64 host systems.

- pnpm: installed via corepack or npm
- bun: installed via official install script
- nfpm: downloaded from GitHub for the correct host architecture
- node_modules: runs pnpm install if missing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-13 23:11:35 +00:00

77 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_ROOT"
# Load .env if present
if [ -f .env ]; then
set -a; source .env; set +a
fi
# Ensure tools are on PATH
export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH"
# Architecture detection / cross-compilation support
# MCPCTL_TARGET_ARCH overrides native detection (e.g. "amd64" or "arm64")
source "$SCRIPT_DIR/arch-helper.sh"
resolve_arch "${MCPCTL_TARGET_ARCH:-}"
# Sets: NFPM_ARCH, BUN_TARGET, ARCH_SUFFIX
# Check and install missing build dependencies
source "$SCRIPT_DIR/ensure-deps.sh"
ensure_build_deps
echo "==> Running unit tests..."
pnpm test:run
echo ""
echo "==> Building TypeScript..."
pnpm build
echo "==> Generating shell completions..."
pnpm completions:generate
echo "==> Bundling standalone binaries (target: ${NFPM_ARCH})..."
mkdir -p dist
rm -f "dist/mcpctl${ARCH_SUFFIX}" "dist/mcpctl-local${ARCH_SUFFIX}"
# Only remove RPMs for the target arch (preserve cross-compiled packages)
ls dist/mcpctl-*.${NFPM_ARCH}.rpm 2>/dev/null | xargs -r rm -f
# Ink optionally imports react-devtools-core which isn't installed.
# Provide a no-op stub so bun can bundle it (it's only invoked when DEV=true).
if [ ! -e node_modules/react-devtools-core ]; then
ln -s ../src/cli/stubs/react-devtools-core node_modules/react-devtools-core
fi
bun build src/cli/src/index.ts --compile ${BUN_TARGET:+--target "$BUN_TARGET"} --outfile "dist/mcpctl${ARCH_SUFFIX}"
bun build src/mcplocal/src/main.ts --compile ${BUN_TARGET:+--target "$BUN_TARGET"} --outfile "dist/mcpctl-local${ARCH_SUFFIX}"
# If cross-compiling, copy arch-suffixed binaries to the names nfpm expects
if [ -n "$ARCH_SUFFIX" ]; then
cp "dist/mcpctl${ARCH_SUFFIX}" dist/mcpctl
cp "dist/mcpctl-local${ARCH_SUFFIX}" dist/mcpctl-local
fi
echo "==> Packaging RPM (arch: ${NFPM_ARCH})..."
export NFPM_ARCH
nfpm pkg --packager rpm --target dist/
RPM_FILE=$(ls dist/mcpctl-*.${NFPM_ARCH}.rpm 2>/dev/null | head -1)
echo "==> Built: $RPM_FILE"
echo " Size: $(du -h "$RPM_FILE" | cut -f1)"
if command -v rpm &>/dev/null; then
rpm -qpi "$RPM_FILE"
fi
echo ""
echo "==> Packaging DEB (arch: ${NFPM_ARCH})..."
# Only remove DEBs for the target arch
ls dist/mcpctl*_${NFPM_ARCH}.deb 2>/dev/null | xargs -r rm -f
nfpm pkg --packager deb --target dist/
DEB_FILE=$(ls dist/mcpctl*_${NFPM_ARCH}.deb 2>/dev/null | head -1)
echo "==> Built: $DEB_FILE"
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"