-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
103 lines (84 loc) · 2.38 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
PACKAGE = interview
DATE ?= $(shell date +%FT%T%z)
VERSION ?= $(shell echo $(shell cat $(PWD)/.version)-$(shell git describe --tags --always))
GO = go
GOROOT ?= $(shell go env GOROOT)
GODOC = godoc
GOFMT = gofmt
GOLINT = golangci-lint
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[0;35m▶\033[0m")
GO_PACKAGE = github.com/gustvision/powder-interview
API = api
INTEGRATION = integration
.PHONY: all
all: api
.PHONY: api
api: ## Build api binary
$(info $(M) building executable api…) @
$Q cd cmd/$(API) && $(GO) build \
-mod=readonly \
-tags release \
-ldflags '-X main.version=$(VERSION)' \
-o ../../bin/$(PACKAGE)_$(API)_$(VERSION)
$Q cp bin/$(PACKAGE)_$(API)_$(VERSION) bin/$(PACKAGE)_$(API)
.PHONY: integration
integration: ## Build integration binary
$(info $(M) building executable integration…) @
$Q cd cmd/$(INTEGRATION) && $(GO) build \
-mod=readonly \
-tags release \
-ldflags '-X main.version=$(VERSION)' \
-o ../../bin/$(PACKAGE)_$(INTEGRATION)_$(VERSION)
$Q cp bin/$(PACKAGE)_$(INTEGRATION)_$(VERSION) bin/$(PACKAGE)_$(INTEGRATION)
.PHONY: migrate
migrate: ## Migrate sql db
$(info $(M) migrate…) @
$Q psql --host=0.0.0.0 --user=postgres postgres -f migrations/00.sql
.PHONY: populate
populate: ## Populate sql db with test data
$(info $(M) populate…) @
$Q psql --host=0.0.0.0 --user=postgres postgres -f migrations/populate.sql
# Vendor
.PHONY: vendor
vendor:
$(info $(M) running go mod vendor…) @
$Q $(GO) mod vendor
# Tidy
.PHONY: tidy
tidy:
$(info $(M) running go mod tidy…) @
$Q $(GO) mod tidy
# Check
.PHONY: check
check: vendor test lint
# Lint
.PHONY: lint
lint:
$(info $(M) running $(GOLINT)…)
$Q $(GOLINT) run
# Test
.PHONY: test
test:
$(info $(M) running go test…) @
$Q $(GO) test -cover -race -v ./...
# Helpers
.PHONY: go-version
go-version: ## Print go version used in this makefile
$Q echo $(GO)
.PHONY: fmt
fmt: ## Format code
$(info $(M) running $(GOFMT)…) @
$Q $(GOFMT) ./...
.PHONY: doc
doc: ## Generate project documentation
$(info $(M) running $(GODOC)…) @
$Q $(GODOC) ./...
.PHONY: version
version: ## Print current project version
@echo $(VERSION)
.PHONY: help
help: ## Print this
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'