-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile.module
More file actions
82 lines (64 loc) · 1.92 KB
/
makefile.module
File metadata and controls
82 lines (64 loc) · 1.92 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# project name
PROJECT_NAME=xxxx
# main version
VERSION ?= $(shell git describe --tags --always --dirty)
# git commit Hash
COMMIT_HASH ?= $(shell git show -s --format=%H)
# build at
BUILD_TIME ?= $(shell date +"%F %T")
# go source file list
GOFILES := $(shell find . ! -path "./vendor/*" -name "*.go")
# unit test environment
TEST_ENV :=
# benchmark test environment
BENCHMARK_ENV :=
# unit test options
TEST_OPTS := -v
# benchmark test options
BENCHMARK_OPTS := -cpu 1,2,3,4,5,6,7,8 -benchmem
# sonar report output folder
REPORT_FOLDER := sonar
# sonar report file list
TEST_REPORT := ${REPORT_FOLDER}/test.report
COVER_REPORT := ${REPORT_FOLDER}/cover.report
GOLANGCI_LINT_REPORT := ${REPORT_FOLDER}/golangci-lint.xml
GOLINT_REPORT := ${REPORT_FOLDER}/golint.report
GO_VET_REPORT := ${REPORT_FOLDER}/go_vet.report
SONAR_SERVICE=http://xxx.xxx.xxx.xxx:9000
SONAR_TOKEN=
.PHONY: format test benchmark sonar clean
.DEFAULT_GOAL := test
# format go code
format:
@for f in ${GOFILES} ; do \
gofmt -w $${f}; \
done
# unit test
test:
${TEST_ENV} go test ${TEST_OPTS} ./...
# benchmark test
benchmark:
${BENCHMARK_ENV} go test -bench . -run ^$$ ${BENCHMARK_OPTS} ./...
# sonar
sonar:
mkdir -p ${REPORT_FOLDER}
go test -json ./... > ${TEST_REPORT}
go test -coverprofile=${COVER_REPORT} ./...
golangci-lint run --out-format checkstyle --issues-exit-code 0 ./... > ${GOLANGCI_LINT_REPORT}
# golint ./... > ${GOLINT_REPORT}
go vet ./... > ${GO_VET_REPORT} 2>&1
# sonar-scanner -Dsonar.projectKey=${PROJECT_NAME} \
-Dsonar.sources=. \
-Dsonar.host.url=${SONAR_SERVICE} \
# -Dsonar.token=${SONAR_TOKEN} \
-Dsonar.login=${SONAR_TOKEN} \
-Dproject.settings=target/sonar-project.properties
# clean target executable program and sonar report
clean:
-rm -f ${TEST_REPORT}
-rm -f ${COVER_REPORT}
-rm -f ${GOLANGCI_LINT_REPORT}
-rm -f ${GOLINT_REPORT}
-rm -f ${GO_VET_REPORT}
-go clean
-go clean -cache