-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
168 lines (145 loc) · 6.52 KB
/
Makefile
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
AUTH_DIR := ./components/auth
INFRA_DIR := ./components/infra
LEDGER_DIR := ./components/ledger
TRANSACTION_DIR := ./components/transaction
MDZ_DIR := ./components/mdz
.PHONY: help test cover lint format check-logs check-tests \
setup-git-hooks check-hooks goreleaser tidy sec set-env up auth infra ledger \
transaction all-services
BLUE := \033[36m
NC := \033[0m
BOLD := \033[1m
RED := \033[31m
MAGENTA := \033[35m
help:
@echo "$(BOLD)Midaz Project Management Commands$(NC)"
@echo ""
@echo "$(BOLD)Core Commands:$(NC)"
@echo " make test - Run tests on all projects"
@echo " make cover - Run test coverage"
@echo ""
@echo "$(BOLD)Code Quality Commands:$(NC)"
@echo " make lint - Run golangci-lint and performance checks"
@echo " make format - Format Go code using gofmt"
@echo " make check-logs - Verify error logging in usecases"
@echo " make check-tests - Verify test coverage for components"
@echo " make sec - Run security checks using gosec"
@echo ""
@echo "$(BOLD)Git Hook Commands:$(NC)"
@echo " make setup-git-hooks - Install and configure git hooks"
@echo " make check-hooks - Verify git hooks installation status"
@echo ""
@echo "$(BOLD)Setup Commands:$(NC)"
@echo " make set-env - Copy .env.example to .env for all components"
@echo "Usage:"
@echo " ## Root Commands"
@echo " make build Build all project services."
@echo " make test Run tests on all projects."
@echo " make clean Clean the directory tree of produced artifacts."
@echo " make lint Run static code analysis (lint)."
@echo " make format Run code formatter."
@echo " make checkEnvs Check if github hooks are installed and secret env on files are not exposed."
@echo " make auth Run a command inside the auth app in the components directory to see available commands."
@echo " make infra Run a command inside the infra app in the components directory to see available commands."
@echo " make ledger Run a command inside the ledger app in the components directory to see available commands."
@echo " make transaction Run a command inside the transaction app in the components directory to see available commands."
@echo " make set-env Run a command to copy all .env.example to .env into respective folders."
@echo " make all-services Run a command to all services passing any individual container command."
@echo " make generate-docs-all Run a command to inside the ledger and transaction app to generate swagger docs."
@echo ""
@echo "$(BOLD)Service Commands:$(NC)"
@echo " make up - Start all services with Docker Compose"
@echo " make auth COMMAND=<cmd> - Run command in auth service"
@echo " make infra COMMAND=<cmd> - Run command in infra service"
@echo " make ledger COMMAND=<cmd> - Run command in ledger service"
@echo " make transaction COMMAND=<cmd> - Run command in transaction service"
@echo " make all-services COMMAND=<cmd> - Run command across all services"
@echo ""
@echo "$(BOLD)Development Commands:$(NC)"
@echo " make tidy - Run go mod tidy"
@echo " make goreleaser - Create a release snapshot"
test:
@echo "$(BLUE)Running tests...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
go test -v ./... ./...
cover:
@echo "$(BLUE)Generating test coverage...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
go test -cover ./...
lint:
@echo "$(BLUE)Running linter and performance checks...$(NC)"
./make.sh "lint"
format:
@echo "$(BLUE)Formatting Go code...$(NC)"
./make.sh "format"
check-logs:
@echo "$(BLUE)Checking error logging in usecases...$(NC)"
./make.sh "checkLogs"
check-tests:
@echo "$(BLUE)Verifying test coverage...$(NC)"
./make.sh "checkTests"
sec:
@echo "$(BLUE)Running security checks...$(NC)"
@if ! command -v gosec >/dev/null 2>&1; then \
echo "$(RED)Error: gosec is not installed$(NC)"; \
echo "$(MAGENTA)To install: go install github.com/securego/gosec/v2/cmd/gosec@latest$(NC)"; \
exit 1; \
fi
gosec ./...
setup-git-hooks:
@echo "$(BLUE)Setting up git hooks...$(NC)"
./make.sh "setupGitHooks"
check-hooks:
@echo "$(BLUE)Checking git hooks status...$(NC)"
./make.sh "checkHooks"
set-env:
@echo "$(BLUE)Setting up environment files...$(NC)"
cp -r $(AUTH_DIR)/.env.example $(AUTH_DIR)/.env
cp -r $(INFRA_DIR)/.env.example $(INFRA_DIR)/.env
cp -r $(LEDGER_DIR)/.env.example $(LEDGER_DIR)/.env
cp -r $(TRANSACTION_DIR)/.env.example $(TRANSACTION_DIR)/.env
cp -r $(MDZ_DIR)/.env.example $(MDZ_DIR)/.env
@echo "$(BLUE)Environment files created successfully$(NC)"
up:
@echo "$(BLUE)Starting all services...$(NC)"
docker-compose -f $(AUTH_DIR)/docker-compose.yml up --build -d && \
docker-compose -f $(INFRA_DIR)/docker-compose.yml up --build -d && \
docker-compose -f $(LEDGER_DIR)/docker-compose.yml up --build -d && \
docker-compose -f $(TRANSACTION_DIR)/docker-compose.yml up --build -d
@echo "$(BLUE)All services started successfully$(NC)"
auth:
@echo "$(BLUE)Executing command in auth service...$(NC)"
$(MAKE) -C $(AUTH_DIR) $(COMMAND)
infra:
@echo "$(BLUE)Executing command in infra service...$(NC)"
$(MAKE) -C $(INFRA_DIR) $(COMMAND)
ledger:
@echo "$(BLUE)Executing command in ledger service...$(NC)"
$(MAKE) -C $(LEDGER_DIR) $(COMMAND)
transaction:
@echo "$(BLUE)Executing command in transaction service...$(NC)"
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)
all-services:
@echo "$(BLUE)Executing command across all services...$(NC)"
$(MAKE) -C $(AUTH_DIR) $(COMMAND) && \
$(MAKE) -C $(INFRA_DIR) $(COMMAND) && \
$(MAKE) -C $(LEDGER_DIR) $(COMMAND) && \
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)
test_integration_cli:
go test -v -tags=integration ./components/mdz/test/integration/...
goreleaser:
@echo "$(BLUE)Creating release snapshot...$(NC)"
goreleaser release --snapshot --skip-publish --rm-dist
tidy:
@echo "$(BLUE)Running go mod tidy...$(NC)"
go mod tidy
generate-docs-all:
@echo "$(BLUE)Executing command to generate swagger...$(NC)"
$(MAKE) -C $(LEDGER_DIR) generate-docs && \
$(MAKE) -C $(TRANSACTION_DIR) generate-docs