-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
164 lines (125 loc) · 2.95 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
LOCAL_BIN := $(CURDIR)/.bin
DB_DSN := postgres://db:db@localhost:5432/db_test?sslmode=disable
DB_MIGRATIONS_DIR := internal/database/migrations
export PATH := $(LOCAL_BIN):$(PATH)
#
# Build
#
default: build
.PHONY: build
build: build/server build/client
.PHONY: build/server
build/server:
@echo "Building server..."
@go build -o server ./cmd/server
.PHONY: build/client
build/client:
@echo "Building client..."
@go build -o sonar ./cmd/client
#
# Dev
#
.PHONY: dev
dev/server:
@$(LOCAL_BIN)/air
.PHONY: dev/docs
dev/docs:
cd docs && npm start
#
# Completions
#
.PHONY: completions
completions: build/client
@rm -rf completions
@mkdir completions
@./sonar completion zsh > completions/sonar.zsh
@./sonar completion bash > completions/sonar.bash
@./sonar completion fish > completions/sonar.fish
#
# Tools
#
override GOBIN := $(LOCAL_BIN)
.PHONY: tools
tools:
@GOBIN=$(GOBIN) go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
@GOBIN=$(GOBIN) go install github.com/air-verse/air@latest
@GOBIN=$(GOBIN) go install github.com/abice/go-enum@latest
@GOBIN=$(GOBIN) go install github.com/vektra/mockery/v2@latest
#
# Test
#
.PHONY: test
test:
@go test ./... -v -p 1 -coverprofile coverage.out
.PHONY: coverage/html
coverage/html:
@go tool cover -html=coverage.out
#
# Lint & format
#
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt ./...
.PHONY: lint
lint:
@echo "Linting code..."
@golangci-lint run
#
# Code generation
#
.PHONY: generate
generate: generate/api generate/cmd generate/client generate/mocks
.PHONY: generate/api
generate/api:
@echo "Generating API..."
@go run ./internal/codegen/*.go -type api > internal/modules/api/generated.go
@go fmt ./internal/modules/api
.PHONY: generate/cmd
generate/cmd:
@echo "Generating CLI..."
@go run ./internal/codegen/*.go -type cmd > internal/cmd/generated.go
@go fmt ./internal/cmd
.PHONY: generate/client
generate/client:
@echo "Generating API client..."
@go run ./internal/codegen/*.go -type apiclient > internal/modules/api/apiclient/generated.go
@go fmt ./internal/modules/api/apiclient
.PHONY: generate/mocks
generate/mocks:
@echo "Generating mocks..."
@$(LOCAL_BIN)/mockery \
--dir internal/actions \
--output internal/actions/mock \
--outpkg actions_mock \
--name Actions
#
# Migrations
#
override MIGRATE := $(LOCAL_BIN)/migrate -path $(DB_MIGRATIONS_DIR) -database $(DB_DSN)
.PHONY: migrations/create
migrations/create: guard-NAME
@$(LOCAL_BIN)/migrate create -ext sql -dir $(DB_MIGRATIONS_DIR) -seq $(NAME)
.PHONY: migrations/up
migrations/up:
@$(MIGRATE) up $(N)
.PHONY: migrations/down
migrations/down:
@$(MIGRATE) down $(N)
.PHONY: migrations/goto
migrations/goto: guard-V
@$(MIGRATE) goto $(V)
.PHONY: migrations/drop
migrations/drop:
@$(MIGRATE) drop
.PHONY: migrations/force
migrations/force: guard-V
@$(MIGRATE) force $(V)
#
# Helpers
#
guard-%:
@if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi