chore: build.sh con version desde app.md + pre-commit anti-stale

build.sh inyecta la version de app.md por -ldflags (-X main.version), haciendo de
app.md la unica fuente de verdad — el binario ya no puede quedar por detras
(drift 0.7.0 vs 0.8.0 del 16/06/2026). main.go pasa la version de const a var
para permitir el override por ldflags.

scripts/pre-commit recompila en cada commit para que el binario que sirve el
.mcp.json nunca quede stale respecto a los .go commiteados (la causa raiz del
mismo bug). scripts/install-hooks.sh lo instala via symlink.
This commit is contained in:
Egutierrez
2026-06-16 20:27:45 +02:00
parent 82993179dc
commit 33358bca6c
4 changed files with 40 additions and 1 deletions
Executable
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Compila browser_mcp inyectando la versión declarada en app.md como única fuente
# de verdad. Evita el drift entre la constante del binario y app.md (bug 16/06/2026:
# serverInfo reportaba 0.7.0 mientras app.md ya iba por 0.8.0).
#
# Uso: ./build.sh
set -euo pipefail
cd "$(dirname "$0")"
version="$(grep -m1 '^version:' app.md | awk '{print $2}')"
if [ -z "${version}" ]; then
echo "build.sh: no pude leer 'version:' de app.md" >&2
exit 1
fi
CGO_ENABLED=0 go build -ldflags "-X main.version=${version}" -o browser_mcp .
echo "built browser_mcp version=${version}"
+5 -1
View File
@@ -15,7 +15,11 @@ import (
"fn-registry/functions/browser"
)
const version = "0.8.0"
// version is the server version reported in serverInfo. The literal here is a
// fallback for `go build` with no flags; build.sh overrides it via
// -ldflags "-X main.version=<app.md version>" so app.md stays the single source
// of truth and the binary can never drift behind it (see build.sh).
var version = "0.8.0"
type config struct {
httpAddr string
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Instala los git hooks versionados de este repo en .git/hooks.
set -euo pipefail
cd "$(dirname "$0")/.."
ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
echo "instalado .git/hooks/pre-commit -> scripts/pre-commit"
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Anti-stale binary guard. El .mcp.json ejecuta el binario ./browser_mcp; si se
# commitea un cambio en los .go sin recompilar, la sesión sirve código viejo
# (bug 16/06/2026). Este hook recompila en cada commit. Instálalo con
# scripts/install-hooks.sh.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
if ! ./build.sh >/tmp/browser_mcp_build.log 2>&1; then
echo "pre-commit: build.sh falló — commit abortado. Log:" >&2
cat /tmp/browser_mcp_build.log >&2
exit 1
fi