-
Notifications
You must be signed in to change notification settings - Fork 650
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (92 loc) · 3.67 KB
/
Makefile
File metadata and controls
117 lines (92 loc) · 3.67 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
ifneq ($(wildcard .env),)
include .env
export
else
$(warning WARNING: .env file not found! Using .env.example)
include .env.example
export
endif
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 nats && 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; exit_code=$$?; \
$(INTEGRATION_TEST_STACK) down --remove-orphans; exit $$exit_code
.PHONY: compose-up-integration-test
compose-down: ### Down docker compose
$(ALL_STACK) down --remove-orphans
.PHONY: compose-down
swag-v1: ### swag init
swag init --parseDependency -g internal/controller/restapi/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
fix-diff: ### Show code changes by `go fix`
go fix -diff ./...
.PHONY: fix-diff
format: ### Run code formatter
go fix ./...
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/... ./pkg/...
.PHONY: test
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
go install tool
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate
.PHONY: bin-deps
pre-commit: deps swag-v1 proto-v1 mock format linter-golangci test ### run pre-commit
.PHONY: pre-commit