forked from chanify/chanify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
51 lines (42 loc) · 1.33 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
# Makefile - Chanify server
PACKAGE?=$(shell go list .|head -1)
PROJECT_NAME?=$(notdir $(PACKAGE))
## Env variables
TAG_COMMIT=$(shell git rev-list --tags --max-count=1)
COMMIT_REF_NAME=$(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(TAG_COMMIT),)
MAIN_VER=0.0.0
else
MAIN_VER=$(shell git describe --tags ${TAG_COMMIT}|cut -c2-)
endif
ifeq ($(GITHUB_SHA),)
GITHUB_SHA=$(shell git rev-parse HEAD)
endif
ifneq ($(GITHUB_SHA), $(TAG_COMMIT))
SUB_VER=-$(COMMIT_REF_NAME)
endif
VERSION=${MAIN_VER}${SUB_VER}
GIT_COMMIT=$(shell echo ${GITHUB_SHA}|cut -c1-7)
BUILD_TIME=$(shell date -u +%FT%TZ)
LDFLAGS= -ldflags "\
-X ${PACKAGE}/cmd.GitCommit=${GIT_COMMIT} \
-X ${PACKAGE}/cmd.BuildTime=${BUILD_TIME} \
-X ${PACKAGE}/cmd.Version=${VERSION}"
# Command
lint:
@echo Lint ${PACKAGE}
@golangci-lint run ./...
test:
@echo Test ${PACKAGE}
@go list -f '{{if gt (len .TestGoFiles) 0}}"go test -tags test -covermode count -coverprofile {{.Name}}.coverprofile -coverpkg ./... {{.ImportPath}}"{{end}}' ./... | xargs -I {} sh -c {}
@gocovmerge `ls *.coverprofile` | grep -v ".pb.go" > coverage.out
@go tool cover -func coverage.out | grep total
cover: test
@go tool cover -html coverage.out
build:
@echo Build ${PACKAGE}
@go build ${LDFLAGS} ${PACKAGE}
install:
@echo Build ${PACKAGE}
@go install ${LDFLAGS} ${PACKAGE}
.PHONY: lint test cover build install