-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
57 lines (45 loc) · 2.04 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
MODULE = $(shell go list -m)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || echo "1.0.0")
PACKAGES := $(shell go list ./... | grep -v /vendor/)
LDFLAGS := -ldflags "-X main.Version=${VERSION}"
#CONFIG_FILE ?= ./config/local.yml
#APP_DSN ?= $(shell sed -n 's/^dsn:[[:space:]]*"\(.*\)"/\1/p' $(CONFIG_FILE))
#MIGRATE := docker run -v $(shell pwd)/migrations:/migrations --network host migrate/migrate:v4.10.0 -path=/migrations/ -database "$(APP_DSN)"
PID_FILE := './.pid'
FSWATCH_FILE := './fswatch.cfg'
.PHONY: default
default: help
.PHONY: help
help: ## help information about make commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: test
test: ## run unit tests
@echo "mode: count" > coverage-all.out
@$(foreach pkg,$(PACKAGES), \
go test -p=1 -cover -covermode=count -coverprofile=coverage.out ${pkg}; \
tail -n +2 coverage.out >> coverage-all.out;)
.PHONY: test-cover
test-cover: test ## run unit tests and show test coverage information
go tool cover -html=coverage-all.out
.PHONY: run
run: ## run the API server
go run ${LDFLAGS} cmd/server/main.go
.PHONY: run-restart
run-restart: ## restart the API server
@pkill -P `cat $(PID_FILE)` || true
@printf '%*s\n' "80" '' | tr ' ' -
@echo "Source file changed. Restarting server..."
@go run ${LDFLAGS} cmd/server/main.go & echo $$! > $(PID_FILE)
@printf '%*s\n' "80" '' | tr ' ' -
run-live: ## run the API server with live reload support (requires fswatch)
@go run ${LDFLAGS} cmd/server/main.go & echo $$! > $(PID_FILE)
@fswatch -x -o --event Created --event Updated --event Renamed -r internal pkg cmd config | xargs -n1 -I {} make run-restart
.PHONY: build
build: ## build the API server binary
CGO_ENABLED=0 go build ${LDFLAGS} -a -o server $(MODULE)/cmd/server
.PHONY: build-docker
build-docker: ## build the API server as a docker image
docker build -f Dockerfile -t server .
.PHONY: clean
clean: ## remove temporary files
rm -rf server coverage.out coverage-all.out