forked from yunify/qingcloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (145 loc) · 5.45 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
SHELL := /bin/bash
.PHONY: all check vet lint update generate build unit test release clean
PREFIX=qingcloud-sdk-go
VERSION=$(shell cat version.go | grep "Version\ =" | sed -e s/^.*\ //g | sed -e s/\"//g)
DIRS_TO_CHECK=$(shell ls -d */ | grep -vE "vendor|test")
PKGS_TO_CHECK=$(shell go list ./... | grep -vE "vendor|test")
PKGS_TO_RELEASE=$(shell go list ./... | grep -vE "/vendor/|/test")
FILES_TO_RELEASE=$(shell find . -name "*.go" | grep -vE "/vendor/|/test|.*_test.go")
FILES_TO_RELEASE_WITH_VENDOR=$(shell find . -name "*.go" | grep -vE "/test|.*_test.go")
LINT_IGNORE_DOC="service\/.*\.go:.+(comment on exported|should have comment or be unexported)"
LINT_IGNORE_CONFLICT="service\/.*\.go:.+(type name will be used as)"
help:
@echo "Please use \`make <target>\` where <target> is one of"
@echo " all to check, build, test and release this SDK"
@echo " check to vet and lint the SDK"
@echo " generate to generate service code"
@echo " build to build the SDK"
@echo " unit to run all sort of unit tests except runtime"
@echo " unit-test to run unit test"
@echo " unit-benchmark to run unit test with benchmark"
@echo " unit-coverage to run unit test with coverage"
@echo " unit-race to run unit test with race"
@echo " unit-runtime to run test with go1.5, go1.6, go 1.7 in docker"
@echo " test to run service test"
@echo " release to build and release current version"
@echo " release-source to pack the source code"
@echo " clean to clean the coverage files"
all: check build unit release
check: vet lint
vet:
@echo "go tool vet, skipping vendor packages"
@go tool vet -all ${DIRS_TO_CHECK}
@echo "ok"
lint:
@echo "golint, skipping vendor packages"
@lint=$$(for pkg in ${PKGS_TO_CHECK}; do golint $${pkg}; done); \
lint=$$(echo "$${lint}" | grep -vE -e ${LINT_IGNORE_DOC} -e ${LINT_IGNORE_CONFLICT}); \
if [[ -n $${lint} ]]; then echo "$${lint}"; exit 1; fi
@echo "ok"
generate: snips ../qingcloud-api-specs/package.json
./snips \
-f=../qingcloud-api-specs/2013-08-30/swagger/api_v2.0.json \
-t=./template \
-o=./service
go fmt ./service/...
@echo "ok"
snips:
curl -L https://github.com/yunify/snips/releases/download/v0.2.16/snips-v0.2.16-${shell go env GOOS}_amd64.tar.gz | tar zx
../qingcloud-api-specs/package.json:
-go get -d github.com/yunify/qingcloud-api-specs
file %@
build:
@echo "build the SDK"
GOOS=linux GOARCH=amd64 go build ${PKGS_TO_CHECK}
GOOS=darwin GOARCH=amd64 go build ${PKGS_TO_CHECK}
GOOS=windows GOARCH=amd64 go build ${PKGS_TO_CHECK}
@echo "ok"
unit: unit-test unit-benchmark unit-coverage unit-race
unit-test:
@echo "run unit test"
go test -v ${PKGS_TO_CHECK}
@echo "ok"
unit-benchmark:
@echo "run unit test with benchmark"
go test -v -bench=. ${PKGS_TO_CHECK}
@echo "ok"
unit-coverage:
@echo "run unit test with coverage"
for pkg in ${PKGS_TO_CHECK}; do \
output="coverage$${pkg#github.com/yunify/qingcloud-sdk-go}"; \
mkdir -p $${output}; \
go test -v -cover -coverprofile="$${output}/profile.out" $${pkg}; \
if [[ -e "$${output}/profile.out" ]]; then \
go tool cover -html="$${output}/profile.out" -o "$${output}/profile.html"; \
fi; \
done
@echo "ok"
unit-race:
@echo "run unit test with race"
go test -v -race -cpu=1,2,4 ${PKGS_TO_CHECK}
@echo "ok"
unit-runtime: unit-runtime-go-1.5 unit-runtime-go-1.6 unit-runtime-go-1.7
export define DOCKERFILE_GO_1_7
FROM golang:1.7
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
CMD ["make", "build", "unit"]
endef
unit-runtime-go-1.7:
@echo "run test in go 1.7"
echo "$${DOCKERFILE_GO_1_7}" > "dockerfile_go_1.7"
docker build -f "./dockerfile_go_1.7" -t "${PREFIX}:go-1.7" .
rm -f "./dockerfile_go_1.7"
docker run --name "${PREFIX}-go-1.7-unit" -t "${PREFIX}:go-1.7"
docker rm "${PREFIX}-go-1.7-unit"
docker rmi "${PREFIX}:go-1.7"
@echo "ok"
export define DOCKERFILE_GO_1_6
FROM golang:1.6
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
CMD ["make", "build", "unit"]
endef
unit-runtime-go-1.6:
@echo "run test in go 1.6"
echo "$${DOCKERFILE_GO_1_6}" > "dockerfile_go_1.6"
docker build -f "./dockerfile_go_1.6" -t "${PREFIX}:go-1.6" .
rm -f "./dockerfile_go_1.6"
docker run --name "${PREFIX}-go-1.6-unit" -t "${PREFIX}:go-1.6"
docker rm "${PREFIX}-go-1.6-unit"
docker rmi "${PREFIX}:go-1.6"
@echo "ok"
export define DOCKERFILE_GO_1_5
FROM golang:1.5
ENV GO15VENDOREXPERIMENT="1"
ADD . /go/src/github.com/yunify/qingcloud-sdk-go
WORKDIR /go/src/github.com/yunify/qingcloud-sdk-go
CMD ["make", "build", "unit"]
endef
unit-runtime-go-1.5:
@echo "run test in go 1.5"
echo "$${DOCKERFILE_GO_1_5}" > "dockerfile_go_1.5"
docker build -f "./dockerfile_go_1.5" -t "${PREFIX}:go-1.5" .
rm -f "./dockerfile_go_1.5"
docker run --name "${PREFIX}-go-1.5-unit" -t "${PREFIX}:go-1.5"
docker rm "${PREFIX}-go-1.5-unit"
docker rmi "${PREFIX}:go-1.5"
@echo "ok"
test:
pushd "./test"; go test ; popd
@echo "ok"
release: release-source release-source-with-vendor
release-source:
@echo "pack the source code"
mkdir -p "release"
@zip -FS "release/${PREFIX}-source-v${VERSION}.zip" ${FILES_TO_RELEASE}
@echo "ok"
release-source-with-vendor:
@echo "pack the source code"
mkdir -p "release"
@zip -FS "release/${PREFIX}-source-with-vendor-v${VERSION}.zip" ${FILES_TO_RELEASE_WITH_VENDOR}
@echo "ok"
clean:
rm -rf $${PWD}/coverage
@echo "ok"