github.com/retailcrm/mg-bot-helper@v0.0.0-20201229112329-a17255681a84/Makefile (about)

     1  ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
     2  SRC_DIR=$(ROOT_DIR)/src
     3  MIGRATIONS_DIR=$(ROOT_DIR)/migrations
     4  CONFIG_FILE=$(ROOT_DIR)/config.yml
     5  BIN=$(ROOT_DIR)/bin/bot
     6  REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown")
     7  
     8  fmt:
     9  	@echo "==> Running gofmt"
    10  	@gofmt -l -s -w $(SRC_DIR)
    11  
    12  deps:
    13  	@echo "==> Installing dependencies"
    14  	@go mod tidy
    15  
    16  build: deps fmt
    17  	@echo "==> Building"
    18  	@cd $(SRC_DIR) && CGO_ENABLED=0 go build -o $(BIN) -ldflags "-X common.build=${REVISION}" .
    19  	@echo $(BIN)
    20  
    21  migrate: build
    22  	${BIN} --config $(CONFIG_FILE) migrate -p $(MIGRATIONS_DIR)
    23  
    24  migrate_down: build
    25  	@${BIN} --config $(CONFIG_FILE) migrate -v down
    26  
    27  run: migrate
    28  	@echo "==> Running"
    29  	@${BIN} --config $(CONFIG_FILE) run
    30  
    31  test: deps fmt
    32  	@echo "==> Running tests"
    33  	@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race