-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
307 lines (257 loc) · 9.06 KB
/
Copy pathMakefile
File metadata and controls
307 lines (257 loc) · 9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Makefile for QR Code Bot
#
# Usage:
# make test - Run all tests with test infrastructure
# make test-unit - Run only unit tests (fast, no infrastructure)
# make test-integration - Run only integration tests
# make test-cov - Run tests with coverage report
# make lint - Run linters
# make run - Run the bot locally
.PHONY: help test test-unit test-integration test-cov test-infra-up test-infra-down lint run clean docker-build docker-up docker-down format check-format check-imports security pre-commit install-hooks ci-check setup
# Default target
help:
@echo "QR Code Bot - Available commands:"
@echo ""
@echo "Setup:"
@echo " make setup - Install all dependencies (production + development)"
@echo ""
@echo "Testing:"
@echo " make test - Run all tests with test infrastructure"
@echo " make test-unit - Run only unit tests (no infrastructure required)"
@echo " make test-integration - Run only integration tests"
@echo " make test-cov - Run tests with coverage report"
@echo ""
@echo "Code Quality:"
@echo " make lint - Run linters"
@echo " make format - Auto-format code with black and isort"
@echo " make check-format - Check code formatting"
@echo " make check-imports - Check import sorting"
@echo " make security - Run security scan"
@echo " make pre-commit - Run all pre-commit checks"
@echo " make ci-check - Run all CI checks locally"
@echo ""
@echo "Git Hooks:"
@echo " make install-hooks - Install Git pre-commit hooks"
@echo ""
@echo "Infrastructure:"
@echo " make test-infra-up - Start test database and redis"
@echo " make test-infra-down - Stop test infrastructure"
@echo ""
@echo "Docker:"
@echo " make docker-build - Build docker image"
@echo " make docker-up - Start production containers"
@echo " make docker-down - Stop production containers"
# ==============================================================================
# Setup
# ==============================================================================
setup:
@echo "📦 Installing dependencies..."
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
@echo "✅ All dependencies installed"
# ==============================================================================
# Test Infrastructure
# ==============================================================================
test-infra-up:
@echo "🚀 Starting test infrastructure..."
docker-compose -f docker-compose.test.yml up -d
@echo "⏳ Waiting for services to be ready..."
@sleep 3
@echo "✅ Test infrastructure is ready"
test-infra-down:
@echo "🛑 Stopping test infrastructure..."
docker-compose -f docker-compose.test.yml down -v
@echo "✅ Test infrastructure stopped"
test-infra-status:
@docker-compose -f docker-compose.test.yml ps
# ==============================================================================
# Testing
# ==============================================================================
# Run all tests (starts infrastructure automatically)
test: test-infra-up
@echo "🧪 Running all tests..."
PYTHONPATH=. pytest tests/ -v --tb=short
@$(MAKE) test-infra-down
# Run only unit tests (fast, no infrastructure)
test-unit:
@echo "🧪 Running unit tests..."
PYTHONPATH=. pytest tests/unit/ -v -m "not integration"
# Run only integration tests
test-integration: test-infra-up
@echo "🧪 Running integration tests..."
PYTHONPATH=. pytest tests/integration/ -v -m "integration"
@$(MAKE) test-infra-down
# Run tests with coverage report
test-cov: test-infra-up
@echo "📊 Running tests with coverage..."
PYTHONPATH=. pytest tests/ \
--cov=bot \
--cov-report=term-missing \
--cov-report=html:htmlcov \
-v
@$(MAKE) test-infra-down
@echo "📊 Coverage report generated in htmlcov/index.html"
# Run tests without stopping infrastructure (for development)
test-dev:
@echo "🧪 Running tests (infrastructure assumed running)..."
PYTHONPATH=. pytest tests/ -v --tb=short
# Run a specific test file
test-file:
@echo "Usage: make test-file FILE=tests/integration/test_qr_generation_flow.py"
PYTHONPATH=. pytest $(FILE) -v --tb=short
# ==============================================================================
# Code Quality
# ==============================================================================
lint:
@echo "🔍 Running linters..."
python -m ruff check bot/ tests/ --fix
python -m ruff format bot/ tests/
lint-check:
@echo "🔍 Checking code style..."
python -m ruff check bot/ tests/
python -m ruff format bot/ tests/ --check
type-check:
@echo "🔍 Running type checker..."
python -m mypy bot/ --ignore-missing-imports
# ==============================================================================
# Development
# ==============================================================================
run:
@echo "🤖 Starting bot..."
python main.py
run-dev:
@echo "🤖 Starting bot with auto-reload..."
watchmedo auto-restart --pattern="*.py" --recursive python main.py
clean:
@echo "🧹 Cleaning generated files..."
rm -rf __pycache__ */__pycache__ */*/__pycache__
rm -rf .pytest_cache
rm -rf htmlcov
rm -rf .coverage
rm -rf *.egg-info
rm -rf build dist
@echo "✅ Clean complete"
# ==============================================================================
# Docker (Production)
# ==============================================================================
docker-build:
@echo "🐳 Building docker image..."
docker-compose build
docker-up:
@echo "🐳 Starting production containers..."
docker-compose up -d
@echo "✅ Production environment is running"
docker-down:
@echo "🐳 Stopping production containers..."
docker-compose down
@echo "✅ Production environment stopped"
docker-logs:
docker-compose logs -f
docker-restart:
docker-compose restart bot
# ==============================================================================
# Code Quality & CI/CD
# ==============================================================================
# Форматирование кода
format:
@echo "🎨 Formatting code..."
ruff format .
ruff check --fix --select I .
@echo "✅ Code formatted"
# Проверка форматирования
check-format:
@echo "🔍 Checking code formatting..."
ruff format --check .
@echo "✅ Code formatting OK"
# Проверка сортировки импортов
check-imports:
@echo "🔍 Checking import sorting..."
ruff check --select I .
@echo "✅ Import sorting OK"
# Линтинг
lint:
@echo "🔍 Running linters..."
ruff check .
@echo "✅ Linting passed"
# Сканирование безопасности
security:
@echo "🔒 Running security scan..."
bandit -r bot/ -ll
safety check
@echo "✅ Security scan completed"
# Pre-commit проверки
pre-commit:
@echo "🚀 Running pre-commit checks..."
@make check-format
@make check-imports
@make lint
@make test-unit
@make security
@echo "🎉 All pre-commit checks passed!"
# Установка Git hooks
install-hooks:
@echo "🔧 Installing Git hooks..."
python scripts/setup-hooks.py
@echo "✅ Git hooks installed"
# CI проверки (как в GitHub Actions)
ci-check:
@echo "🔄 Running full CI checks..."
@echo "1/6 Code Quality..."
@make check-format
@make check-imports
@make lint
@echo "2/6 Unit Tests..."
@make test-unit
@echo "3/6 Integration Tests..."
@make test
@echo "4/6 Coverage..."
@make test-cov
@echo "5/6 Security..."
@make security
@echo "6/6 Build Check..."
@make docker-build
@echo "🎉 All CI checks passed! Ready for merge!"
# ==============================================================================
# Development Scripts
# ==============================================================================
# Development toolkit
dev-help:
@echo "🛠️ Available development commands:"
@echo " make dev-setup - Setup complete development environment"
@echo " make dev-ci - Run local CI pipeline"
@echo " make dev-tools - Show dev.sh toolkit help"
@scripts/dev.sh help
dev-setup:
@echo "🛠️ Setting up development environment..."
@scripts/dev-setup.sh
dev-ci:
@echo "🚀 Running local CI pipeline..."
@scripts/local-ci.sh
dev-tools:
@scripts/dev.sh help
# Enhanced pre-push validation
pre-push:
@echo "🔒 Running pre-push validation..."
@scripts/pre-push.sh
# ==============================================================================
# Database
# ==============================================================================
db-migrate:
@echo "📦 Running database migrations..."
alembic upgrade head
db-rollback:
@echo "📦 Rolling back last migration..."
alembic downgrade -1
db-shell:
@echo "📦 Opening database shell..."
docker-compose exec postgres psql -U qr_bot_user -d qr_bot
# ==============================================================================
# Shortcuts
# ==============================================================================
# Alias for common commands
t: test
tu: test-unit
ti: test-integration
tc: test-cov
r: run