-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (59 loc) · 2.65 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
# Include .env if exists
-include .env
# -----------------------------------------------------------------------------
# General
# -----------------------------------------------------------------------------
# Git related
COMMIT_HASH = $(shell git rev-parse --short HEAD)
TAG = $(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD)
# GO related
GO ?= go
LDFLAGS = -X "main.CommitHash=$(COMMIT_HASH)" -X "main.Tag=$(TAG)"
# Database related
MYSQL_CONN = $(DB_USER):$(DB_PASS)@tcp($(DB_HOST))/$(DB_NAME)?parseTime=true
MIGRATIONS_DIR = resources/database/migrations
# -----------------------------------------------------------------------------
# Migrations
# -----------------------------------------------------------------------------
# Dump the migration status for the current DB
# Usage: make migrations-status
migrations-status:
@goose -dir "$(MIGRATIONS_DIR)" mysql "$(MYSQL_CONN)" status
# Creates new migration file in sequential order
# Usage: make migrations-create NAME=add_new_column
migrations-create:
@goose -dir "$(MIGRATIONS_DIR)" create ${NAME} sql
@goose -dir "$(MIGRATIONS_DIR)" mysql "$(MYSQL_CONN)" fix
# Migrate the DB to the most recent version available
# Usage: make migrations-up
migrations-up:
@goose -dir "$(MIGRATIONS_DIR)" mysql "$(MYSQL_CONN)" up
# Migrate the DB up by 1
# Usage: make migrations-up-by-one
migrations-up-by-one:
@goose -dir "$(MIGRATIONS_DIR)" mysql "$(MYSQL_CONN)" up-by-one
# Roll back the version by 1
# Usage: make migrations-down
migrations-down:
@goose -dir "$(MIGRATIONS_DIR)" mysql "$(MYSQL_CONN)" down
# -----------------------------------------------------------------------------
# Mocks
# -----------------------------------------------------------------------------
# Generate mocks for all interfaces
generate-mocks:
$(GO) generate ./...
# -----------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------
# Run tests
tests:
@$(GO) test -count=1 -race -v -tags=unit --parallel 10 ./... -coverprofile=testdata/coverage.out
# View test coverage in browser
view-coverage:
@$(GO) tool cover -html=testdata/coverage.out
# -----------------------------------------------------------------------------
# Build
# -----------------------------------------------------------------------------
# Build api binary
build:
$(GO) build -ldflags '$(LDFLAGS)' -o ./bin/main cmd/api/main.go