From ef31263797d14f50cdb87f77248a6bd169e3da30 Mon Sep 17 00:00:00 2001 From: Dimas Yudha P Date: Thu, 3 Nov 2022 23:47:28 +0700 Subject: [PATCH] refactoring makefile, also adding test (#71) --- Makefile | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index dea2720..00ca229 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,24 @@ -pull: - git pull +DATE ?= $(shell date +%FT%T%z) +VERSION ?= $(git describe --tags --always --dirty --match=v* 2> /dev/null || \ + cat $(CURDIR)/.version 2> /dev/null || echo "v0") -build: - go build -o bin/dashboard . +.PHONY: test +test: ; $(info $(M) start unit testing...) @ + @go test $$(go list ./... | grep -v /mocks/) --race -v -short -coverprofile=profile.cov + @echo "\n*****************************" + @echo "** TOTAL COVERAGE: $$(go tool cover -func profile.cov | grep total | grep -Eo '[0-9]+\.[0-9]+')% **" + @echo "*****************************\n" +.PHONY: pull +pull: ; $(info $(M) Pulling source...) @ + @git pull -debug: - DEBUG=1 ./bin/dashboard \ No newline at end of file +.PHONY: build +build: $(BIN) ; $(info $(M) Building executable...) @ ## Build program binary + $Q $(GO) build \ + -ldflags '-X main.version=$(VERSION) -X main.buildDate=$(DATE)' \ + -o bin/dashboard . + +.PHONY: debug +debug: ; $(info $(M) Running dashboard in debug mode...) @ + @DEBUG=1 ./bin/dashboard \ No newline at end of file