-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (115 loc) · 4.92 KB
/
Makefile
File metadata and controls
146 lines (115 loc) · 4.92 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
# Load .env file if it exists (optional - project uses config.yaml)
ifneq ($(wildcard .env),)
include .env
export
else ifneq ($(wildcard .env.example),)
$(info INFO: Using .env.example file)
include .env.example
export
else
$(info INFO: No .env file found. Project uses config.yaml for configuration.)
endif
LOCAL_BIN:=$(CURDIR)/bin
BASE_STACK = docker compose -f docker-compose.yml
INTEGRATION_TEST_STACK = $(BASE_STACK) -f docker-compose-integration-test.yml
ALL_STACK = $(INTEGRATION_TEST_STACK)
# HELP =================================================================================================================
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## Display this help screen
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
compose-up: ### Run docker compose (without backend and reverse proxy)
$(BASE_STACK) up --build -d db rabbitmq && docker compose logs -f
.PHONY: compose-up
compose-up-all: ### Run docker compose (with backend and reverse proxy)
$(BASE_STACK) up --build -d
.PHONY: compose-up-all
compose-up-integration-test: ### Run docker compose with integration test
$(INTEGRATION_TEST_STACK) up --build --abort-on-container-exit --exit-code-from integration-test
.PHONY: compose-up-integration-test
compose-down: ### Down docker compose
$(ALL_STACK) down --remove-orphans
.PHONY: compose-down
swag-v1: ### swag init
swag init -g internal/controller/http/router.go
.PHONY: swag-v1
proto-v1: ### generate source files from proto
protoc --go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
docs/proto/v1/*.proto
.PHONY: proto-v1
deps: ### deps tidy + verify
go mod tidy && go mod verify
.PHONY: deps
deps-audit: ### check dependencies vulnerabilities
govulncheck ./...
.PHONY: deps-audit
format: ### Run code formatter
gofumpt -l -w .
gci write . --skip-generated -s standard -s default
.PHONY: format
run: deps swag-v1 proto-v1 ### swag run for API v1
go mod download && \
CGO_ENABLED=0 go run -tags migrate ./cmd/app
.PHONY: run
docker-rm-volume: ### remove docker volume
docker volume rm go-clean-template_pg-data
.PHONY: docker-rm-volume
linter-golangci: ### check by golangci linter
golangci-lint run
.PHONY: linter-golangci
linter-hadolint: ### check by hadolint linter
git ls-files --exclude='Dockerfile*' --ignored | xargs hadolint
.PHONY: linter-hadolint
linter-dotenv: ### check by dotenv linter
dotenv-linter
.PHONY: linter-dotenv
test: ### run test
go test -v -race -covermode atomic -coverprofile=coverage.txt ./internal/...
.PHONY: test
test-unit: ### run unit tests only
go test -v -race -covermode atomic -coverprofile=coverage.txt ./internal/...
.PHONY: test-unit
test-coverage: ### run tests with coverage report
go test -v -race -covermode atomic -coverprofile=coverage.txt ./internal/... && \
go tool cover -html=coverage.txt -o coverage.html && \
echo "Coverage report generated: coverage.html"
.PHONY: test-coverage
test-coverage-view: ### run tests with coverage and open HTML report
go test -v -race -covermode atomic -coverprofile=coverage.txt ./internal/... && \
go tool cover -html=coverage.txt -o coverage.html && \
open coverage.html || xdg-open coverage.html || echo "Coverage report generated: coverage.html"
.PHONY: test-coverage-view
test-package: ### run tests for specific package (usage: make test-package PACKAGE=./internal/controller/http/v1)
go test -v -race -covermode atomic -coverprofile=coverage.txt $(PACKAGE)
.PHONY: test-package
test-short: ### run tests without race detector (faster)
go test -v -covermode atomic -coverprofile=coverage.txt ./internal/...
.PHONY: test-short
test-verbose: ### run tests with verbose output
go test -v -race -covermode atomic -coverprofile=coverage.txt ./internal/... -test.v
.PHONY: test-verbose
integration-test: ### run integration-test
go clean -testcache && go test -v ./integration-test/...
.PHONY: integration-test
mock: ### run mockgen
mockgen -source ./internal/repo/contracts.go -package usecase_test > ./internal/usecase/mocks_repo_test.go
mockgen -source ./internal/usecase/contracts.go -package usecase_test > ./internal/usecase/mocks_usecase_test.go
.PHONY: mock
migrate-create: ### create new migration
migrate create -ext sql -dir migrations '$(word 2,$(MAKECMDGOALS))'
.PHONY: migrate-create
migrate-up: ### migration up
migrate -path migrations -database '$(PG_URL)?sslmode=disable' up
.PHONY: migrate-up
bin-deps: ### install tools
GOBIN=$(LOCAL_BIN) go install tool
.PHONY: bin-deps
pre-commit: swag-v1 proto-v1 mock format linter-golangci test ### run pre-commit
.PHONY: pre-commit
docker-run-nats: ## Run NATS server in Docker
docker run -d --name nats-server -p 4222:4222 nats:latest
.PHONY: docker-run-nats