Files
mcpctl/scripts/build-deb.sh
Michal Rydlikowski e4bff0ef89
Some checks are pending
CI/CD / lint (push) Successful in 50s
CI/CD / test (push) Successful in 1m4s
CI/CD / typecheck (push) Successful in 3m0s
CI/CD / build (amd64) (push) Successful in 2m22s
CI/CD / build (arm64) (push) Successful in 1m45s
CI/CD / publish-rpm (amd64) (push) Successful in 46s
CI/CD / publish-rpm (arm64) (push) Successful in 48s
CI/CD / publish-deb (amd64) (push) Successful in 58s
CI/CD / publish-deb (arm64) (push) Successful in 58s
CI/CD / smoke (push) Has started running
fix: correct arch naming and build order for ARM64 packages
- nfpm.yaml: use ${NFPM_ARCH} (Go's ExpandEnv doesn't support :-default)
- arch-helper.sh: export RPM_ARCH (x86_64/aarch64) alongside NFPM_ARCH
- build-rpm/deb.sh: build TypeScript before running tests (tests need
  built @mcpctl/shared), generate Prisma client on fresh checkout
- Fix RPM filename matching to use aarch64 not arm64

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

81 lines
2.7 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
# Check if binaries already exist (build-rpm.sh may have been run first)
if [ ! -f "dist/mcpctl${ARCH_SUFFIX}" ] || [ ! -f "dist/mcpctl-local${ARCH_SUFFIX}" ]; then
echo "==> Binaries not found, building from scratch..."
echo ""
# Generate Prisma client if missing (fresh checkout)
if [ ! -d src/db/node_modules/.prisma ]; then
echo "==> Generating Prisma client..."
pnpm --filter @mcpctl/db exec prisma generate
fi
echo "==> Building TypeScript..."
pnpm build
echo "==> Running unit tests..."
pnpm test:run
echo ""
echo "==> Generating shell completions..."
pnpm completions:generate
echo "==> Bundling standalone binaries (target: ${NFPM_ARCH})..."
mkdir -p dist
# 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}"
else
echo "==> Using existing binaries in dist/"
fi
# 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 DEB (arch: ${NFPM_ARCH})..."
# Only remove DEBs for the target arch (preserve cross-compiled packages)
ls dist/mcpctl*_${NFPM_ARCH}.deb 2>/dev/null | xargs -r rm -f
export NFPM_ARCH
nfpm pkg --packager deb --target dist/
DEB_FILE=$(ls dist/mcpctl*.deb 2>/dev/null | grep -E "[._]${NFPM_ARCH}[._]" | head -1)
echo "==> Built: $DEB_FILE"
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
# dpkg-deb may not be available on RPM-based systems (Fedora)
if command -v dpkg-deb &>/dev/null; then
dpkg-deb --info "$DEB_FILE" 2>/dev/null || true
fi