2018-05-17 18:35:53 +03:00
|
|
|
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
SRC_DIR=$(ROOT_DIR)
|
2018-05-18 15:38:59 +03:00
|
|
|
MIGRATIONS_DIR=$(ROOT_DIR)/migrations
|
2018-05-17 18:35:53 +03:00
|
|
|
CONFIG_FILE=$(ROOT_DIR)/config.yml
|
|
|
|
CONFIG_TEST_FILE=$(ROOT_DIR)/config_test.yml
|
2018-05-18 15:38:59 +03:00
|
|
|
BIN=$(ROOT_DIR)/bin/mg-telegram
|
2018-05-17 18:35:53 +03:00
|
|
|
REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown")
|
|
|
|
|
|
|
|
ifndef GOPATH
|
|
|
|
$(error GOPATH must be defined)
|
|
|
|
endif
|
|
|
|
|
|
|
|
export GOPATH := $(GOPATH):$(ROOT_DIR)
|
|
|
|
|
2018-05-18 15:38:59 +03:00
|
|
|
build: deps fmt
|
|
|
|
@echo "==> Building"
|
|
|
|
@go build -o $(BIN) -ldflags "-X common.build=${REVISION}" .
|
|
|
|
@echo $(BIN)
|
|
|
|
|
|
|
|
run: migrate
|
|
|
|
@echo "==> Running"
|
|
|
|
@${BIN} --config $(CONFIG_FILE) run
|
|
|
|
|
2018-05-25 16:01:58 +03:00
|
|
|
test: deps fmt
|
|
|
|
@echo "==> Running tests"
|
|
|
|
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race
|
|
|
|
|
|
|
|
jenkins_test: deps
|
|
|
|
@echo "==> Running tests (result in test-report.xml)"
|
|
|
|
@go get -v -u github.com/jstemmer/go-junit-report
|
|
|
|
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race | go-junit-report -set-exit-code > $(SRC_DIR)/test-report.xml
|
|
|
|
|
2018-05-17 18:35:53 +03:00
|
|
|
fmt:
|
|
|
|
@echo "==> Running gofmt"
|
|
|
|
@gofmt -l -s -w $(SRC_DIR)
|
|
|
|
|
2018-05-18 15:38:59 +03:00
|
|
|
deps:
|
|
|
|
@echo "==> Installing dependencies"
|
2018-05-17 18:35:53 +03:00
|
|
|
$(eval DEPS:=$(shell cd $(SRC_DIR) \
|
|
|
|
&& go list -f '{{join .Imports "\n"}}{{ "\n" }}{{join .TestImports "\n"}}' ./... \
|
|
|
|
| sort | uniq | tr '\r' '\n' | paste -sd ' ' -))
|
|
|
|
@go get -d -v $(DEPS)
|
|
|
|
|
|
|
|
migrate: build
|
|
|
|
@${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/
|
|
|
|
|
2018-05-18 15:38:59 +03:00
|
|
|
migrate_test: build
|
2018-05-25 16:03:50 +03:00
|
|
|
@${BIN} --config $(CONFIG_TEST_FILE) migrate ./migrations/
|
2018-05-18 15:38:59 +03:00
|
|
|
|
|
|
|
migrate_down: build
|
|
|
|
@${BIN} --config $(CONFIG_FILE) migrate -v down
|