# Makefile for Discord Quote Bot .PHONY: help test test-unit test-integration test-performance test-coverage clean install lint format type-check security # Default target .DEFAULT_GOAL := help # Variables PYTHON := python3 UV := uv PIP := $(UV) pip PYTEST := $(UV) run pytest BLACK := $(UV) run black ISORT := $(UV) run isort MYPY := $(UV) run mypy PYRIGHT := $(UV) run pyright COVERAGE := $(UV) run coverage help: ## Show this help message @echo "Discord Quote Bot - Development Commands" @echo "========================================" @echo "" @echo "Usage: make [target]" @echo "" @echo "Available targets:" @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' install: ## Install all dependencies $(UV) sync --all-extras test: ## Run all tests ./run_tests.sh all test-unit: ## Run unit tests only $(PYTEST) -m unit -v test-integration: ## Run integration tests only $(PYTEST) -m integration -v test-performance: ## Run performance tests only $(PYTEST) -m performance -v test-load: ## Run load tests only $(PYTEST) -m load -v test-fast: ## Run fast tests (exclude slow tests) $(PYTEST) -m "not slow" -v test-coverage: ## Run tests with coverage report $(PYTEST) --cov=. --cov-report=html --cov-report=term-missing @echo "Coverage report available at htmlcov/index.html" test-watch: ## Run tests in watch mode ptw -- -v test-parallel: ## Run tests in parallel $(PYTEST) -n auto -v lint: ## Run linting checks $(BLACK) --check . $(ISORT) --check-only . ruff check . format: ## Format code $(BLACK) . $(ISORT) . ruff check --fix . type-check: ## Run type checking $(MYPY) . --ignore-missing-imports $(PYRIGHT) security: ## Run security checks bandit -r . -x tests/ safety check clean: ## Clean generated files and caches find . -type f -name '*.pyc' -delete find . -type d -name '__pycache__' -delete find . -type d -name '.pytest_cache' -delete find . -type d -name '.mypy_cache' -delete find . -type d -name 'htmlcov' -exec rm -rf {} + find . -type f -name '.coverage' -delete find . -type f -name 'coverage.xml' -delete rm -rf build/ dist/ *.egg-info/ docker-build: ## Build Docker image docker build -t discord-quote-bot:latest . docker-run: ## Run bot in Docker docker run --rm -it \ --env-file .env \ --name discord-quote-bot \ discord-quote-bot:latest docker-test: ## Run tests in Docker docker run --rm \ --env-file .env.test \ discord-quote-bot:latest \ pytest migrate: ## Run database migrations alembic upgrade head migrate-create: ## Create new migration @read -p "Enter migration message: " msg; \ alembic revision --autogenerate -m "$$msg" migrate-rollback: ## Rollback last migration alembic downgrade -1 db-reset: ## Reset database (CAUTION: Destroys all data) @echo "WARNING: This will destroy all data in the database!" @read -p "Are you sure? (y/N): " confirm; \ if [ "$$confirm" = "y" ]; then \ alembic downgrade base; \ alembic upgrade head; \ echo "Database reset complete"; \ else \ echo "Database reset cancelled"; \ fi run: ## Run the bot locally $(UV) run python main.py run-dev: ## Run the bot in development mode with auto-reload $(UV) run watchmedo auto-restart \ --directory=. \ --pattern="*.py" \ --recursive \ -- python main.py logs: ## Show bot logs tail -f logs/bot.log logs-error: ## Show error logs only grep ERROR logs/bot.log | tail -50 health: ## Check bot health @echo "Checking bot health..." @curl -s http://localhost:8080/health | jq '.' || echo "Health endpoint not available" metrics: ## Show bot metrics @echo "Bot metrics:" @curl -s http://localhost:8080/metrics | head -20 || echo "Metrics endpoint not available" pre-commit: ## Run pre-commit checks @echo "Running pre-commit checks..." @make format @make lint @make type-check @make test-fast @echo "Pre-commit checks passed!" ci: ## Run full CI pipeline locally @echo "Running full CI pipeline..." @make clean @make install @make lint @make type-check @make security @make test-coverage @echo "CI pipeline complete!" docs: ## Generate documentation sphinx-build -b html docs/ docs/_build/html @echo "Documentation available at docs/_build/html/index.html" profile: ## Profile bot performance $(UV) run python -m cProfile -o profile.stats main.py $(UV) run python -m pstats profile.stats benchmark: ## Run performance benchmarks $(PYTEST) tests/performance/test_load_scenarios.py::TestLoadScenarios -v --benchmark-only check-deps: ## Check for outdated dependencies $(UV) pip list --outdated update-deps: ## Update all dependencies $(UV) pip install --upgrade -r requirements.txt .PHONY: venv venv: ## Create virtual environment $(UV) venv @echo "Virtual environment created. Activate with: source .venv/bin/activate"