-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
232 lines (199 loc) · 6.58 KB
/
Makefile
File metadata and controls
232 lines (199 loc) · 6.58 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
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
MAKEFLAGS += --no-print-directory
MAIN_PACKAGE_PATH := .
BINARY_NAME := git-classrooms
APP_VERSION ?= $(shell git describe --tags --always --dirty)
APP_GIT_COMMIT ?= $(shell git rev-parse HEAD)
APP_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
APP_GIT_REPOSITORY ?= https://github.com/git-classrooms/git-classrooms
APP_BUILD_TIME ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
define GOFLAGS
-ldflags=" \
-s -w \
-X main.version=$(APP_VERSION) \
"
endef
# -X github.com/git-classrooms/git-classrooms/internal/storage/local/info.version=$(APP_VERSION) \
# -X github.com/git-classrooms/git-classrooms/internal/storage/local/info.gitCommit=$(APP_GIT_COMMIT) \
# -X github.com/git-classrooms/git-classrooms/internal/storage/local/info.gitBranch=$(APP_GIT_BRANCH) \
# -X github.com/git-classrooms/git-classrooms/internal/storage/local/info.gitRepository=$(APP_GIT_REPOSITORY) \
# -X github.com/git-classrooms/git-classrooms/internal/storage/local/info.buildTime=$(APP_BUILD_TIME) \
POSTGRES_USER ?= postgres
POSTGRES_PASSWORD ?= postgres
POSTGRES_DB ?= postgres
POSTGRES_HOST ?= localhost
POSTGRES_PORT ?= 5432
.PHONY: help
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build Build"
@echo " build/frontend Build frontend"
@echo " generate Generate"
@echo " generate/client Generate client pkg"
@echo " setup Install dependencies"
@echo " setup/ci Install dependencies for CI"
@echo " clean Clean"
@echo " run Run"
@echo " run/dev Run development environment"
@echo " build/docker Build docker image"
@echo " run/docker Run docker container"
@echo " infra/reset Reset infra with new seeding data. Manual actions required"
@echo " infra/up Run infrastructure in docker compose"
@echo " infra/stop Run infrastructure stop"
@echo " infra/down Run infrastructure down (delete)"
@echo " migrate/new name=<name> Create new migration"
@echo " migrate/check Check and print outstanding migrations"
@echo " migrate/status Migrate status"
@echo " tidy Fmt and Tidy"
@echo " lint Lint"
@echo " test Test"
@echo " test/verbose Test verbose"
@echo " config TODO: Edit config"
@echo " debug Debug"
.PHONY: run/dev
run/dev:
@echo "Starting development environment..."
@go tool concur || true
.PHONY: run
run: build
@echo "Running binary..."
@./bin/$(BINARY_NAME)
.PHONY: build
build:
@if [ -z "$(CI)" ]; then \
$(MAKE) generate; \
fi
@if ! [ -d ./frontend/dist ]; then \
$(MAKE) build/frontend; \
fi
@echo "Building binary..."
@CGO_ENABLED=0 go build $(GOFLAGS) -o ./bin/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
.PHONY: build/frontend
build/frontend:
@echo "Building frontend..."
@cd frontend && pnpm build
.PHONY: setup
setup: setup/frontend
@echo "Setting up environment..."
@# TODO: maybe go install github.com/mikefarah/yq/v4@latest
go mod download
.PHONY: setup/ci
setup/ci:
@echo "Installing..."
go mod download
.PHONY: setup/frontend
setup/frontend:
@cd frontend && pnpm install
.PHONY: clean
clean:
@echo "Cleaning up..."
@rm -rf ./bin ./tmp
@rm -f docs/docs.go docs/swagger.json docs/swagger.yaml
@rm -rf $(shell yq '.packages | to_entries | map(.value.config.dir) | .[]' .mockery.yaml)
@cd frontend && pnpm clean
.PHONY: generate
generate:
@echo "Generating code..."
@go generate ./...
@if [ -z "$(CI)" ]; then \
$(MAKE) generate/client; \
fi
.PHONY: generate/client
generate/client:
@echo "Generating client..."
@if ! [ -f "docs/swagger.yaml" ]; then \
$(MAKE) generate; \
fi
@cd frontend && pnpm generate
.PHONY: build/docker
build/docker:
@echo "Running docker..."
docker build -t $(BINARY_NAME)-docker \
--build-arg APP_VERSION=$(APP_VERSION) \
--build-arg APP_GIT_COMMIT=$(APP_GIT_COMMIT) \
--build-arg APP_GIT_BRANCH=$(APP_GIT_BRANCH) \
--build-arg APP_GIT_REPOSITORY=$(APP_GIT_REPOSITORY) \
--build-arg APP_BUILD_TIME=$(APP_BUILD_TIME) \
.
.PHONY: run/docker
run/docker:
@echo "Running docker..."
docker run -it --env-file .env --rm -p 3000:3000 $(BINARY_NAME)-docker
.PHONY: migrate/new
migrate/new:
@echo "Migrating up..."
@if [ -z "$(name)" ]; then \
echo "error: name is required"; \
echo "usage: make migrate/new name=name_of_migration"; \
exit 1; \
fi
go tool goose -dir model/database/migrations create $(name) sql
.PHONY: migrate/status
migrate/status:
@echo "Migrating status..."
go tool goose -dir model/database/migrations postgres "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)" status
.PHONY: migrate/up
migrate/up:
@echo "Migrating up..."
go tool goose -dir model/database/migrations postgres "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)" up
.PHONY: migrate/down
migrate/down:
@echo "Migrating down..."
go tool goose -dir model/database/migrations postgres "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)" down
.PHONY: migrate/check
migrate/check:
@echo "Building migrate tool..."
# @go build -o ./bin/migrate $(MAIN_PACKAGE_PATH)/code_gen/migrations/.
go tool migrations
.PHONY: tidy
tidy:
@echo "Tidying up..."
go fmt ./...
go tool swag fmt --exclude frontend
go mod tidy
.PHONY: lint
lint:
@echo "Linting..."
go tool golangci-lint run
.PHONY: lint/frontend
lint/frontend:
@echo "Linting frontend..."
cd frontend && pnpm lint
.PHONY: test/frontend
test/frontend:
@echo "Testing frontend..."
cd frontend && pnpm test
.PHONY: test
test:
@echo "Testing..."
go test -cover ./...
.PHONY: test/verbose
test/verbose:
@echo "Testing..."
go test -v -cover ./...
.PHONY: infra/reset
infra/reset:
@go tool seed -b=false
.PHONY: infra/up
infra/up:
@docker compose up -d
.PHONY: infra/logs
infra/logs:
@docker compose logs db -n 10 -f || true
.PHONY: infra/stop
infra/stop:
@docker compose stop
.PHONY: infra/down
infra/down:
@docker compose down --volumes
.PHONY: infra/status
infra/status:
@docker compose ps -a --format="table {{.Service}}\t{{.State}}\t{{.Status}}"
.PHONY: debug
debug:
@echo "Debugging..."
dlv debug
.PHONY: config
config:
@echo "TODO: Implement config with sops"