feat: add init.sh quality gate

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.
This commit is contained in:
homelab-mcp
2026-07-22 12:51:19 +00:00
parent 0212913831
commit be9ad48a1c
Executable
+91
View File
@@ -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 <<EOF
init.sh — environment health check for homelab-mcp-gitea
Usage:
./init.sh Run the health check (uv sync + ruff + mypy + pytest).
./init.sh help Show this help.
Exit 0 means everything is green. Exit 1 means fix and retry.
Adapted from python-project-template-internal/init.sh. The MCP server has
no Docker, no CI-to-NAS, no deploy step — those parts of the template were
deliberately dropped because they don't apply to a stdio MCP subprocess.
EOF
;;
*)
echo "Unknown subcommand: $SUBCMD"
echo "Run './init.sh help' for usage."
exit 1
;;
esac