-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
172 lines (139 loc) · 4.81 KB
/
makefile
File metadata and controls
172 lines (139 loc) · 4.81 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
BINARY_NAME=go-taskflow
DOCKER_COMPOSE=docker-compose
GO=go
GOFLAGS=-v
PROTO_DIR=proto
OUT_DIR=bin
# Colors for output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[1;33m
NC=\033[0m # No Color
.PHONY: help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
.PHONY: build
build: ## Build all binaries
@echo "$(GREEN)Building binaries...$(NC)"
@mkdir -p $(OUT_DIR)
@$(GO) build $(GOFLAGS) -o $(OUT_DIR)/api ./cmd/api
@$(GO) build $(GOFLAGS) -o $(OUT_DIR)/worker ./cmd/worker
@$(GO) build $(GOFLAGS) -o $(OUT_DIR)/migrator ./cmd/migrator
@echo "$(GREEN)Build complete!$(NC)"
.PHONY: run-api
run-api: ## Run API server
@echo "$(GREEN)Starting API server...$(NC)"
@$(GO) run ./cmd/api
.PHONY: run-worker
run-worker: ## Run worker
@echo "$(GREEN)Starting worker...$(NC)"
@$(GO) run ./cmd/worker
.PHONY: test
test: ## Run unit tests
@echo "$(GREEN)Running tests...$(NC)"
@$(GO) test -v -race -short ./...
.PHONY: test-integration
test-integration: ## Run integration tests
@echo "$(GREEN)Running integration tests...$(NC)"
@$(GO) test -v -race -tags=integration ./tests/integration/...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "$(GREEN)Running tests with coverage...$(NC)"
@$(GO) test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
@$(GO) tool cover -html=coverage.txt -o coverage.html
@echo "$(GREEN)Coverage report generated: coverage.html$(NC)"
.PHONY: lint
lint: ## Run linter
@echo "$(GREEN)Running linter...$(NC)"
@golangci-lint run ./...
.PHONY: fmt
fmt: ## Format code
@echo "$(GREEN)Formatting code...$(NC)"
@$(GO) fmt ./...
.PHONY: vet
vet: ## Run go vet
@echo "$(GREEN)Running go vet...$(NC)"
@$(GO) vet ./...
.PHONY: clean
clean: ## Clean build artifacts
@echo "$(YELLOW)Cleaning...$(NC)"
@rm -rf $(OUT_DIR)
@rm -f coverage.txt coverage.html
@echo "$(GREEN)Clean complete!$(NC)"
.PHONY: docker-up
docker-up: ## Start docker containers
@echo "$(GREEN)Starting Docker containers...$(NC)"
@$(DOCKER_COMPOSE) up -d
.PHONY: docker-down
docker-down: ## Stop docker containers
@echo "$(YELLOW)Stopping Docker containers...$(NC)"
@$(DOCKER_COMPOSE) down
.PHONY: docker-logs
docker-logs: ## Show docker logs
@$(DOCKER_COMPOSE) logs -f
.PHONY: proto
proto: ## Generate protobuf code
@echo "$(GREEN)Generating protobuf code...$(NC)"
@protoc --go_out=. --go-grpc_out=. $(PROTO_DIR)/*.proto
.PHONY: migrate-up
migrate-up: ## Run database migrations up
@echo "$(GREEN)Running migrations up...$(NC)"
@go run ./cmd/migrator -command=up
.PHONY: migrate-down
migrate-down: ## Run database migrations down
@echo "$(YELLOW)Running migrations down...$(NC)"
@go run ./cmd/migrator -command=down
.PHONY: migrate-drop
migrate-drop: ## Drop all migrations (DANGER!)
@echo "$(RED)Dropping all migrations...$(NC)"
@go run ./cmd/migrator -command=drop
.PHONY: migrate-version
migrate-version: ## Show current migration version
@echo "$(GREEN)Current migration version:$(NC)"
@go run ./cmd/migrator -command=version
.PHONY: migrate-force
migrate-force: ## Force migration to specific version (usage: make migrate-force version=1)
@echo "$(YELLOW)Forcing migration to version $(version)...$(NC)"
@go run ./cmd/migrator -command=force -force=$(version)
.PHONY: migrate-create
migrate-create: ## Create a new migration (usage: make migrate-create name=migration_name)
@echo "$(GREEN)Creating migration: $(name)$(NC)"
@migrate create -ext sql -dir migrations -seq $(name)
.PHONY: install-tools
install-tools: ## Install development tools
@echo "$(GREEN)Installing development tools...$(NC)"
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
@echo "$(GREEN)Tools installed!$(NC)"
.PHONY: check
check: fmt vet lint test ## Run all checks
@echo "$(GREEN)All checks passed!$(NC)"
.PHONY: infra-up
infra-up: ## Start infrastructure (PostgreSQL, Kafka, etc.)
@./scripts/infra.sh up
.PHONY: infra-down
infra-down: ## Stop infrastructure
@./scripts/infra.sh down
.PHONY: infra-restart
infra-restart: ## Restart infrastructure
@./scripts/infra.sh restart
.PHONY: infra-logs
infra-logs: ## Show infrastructure logs
@./scripts/infra.sh logs
.PHONY: infra-status
infra-status: ## Show infrastructure status
@./scripts/infra.sh status
.PHONY: infra-clean
infra-clean: ## Clean infrastructure (WARNING: deletes data)
@./scripts/infra.sh clean
.PHONY: kafka-topics
kafka-topics: ## Create Kafka topics
@./scripts/create-topics.sh
.PHONY: all
all: clean build test ## Clean, build and test
.DEFAULT_GOAL := help