2026-03-09 22:43:40 +00:00
|
|
|
#!/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"
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
# 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
|
|
|
|
|
|
build: refuse to package from a branch that is behind main
Everyone branches off main and builds from their own branch. A branch that is
behind main still builds and installs perfectly — it just packages a binary
missing whatever landed on main meanwhile, and `rpm -U --force` overwrites the
good one with it. Nothing reports an error; the release succeeds and the feature
simply vanishes from the installed CLI.
That is what happened today: a build from a stale checkout replaced
/usr/bin/mcpctl with one that has no `statusline` command at all, months after
the status line landed on main (`mcpctl statusline` -> "unknown command").
`check-main-sync.sh` fetches main, compares, and fails before any work happens,
listing the commits the branch is missing and the merge that fixes it. Sourced
by build-rpm.sh and build-deb.sh — both are run standalone, so neither can rely
on the other having checked.
A hard failure rather than a warning: a warning scrolls past in a build log, and
the whole point is to stop before the artifact exists.
MCPCTL_ALLOW_BEHIND_MAIN=1 is the escape hatch for a deliberate old-tree build;
MCPCTL_BASE_BRANCH retargets the comparison. Offline it degrades to the last
fetched origin/main, then a local main, saying which it used; outside a git
checkout it skips.
Verified: passes on this branch (up to date with main); against a synthetic ref
one commit ahead, build-rpm.sh aborts with exit 1 before ensure_build_deps and
before any compilation; the escape hatch bypasses it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019wUmrfkVQR6CKcYKxENq7k
2026-08-10 16:38:19 +01:00
|
|
|
# Same guard as build-rpm.sh: this script is also run on its own, so it cannot
|
|
|
|
|
# rely on that one having checked.
|
|
|
|
|
source "$SCRIPT_DIR/check-main-sync.sh"
|
|
|
|
|
check_main_sync
|
|
|
|
|
|
2026-03-13 23:11:35 +00:00
|
|
|
# Check and install missing build dependencies
|
|
|
|
|
source "$SCRIPT_DIR/ensure-deps.sh"
|
|
|
|
|
ensure_build_deps
|
|
|
|
|
|
2026-03-09 22:43:40 +00:00
|
|
|
# Check if binaries already exist (build-rpm.sh may have been run first)
|
2026-03-13 23:01:51 +00:00
|
|
|
if [ ! -f "dist/mcpctl${ARCH_SUFFIX}" ] || [ ! -f "dist/mcpctl-local${ARCH_SUFFIX}" ]; then
|
2026-03-09 22:43:40 +00:00
|
|
|
echo "==> Binaries not found, building from scratch..."
|
|
|
|
|
echo ""
|
|
|
|
|
|
2026-03-13 23:16:48 +00:00
|
|
|
# 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
|
2026-03-09 22:43:40 +00:00
|
|
|
|
|
|
|
|
echo "==> Building TypeScript..."
|
|
|
|
|
pnpm build
|
|
|
|
|
|
2026-03-13 23:16:48 +00:00
|
|
|
echo "==> Running unit tests..."
|
|
|
|
|
pnpm test:run
|
|
|
|
|
echo ""
|
|
|
|
|
|
2026-03-09 22:43:40 +00:00
|
|
|
echo "==> Generating shell completions..."
|
|
|
|
|
pnpm completions:generate
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
echo "==> Bundling standalone binaries (target: ${NFPM_ARCH})..."
|
2026-03-09 22:43:40 +00:00
|
|
|
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
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
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}"
|
2026-03-09 22:43:40 +00:00
|
|
|
else
|
|
|
|
|
echo "==> Using existing binaries in dist/"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
# 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
|
2026-03-09 22:43:40 +00:00
|
|
|
nfpm pkg --packager deb --target dist/
|
|
|
|
|
|
2026-03-13 23:01:51 +00:00
|
|
|
DEB_FILE=$(ls dist/mcpctl*.deb 2>/dev/null | grep -E "[._]${NFPM_ARCH}[._]" | head -1)
|
2026-03-09 22:43:40 +00:00
|
|
|
echo "==> Built: $DEB_FILE"
|
|
|
|
|
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
|
2026-03-13 23:01:51 +00:00
|
|
|
# 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
|