-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
46 lines (34 loc) · 1.44 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
PROJECT_NAME := "go-pb"
USER_NAME := "iliafrenkel"
PKG := "github.com/$(USER_NAME)/$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
B=$(shell git rev-parse --abbrev-ref HEAD)
BRANCH=$(subst /,-,$(B))
GITREV=$(shell git describe --abbrev=7 --always --tags | cut -d- -f1-2)
REV=$(GITREV)-$(BRANCH)-$(shell date +%Y%m%d-%H:%M:%S)
LDFLAGS=-ldflags "-X 'main.revision=$(REV)' -X 'main.version=$(GITREV)' -X 'main.branch=$(BRANCH)' -s -w"
all: dep lint test build
info: ## Show the revision
@echo "branch: $(BRANCH)"
@echo "version: $(GITREV)"
@echo "revision: $(REV)"
dep: ## Get the dependencies
@go mod tidy
@go mod download
lint: ## Lint all Golang files
@gosec ${PKG_LIST}
@go vet ${PKG_LIST}
@staticcheck ${PKG_LIST}
test: ## Run all the unit tests
@go test -short ${PKG_LIST}
test-coverage: ## Run all the unit tests with coverage report
@go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST}
@cat cover.out >> coverage.txt
build: info dep ## Build the binary
- cd cmd && CGO_ENABLED=0 go build $(LDFLAGS) -o ../build/$(PROJECT_NAME)
clean: ## Remove previous build
@rm -f build/$(PROJECT_NAME)*
help: ## Print this help message
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: all build clean dep info help lint test test-coverage