From be9ad48a1c924053176ea6f4e63a9c3d3e5eef74 Mon Sep 17 00:00:00 2001 From: homelab-mcp Date: Wed, 22 Jul 2026 12:51:19 +0000 Subject: [PATCH] feat: add init.sh quality gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adapted from python-project-template-internal/init.sh but trimmed to what applies to an MCP server: no Docker, no CI-to-NAS, no deploy step (see './init.sh help' for rationale). Single dev dependency group instead of separate lint/type/tests groups, since this project doesn't need that split. Verifies: uv → Python → uv sync → ruff check → ruff format --check → mypy → pytest. Exit 0 = ready; exit 1 = stop and fix. --- init.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 init.sh diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..323b0dd --- /dev/null +++ b/init.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# init.sh — environment health check for homelab-mcp-gitea. +# +# Adapted from python-project-template-internal's init.sh but trimmed to +# what makes sense for an MCP server: no Docker, no CI-to-NAS, no deploy. +# Just the quality gate: uv sync + ruff lint + ruff format + mypy + pytest. +# +# Usage: +# ./init.sh # run the health check +# ./init.sh help # show this help +# +# Exit 0 = everything OK. Exit 1 = stop and fix before touching code. + +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +ok() { echo -e "${GREEN}[OK]${NC} $1"; } +fail() { echo -e "${RED}[FAIL]${NC} $1"; exit 1; } +warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } + +SUBCMD="${1:-check}" +shift || true + +case "$SUBCMD" in + check|"") + echo "=== init.sh — environment check ===" + + # 1. uv + if ! command -v uv &>/dev/null; then + fail "uv not found. Install: curl -LsSf https://astral.sh/uv/install.sh | sh" + fi + ok "uv found: $(uv --version)" + + # 2. Python version + PYTHON_VERSION=$(uv python find 2>/dev/null || echo "none") + if [[ "$PYTHON_VERSION" == "none" ]]; then + fail "No compatible Python found. Install: uv python install 3.12" + fi + ok "Python found: $PYTHON_VERSION" + + # 3. Sync dependencies + echo "Syncing dependencies..." + uv sync --all-groups --quiet || fail "uv sync failed" + ok "dependencies synced" + + # 4. Ruff lint + uv run ruff check src tests --quiet || fail "ruff check failed — run: uv run ruff check src tests" + ok "ruff check passed" + + # 5. Ruff format + uv run ruff format --check src tests --quiet || fail "ruff format check failed — run: uv run ruff format src tests" + ok "ruff format passed" + + # 6. Mypy + uv run mypy src --no-error-summary > /dev/null || fail "mypy failed — run: uv run mypy src" + ok "mypy passed" + + # 7. Tests + uv run pytest --tb=short -q || fail "tests failed — run: uv run pytest" + ok "tests passed" + + echo "" + echo -e "${GREEN}=== Environment ready ===${NC}" + ;; + + help|--help|-h) + cat <