-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
83 lines (71 loc) · 2.91 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
# ==================================================================================== #
# HELPERS #
# ==================================================================================== #
## help: print this help message
.PHONY: help
help:
@echo Usage:
@echo run/api - print this help message
@echo run/api - run the api
@echo db/psql - connect to the db using psql
@echo db/migrations/new - create a new migration with the name passed as an argument
@echo db/migrations/up - run the up migrations using confirm as prerequisite
@echo vendor - tidy and vendor dependencies
@echo build/api - build the cmd/api application
## confirm: create the new confirm prompt from confirm.ps1.
## if on linux you can use https://stackoverflow.com/questions/47837071/making-make-clean-ask-for-confirmation
.PHONY: confirm
confirm:
powershell -File confirm.ps1
# ==================================================================================== #
# DEVELOPMENT #
# ==================================================================================== #
# run/api: run the api with the default DSN pruned from .env file,
# you can import the file directly or use ps script to load it before running
.PHONY: run/api
run/api:
@go run ./cmd/api
# db/psql: connect to the db using psql
.PHONY: db/psql
db/psql:
psql ${GROOVY_DB_DSN}
# db/migrations/new: create a new migration with the name passed as an argument
.PHONY: db/migrations/new
db/migrations/new:
@echo Creating migration files for ${name}...
migrate create -seq -ext .sql -dir=./migrations ${name}
# db/migrations/up: run the up migrations using confirm from confirm.p1 as prereq
.PHONY: db/migrations/up
db/migrations/up: confirm
@echo Running up migrations...
migrate -path=migrations -database=${GROOVY_DB_DSN} up
# ==================================================================================== #
# QUALITY Q/A #
# ==================================================================================== #
## audit: tidy dependencies and format, vet and test all code
.PHONY: audit
audit:
@echo 'Formatting code...'
go fmt ./...
@echo 'Vetting code...'
go vet ./...
staticcheck ./...
@echo 'Running tests...'
go test -race -vet=off ./...
## vendor: tidy and vendor dependencies
.PHONY: vendor
vendor:
@echo 'Tidying and verifying module dependencies...'
go mod tidy
go mod verify
@echo 'Vendoring dependencies...'
go mod vendor
# ==================================================================================== #
# BUILD
# ==================================================================================== #
## build/api: build the cmd/api application
.PHONY: build/api
build/api:
@echo 'Building cmd/api...'
go build -ldflags '-s' -o ./bin/api.exe ./cmd/api
## For linux: GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o bin/linux_amd64_api ./cmd/api