forked from cycloidio/terracost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (60 loc) · 1.7 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
IS_CI ?= 0
DOCKER_COMPOSE_CMD := docker-compose
GO_CMD := go
GO_TEST_CMD := $(GO_CMD) test
GO_RUN_CMD := $(GO_CMD) run
MYSQL_USER := root
MYSQL_PASS := terracost
MYSQL_DB := terracost_test
MYSQL_DUMP ?= mysql/testdata/2023-02-23-pricing.sql.gz
BIN_DIR := $(GOPATH)/bin
GOLINT := $(BIN_DIR)/golinter
GOIMPORTS := $(BIN_DIR)/goimports
ENUMER := $(BIN_DIR)/enumer
MOCKGEN := $(BIN_DIR)/mockgen
# The ci rule is voluntarily simple because
# the CI requires to run the command separately
# and not all at once, otherwise it wouldn't work
.PHONY: ci
ci: lint
@$(GO_TEST_CMD) ./...
.PHONY: test
test: lint down db-up db-migrate
@$(GO_TEST_CMD) ./...
.PHONY: db-inject
db-inject:
@zcat $(MYSQL_DUMP) | $(DOCKER_COMPOSE_CMD) exec -T database mysql -u$(MYSQL_USER) -p$(MYSQL_PASS) $(MYSQL_DB)
$(ENUMER):
@go install github.com/dmarkham/enumer
$(GOLINT):
@go install golang.org/x/lint/golint
$(GOIMPORTS):
@go install golang.org/x/tools/cmd/goimports
$(MOCKGEN):
@go get -u github.com/golang/mock/mockgen
.PHONY: lint
lint: $(GOLINT) $(GOIMPORTS)
@golint -set_exit_status ./... && test -z "`$(GO_CMD) list -f {{.Dir}} ./... | xargs goimports -l | tee /dev/stderr`"
.PHONY: db-up
db-up: # Start the DB server
ifeq ($(IS_CI), 0)
@$(DOCKER_COMPOSE_CMD) up -d database
@$(DOCKER_COMPOSE_CMD) run wait -c database:3306
endif
.PHONY: down
down:
@$(DOCKER_COMPOSE_CMD) down
.PHONY: db-migrate
db-migrate: db-up
@$(GO_RUN_CMD) scripts/migrate.go
.PHONY: db-cli
db-cli:
@$(DOCKER_COMPOSE_CMD) exec database mysql -u$(MYSQL_USER) -p$(MYSQL_PASS) $(MYSQL_DB)
.PHONY: generate
generate: $(GOIMPORTS) $(ENUMER) $(MOCKGEN)
@rm -rf ./mock/
@$(GO_CMD) generate ./...
@goimports -w ./mock
.PHOHY: goimports
goimports:
@goimports -w ./