-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
631 lines (569 loc) Β· 19.7 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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# =============================================================================
# π Documentation
# =============================================================================
# This Makefile is designed to support Go projects of any size, from small
# personal projects to large enterprise applications. It provides a comprehensive
# set of targets for development, testing, building, and deployment.
#
# Quick Start:
# 1. Copy this Makefile to your project
# 2. Create a .env file for local overrides (optional)
# 3. Run `make init` to initialize the project
# 4. Run `make help` to see available commands
#
# Configuration:
# The Makefile can be configured in several ways (in order of precedence):
# 1. Command line variables: make build GOOS=darwin
# 2. Environment variables: export GOOS=darwin
# 3. .env file in project root
# 4. Default values in this Makefile
#
# For large projects:
# - Create a config/ directory with environment-specific configs
# - Use config.mk files for project-specific settings
# - Enable build caching and parallel builds
# - Set up CI/CD pipeline configurations
#
# For small projects:
# - Use default configurations
# - Disable unused features in .env file
# - Focus on core development commands
# =============================================================================
# π Load Environment & Configs
# =============================================================================
# Load .env file if it exists
ifneq (,$(wildcard .env))
include .env
# Only export specific variables that need to be in the environment
export GOOS
export GOARCH
export CGO_ENABLED
export PROJECT_NAME
export ORGANIZATION
export DATABASE_URL
# Add other variables that actually need to be in the environment
endif
# Load project-specific config if it exists
ifneq (,$(wildcard config.mk))
include config.mk
endif
# =============================================================================
# π― Project Configuration
# =============================================================================
# Project Settings
PROJECT_NAME ?= myapp
ORGANIZATION ?= myorg
DESCRIPTION ?= "My Awesome Go Project"
MAINTAINER ?= "[email protected]"
# Feature Flags (can be disabled in .env)
ENABLE_DOCKER ?= true
ENABLE_PROTO ?= true
ENABLE_DOCS ?= true
ENABLE_SECURITY_SCAN ?= true
ENABLE_ADVANCED_TESTING ?= true
ENABLE_BUILD_CACHE ?= true
# Project Structure
PROJECT_TYPE ?= basic # basic, monorepo, microservices
MONOREPO_SERVICES ?= $(wildcard services/*)
BUILD_TARGETS ?= $(if $(filter monorepo,$(PROJECT_TYPE)),$(MONOREPO_SERVICES),$(PROJECT_NAME))
# Build Settings
BUILD_SYSTEM ?= local # local, ci
CI_SYSTEM ?= github # github, gitlab, jenkins
PARALLEL_JOBS ?= $(shell \
if command -v nproc >/dev/null 2>&1; then \
nproc; \
elif command -v getconf >/dev/null 2>&1; then \
getconf _NPROCESSORS_ONLN; \
elif command -v sysctl >/dev/null 2>&1; then \
sysctl -n hw.ncpu; \
else \
echo 1; \
fi)
ENABLE_PARALLEL := $(if $(filter local,$(BUILD_SYSTEM)),true,false)
# Version Control
VERSION_STRATEGY ?= git # git, semver, date
VERSION := $(shell \
if [ "$(VERSION_STRATEGY)" = "git" ] && git rev-parse --git-dir > /dev/null 2>&1; then \
git describe --tags --always --dirty 2>/dev/null || echo "dev"; \
elif [ "$(VERSION_STRATEGY)" = "semver" ]; then \
cat VERSION 2>/dev/null || echo "0.1.0"; \
else \
date -u '+%Y%m%d-%H%M%S'; \
fi)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
BUILD_BY ?= $(shell whoami)
# Go Configuration
GO ?= go
GOCMD = $(shell which go)
GOPATH ?= $(shell $(GO) env GOPATH)
GOBIN ?= $(GOPATH)/bin
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
CGO_ENABLED ?= 0
# Tools & Linters
GOLANGCI_LINT ?= $(GOBIN)/golangci-lint
GOFUMPT ?= $(GOBIN)/gofumpt
GODOC ?= $(GOBIN)/godoc
GOVULNCHECK ?= $(GOBIN)/govulncheck
MOCKGEN ?= $(GOBIN)/mockgen
AIR ?= $(GOBIN)/air
# Directories
ROOT_DIR ?= $(shell pwd)
BIN_DIR ?= $(ROOT_DIR)/bin
DIST_DIR ?= $(ROOT_DIR)/dist
DOCS_DIR ?= $(ROOT_DIR)/docs
TOOLS_DIR ?= $(ROOT_DIR)/tools
PROTO_DIR ?= $(ROOT_DIR)/proto
CONFIG_DIR ?= $(ROOT_DIR)/configs
SCRIPTS_DIR ?= $(ROOT_DIR)/scripts
MIGRATIONS_DIR ?= $(ROOT_DIR)/migrations
# Source Files
GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GOPACKAGES = $(shell $(GO) list ./... | grep -v /vendor/)
# Build Configuration
BUILD_TAGS ?=
EXTRA_TAGS ?=
ALL_TAGS = $(BUILD_TAGS) $(EXTRA_TAGS)
# Linker Flags
LD_FLAGS += -s -w
LD_FLAGS += -X '$(shell go list -m)/pkg/version.Version=$(VERSION)'
LD_FLAGS += -X '$(shell go list -m)/pkg/version.Commit=$(GIT_COMMIT)'
LD_FLAGS += -X '$(shell go list -m)/pkg/version.Branch=$(GIT_BRANCH)'
LD_FLAGS += -X '$(shell go list -m)/pkg/version.BuildTime=$(BUILD_TIME)'
LD_FLAGS += -X '$(shell go list -m)/pkg/version.BuildBy=$(BUILD_BY)'
# Performance & Debug Flags
GCFLAGS ?=
ASMFLAGS ?=
# Docker Configuration
DOCKER_REGISTRY ?= docker.io
DOCKER_REPO ?= $(ORGANIZATION)/$(PROJECT_NAME)
DOCKER_IMAGE ?= $(DOCKER_REGISTRY)/$(DOCKER_REPO)
DOCKER_TAG ?= $(VERSION)
DOCKERFILE ?= Dockerfile
DOCKER_BUILD_ARGS ?=
DOCKER_BUILD_CONTEXT ?= .
# Test Configuration
TEST_TIMEOUT ?= 5m
TEST_FLAGS ?= -v -race -cover
COVERAGE_OUT ?= coverage.out
COVERAGE_HTML ?= coverage.html
COVERAGE_THRESHOLD ?= 80
BENCH_FLAGS ?= -benchmem
BENCH_TIME ?= 2s
TEST_PATTERN ?= .
SKIP_PATTERN ?=
# Cross-Compilation Targets
PLATFORMS ?= \
linux/amd64/- \
linux/arm64/- \
linux/arm/7 \
darwin/amd64/- \
darwin/arm64/- \
windows/amd64/- \
windows/arm64/-
# =============================================================================
# π¨ Terminal Colors & Emoji
# =============================================================================
# Colors
BLUE := \033[34m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
MAGENTA := \033[35m
CYAN := \033[36m
WHITE := \033[37m
BOLD := \033[1m
RESET := \033[0m
# Status Indicators
INFO := @printf "$(BLUE)βΉοΈ $(RESET)"
SUCCESS := @printf "$(GREEN)β
$(RESET)"
WARN := @printf "$(YELLOW)β οΈ $(RESET)"
ERROR := @printf "$(RED)β $(RESET)"
WORKING := @printf "$(CYAN)π¨ $(RESET)"
DEBUG := @printf "$(MAGENTA)π $(RESET)"
ROCKET := @printf "$(GREEN)π $(RESET)"
PACKAGE := @printf "$(CYAN)π¦ $(RESET)"
TRASH := @printf "$(YELLOW)ποΈ $(RESET)"
# =============================================================================
# π― Core Build System
# =============================================================================
.PHONY: init
init: ## Initialize project with sensible defaults
$(INFO) Initializing project...
@if [ ! -f "go.mod" ]; then \
$(GO) mod init $(shell basename $(CURDIR)); \
fi
@if [ ! -f ".env" ]; then \
echo "# Project Configuration" > .env; \
echo "PROJECT_NAME=$(PROJECT_NAME)" >> .env; \
echo "ENABLE_DOCKER=true" >> .env; \
echo "ENABLE_PROTO=false" >> .env; \
fi
@if [ ! -f ".gitignore" ]; then \
curl -sL https://www.gitignore.io/api/go > .gitignore; \
fi
@mkdir -p \
main \
testdata \
.github/workflows
@if [ ! -f "main/main.go" ]; then \
echo 'package main\n\nimport "fmt"\n\nfunc main() {\n fmt.Println("Hello, World!")\n}' > main/main.go; \
fi
$(MAKE) deps
$(SUCCESS) Project initialized!
.PHONY: build
build: $(BIN_DIR) ## Build all targets
$(WORKING) Building project...
@$(foreach target,$(BUILD_TARGETS),\
$(MAKE) build-target TARGET=$(target) $(if $(filter true,$(ENABLE_PARALLEL)),--jobs=$(PARALLEL_JOBS)) &)
@wait
$(SUCCESS) Build complete!
.PHONY: build-target
build-target: generate
$(INFO) Building $(TARGET)...
@if [ -f "$(TARGET)/Makefile" ]; then \
$(MAKE) -C $(TARGET) build; \
else \
CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build -tags '$(ALL_TAGS)' \
$(if $(filter true,$(ENABLE_BUILD_CACHE)),-x) \
-ldflags '$(LD_FLAGS)' \
-gcflags '$(GCFLAGS)' \
-asmflags '$(ASMFLAGS)' \
-o $(BIN_DIR)/$(notdir $(TARGET)) \
./main; \
fi
.PHONY: install
install: build ## Install the application
$(WORKING) Installing $(PROJECT_NAME)...
$(GO) install -tags '$(ALL_TAGS)' -ldflags '$(LD_FLAGS)' ./main
$(SUCCESS) Installation complete!
# =============================================================================
# π Development Workflow
# =============================================================================
.PHONY: dev
dev: deps generate ## Start development environment
$(INFO) Starting development environment...
@if [ ! -f ".air.toml" ]; then \
cp $(CONFIG_DIR)/air.toml.example .air.toml 2>/dev/null || \
curl -sL https://raw.githubusercontent.com/air-verse/air/refs/heads/master/air_example.toml > .air.toml; \
fi
$(ROCKET) Running with hot reload...
$(AIR) -c .air.toml
.PHONY: run
run: build ## Run the application
$(ROCKET) Running $(PROJECT_NAME)...
$(BIN_DIR)/$(PROJECT_NAME)
.PHONY: generate
generate: ## Run code generation
$(WORKING) Running code generation...
$(GO) generate ./...
@if [ -n "$(wildcard $(PROTO_DIR)/*.proto)" ]; then \
$(MAKE) proto; \
fi
$(SUCCESS) Generation complete!
# =============================================================================
# π§ͺ Testing & Quality
# =============================================================================
.PHONY: test
test: ## Run tests
$(INFO) Running tests...
$(GO) test $(TEST_FLAGS) \
-timeout $(TEST_TIMEOUT) \
-run '$(TEST_PATTERN)' \
$(if $(SKIP_PATTERN),-skip '$(SKIP_PATTERN)') \
./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
$(INFO) Running tests with coverage...
$(GO) test $(TEST_FLAGS) \
-timeout $(TEST_TIMEOUT) \
-coverprofile=$(COVERAGE_OUT) \
./...
$(GO) tool cover -html=$(COVERAGE_OUT) -o $(COVERAGE_HTML)
@coverage=$$(go tool cover -func=$(COVERAGE_OUT) | grep total | awk '{print $$3}' | sed 's/%//'); \
if [ "$${coverage%.*}" -lt "$(COVERAGE_THRESHOLD)" ]; then \
$(ERROR) "Coverage $${coverage}% is below threshold $(COVERAGE_THRESHOLD)%"; \
exit 1; \
fi
$(SUCCESS) Coverage report generated: $(COVERAGE_HTML)
.PHONY: test-integration
test-integration: ## Run integration tests
$(INFO) Running integration tests...
$(GO) test $(TEST_FLAGS) \
-tags=integration \
-timeout $(TEST_TIMEOUT) \
./...
.PHONY: test-e2e
test-e2e: ## Run end-to-end tests
$(INFO) Running end-to-end tests...
$(GO) test $(TEST_FLAGS) \
-tags=e2e \
-timeout $(TEST_TIMEOUT) \
./test/e2e/...
.PHONY: bench
bench: ## Run benchmarks
$(INFO) Running benchmarks...
$(GO) test -bench=. \
$(BENCH_FLAGS) \
-run=^$ \
-benchtime=$(BENCH_TIME) \
./...
.PHONY: lint
lint: ## Run linters
$(INFO) Running linters...
$(GOLANGCI_LINT) run --fix
$(SUCCESS) Lint complete!
.PHONY: fmt
fmt: ## Format code
$(INFO) Formatting code...
$(GO) fmt ./...
$(GOFUMPT) -l -w .
$(SUCCESS) Format complete!
.PHONY: vet
vet: ## Run go vet
$(INFO) Running go vet...
$(GO) vet ./...
$(SUCCESS) Vet complete!
.PHONY: security
security: ## Run security checks
$(INFO) Running security checks...
$(GOVULNCHECK) ./...
$(SUCCESS) Security check complete!
# =============================================================================
# ποΈ Build Variations
# =============================================================================
.PHONY: build-all
build-all: $(DIST_DIR) ## Build for all platforms
$(WORKING) Building for all platforms...
@$(foreach platform,$(PLATFORMS),\
$(eval OS := $(word 1,$(subst /, ,$(platform)))) \
$(eval ARCH := $(word 2,$(subst /, ,$(platform)))) \
$(eval ARM := $(word 3,$(subst /, ,$(platform)))) \
$(WORKING) Building for $(OS)/$(ARCH)$(if $(ARM),/v$(ARM))... && \
GOOS=$(OS) GOARCH=$(ARCH) $(if $(ARM),GOARM=$(ARM)) \
CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build -tags '$(ALL_TAGS)' \
-ldflags '$(LD_FLAGS)' \
-o $(DIST_DIR)/$(PROJECT_NAME)-$(OS)-$(ARCH)$(if $(ARM),v$(ARM))$(if $(findstring windows,$(OS)),.exe,) \
./cmd/$(PROJECT_NAME) ; \
)
$(PACKAGE) Creating release archives...
@cd $(DIST_DIR) && \
for file in $(PROJECT_NAME)-* ; do \
if [ -f "$$file" ]; then \
tar czf "$$file.tar.gz" "$$file" || exit 1; \
rm -f "$$file"; \
fi \
done
$(SUCCESS) All platforms built and archived!
.PHONY: build-debug
build-debug: GCFLAGS += -N -l ## Build with debug symbols
build-debug: BUILD_TAGS += debug
build-debug: build
.PHONY: build-race
build-race: CGO_ENABLED=1 ## Build with race detector
build-race: BUILD_TAGS += race
build-race: build
# =============================================================================
# π¦ Docker Support
# =============================================================================
.PHONY: docker-build
docker-build: ## Build Docker image
$(WORKING) Building Docker image...
docker build $(DOCKER_BUILD_ARGS) \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-f $(DOCKERFILE) \
-t $(DOCKER_IMAGE):$(DOCKER_TAG) \
$(DOCKER_BUILD_CONTEXT)
$(SUCCESS) Docker image built!
.PHONY: docker-push
docker-push: ## Push Docker image
$(WORKING) Pushing Docker image...
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
$(SUCCESS) Docker image pushed!
.PHONY: docker-run
docker-run: ## Run Docker container
$(ROCKET) Running Docker container...
docker run --rm -it $(DOCKER_IMAGE):$(DOCKER_TAG)
# =============================================================================
# ποΈ Database Operations
# =============================================================================
.PHONY: db-migrate
db-migrate: ## Run database migrations
$(INFO) Running database migrations...
@if [ -d "$(MIGRATIONS_DIR)" ]; then \
go run -tags 'postgres mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest \
-database "$(DATABASE_URL)" \
-path $(MIGRATIONS_DIR) up; \
else \
$(WARN) No migrations directory found; \
fi
.PHONY: db-rollback
db-rollback: ## Rollback database migration
$(INFO) Rolling back database migration...
go run -tags 'postgres mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest \
-database "$(DATABASE_URL)" \
-path $(MIGRATIONS_DIR) down 1
.PHONY: db-reset
db-reset: ## Reset database
$(WARN) Resetting database...
go run -tags 'postgres mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest \
-database "$(DATABASE_URL)" \
-path $(MIGRATIONS_DIR) drop -f
# =============================================================================
# π Reporting & Analytics
# =============================================================================
.PHONY: report
report: ## Generate project reports
$(INFO) Generating project reports...
@mkdir -p $(DOCS_DIR)/reports
@$(MAKE) test-coverage
@$(MAKE) benchmark-report
@$(MAKE) lint-report
@$(MAKE) security-report
$(SUCCESS) Reports generated in $(DOCS_DIR)/reports
.PHONY: benchmark-report
benchmark-report:
$(GO) test -bench=. -benchmem ./... > $(DOCS_DIR)/reports/benchmark.txt
.PHONY: lint-report
lint-report:
$(GOLANGCI_LINT) run --out-format checkstyle > $(DOCS_DIR)/reports/lint-checkstyle.xml
.PHONY: security-report
security-report:
$(GOVULNCHECK) -json ./... > $(DOCS_DIR)/reports/security.json
# =============================================================================
# π CI/CD Integration
# =============================================================================
.PHONY: ci
ci: ## Run CI pipeline
$(INFO) Running CI pipeline...
@$(MAKE) deps-verify
@$(MAKE) lint
@$(MAKE) test-coverage
@$(MAKE) security
@$(MAKE) build
$(SUCCESS) CI pipeline complete!
.PHONY: cd
cd: ## Run CD pipeline
$(INFO) Running CD pipeline...
@$(MAKE) build
@if [ "$(ENABLE_DOCKER)" = "true" ]; then \
$(MAKE) docker-build; \
$(MAKE) docker-push; \
fi
$(SUCCESS) CD pipeline complete!
# =============================================================================
# π§Ή Cleanup & Maintenance
# =============================================================================
.PHONY: clean
clean: ## Clean build artifacts
$(TRASH) Cleaning build artifacts...
rm -rf $(BIN_DIR) $(DIST_DIR)
$(GO) clean -cache -testcache -modcache
$(SUCCESS) Clean complete!
.PHONY: deps
deps: ## Install dependencies
$(WORKING) Installing dependencies...
$(GO) mod download
@if [ ! -f "$(GOLANGCI_LINT)" ]; then \
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@if [ ! -f "$(GOFUMPT)" ]; then \
$(GO) install mvdan.cc/gofumpt@latest; \
fi
@if [ ! -f "$(GOVULNCHECK)" ]; then \
$(GO) install golang.org/x/vuln/cmd/govulncheck@latest; \
fi
@if [ ! -f "$(MOCKGEN)" ]; then \
$(GO) install github.com/golang/mock/mockgen@latest; \
fi
@if [ ! -f "$(AIR)" ]; then \
$(GO) install github.com/air-verse/air@latest; \
fi
$(SUCCESS) Dependencies installed!
.PHONY: deps-update
deps-update: ## Update dependencies
$(WORKING) Updating dependencies...
$(GO) get -u ./...
$(GO) mod tidy
$(SUCCESS) Dependencies updated!
.PHONY: deps-verify
deps-verify: ## Verify dependencies
$(INFO) Verifying dependencies...
$(GO) mod verify
$(SUCCESS) Dependencies verified!
# =============================================================================
# π Documentation
# =============================================================================
.PHONY: docs
docs: $(DOCS_DIR) ## Generate documentation
$(WORKING) Generating documentation...
@mkdir -p $(DOCS_DIR)
$(GO) doc -all > $(DOCS_DIR)/API.md
@if [ -f "README.md.tmpl" ]; then \
VERSION=$(VERSION) \
BUILD_TIME=$(BUILD_TIME) \
envsubst < README.md.tmpl > README.md; \
fi
$(SUCCESS) Documentation generated!
.PHONY: serve-docs
serve-docs: ## Serve documentation locally
$(ROCKET) Serving documentation at http://localhost:6060
$(GODOC) -http=:6060
# =============================================================================
# π οΈ Tools & Utilities
# =============================================================================
.PHONY: tools
tools: ## Install all tools
$(INFO) Installing tools...
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GO) install mvdan.cc/gofumpt@latest
$(GO) install golang.org/x/vuln/cmd/govulncheck@latest
$(GO) install github.com/golang/mock/mockgen@latest
$(GO) install github.com/air-verse/air@latest
$(GO) install github.com/swaggo/swag/cmd/swag@latest
$(SUCCESS) Tools installed!
.PHONY: proto
proto: ## Generate protocol buffers
$(WORKING) Generating protocol buffers...
@if [ -d "$(PROTO_DIR)" ]; then \
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
$(PROTO_DIR)/*.proto; \
fi
$(SUCCESS) Protocol buffers generated!
.PHONY: mock
mock: ## Generate mocks
$(WORKING) Generating mocks...
$(MOCKGEN) -source=pkg/interfaces.go -destination=pkg/mocks/mocks.go
$(SUCCESS) Mocks generated!
.PHONY: version
version: ## Display version information
@echo "$(CYAN)Version:$(RESET) $(VERSION)"
@echo "$(CYAN)Commit:$(RESET) $(GIT_COMMIT)"
@echo "$(CYAN)Branch:$(RESET) $(GIT_BRANCH)"
@echo "$(CYAN)Built:$(RESET) $(BUILD_TIME)"
@echo "$(CYAN)Built by:$(RESET) $(BUILD_BY)"
@echo "$(CYAN)Go version:$(RESET) $(shell $(GO) version)"
# =============================================================================
# π Directory Creation
# =============================================================================
$(BIN_DIR) $(DIST_DIR) $(DOCS_DIR):
mkdir -p $@
# =============================================================================
# π‘ Help
# =============================================================================
.PHONY: help
help: ## Show this help message
@echo "$(CYAN)$(BOLD)$(PROJECT_NAME) - $(DESCRIPTION)$(RESET)"
@echo "$(WHITE)Maintained by $(MAINTAINER)$(RESET)\n"
@echo "$(CYAN)$(BOLD)Available targets:$(RESET)"
@awk 'BEGIN {FS = ":.*##"; printf ""} \
/^[a-zA-Z_-]+:.*?##/ { printf " $(CYAN)%-20s$(RESET) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(MAGENTA)%s$(RESET)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help