-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (72 loc) · 3.14 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
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #
## audit: run quality control checks
.PHONY: audit
audit: test
go mod tidy -diff
go mod verify
test -z "$(shell gofmt -l .)"
go vet ./...
go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
## test: run all tests
.PHONY: test
test:
go test -v -race -buildvcs ./...
## test/cover: run all tests and display coverage
.PHONY: test/cover
test/cover:
go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./...
go tool cover -html=/tmp/coverage.out
# ==================================================================================== #
# DEVELOPMENT
# ==================================================================================== #
## tidy: tidy modfiles and format .go files
.PHONY: tidy
tidy:
go mod tidy -v
go fmt ./...
## build: build the cmd/api application
.PHONY: build
build:
go build -o=/tmp/bin/api ./cmd/api
## run: run the cmd/api application
.PHONY: run
run: build
/tmp/bin/api
# ==================================================================================== #
# SQL MIGRATIONS
# ==================================================================================== #
## migrations/new name=$1: create a new database migration
.PHONY: migrations/new
migrations/new:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest create -seq -ext=.sql -dir=./assets/migrations ${name}
## migrations/up: apply all up database migrations
.PHONY: migrations/up
migrations/up:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -path=./assets/migrations -database="sqlite3://db.sqlite" up
## migrations/down: apply all down database migrations
.PHONY: migrations/down
migrations/down:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -path=./assets/migrations -database="sqlite3://db.sqlite" down
## migrations/goto version=$1: migrate to a specific version number
.PHONY: migrations/goto
migrations/goto:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -path=./assets/migrations -database="sqlite3://db.sqlite" goto ${version}
## migrations/force version=$1: force database migration
.PHONY: migrations/force
migrations/force:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -path=./assets/migrations -database="sqlite3://db.sqlite" force ${version}
## migrations/version: print the current in-use migration version
.PHONY: migrations/version
migrations/version:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -path=./assets/migrations -database="sqlite3://db.sqlite" version