forked from qingstor/qingstor-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
104 lines (89 loc) · 2.79 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
SHELL := /bin/bash
PREFIX=qingstor-sdk-go
VERSION=$(shell cat version.go | grep "Version\ =" | sed -e s/^.*\ //g | sed -e s/\"//g)
PKGS_TO_CHECK=$(shell go list ./... | grep -v "/vendor/")
PKGS_TO_RELEASE=$(shell go list ./... | grep -vE "/vendor/|/test")
FILES_TO_RELEASE=$(shell find . -name "*.go" | grep -vE "/vendor/|/test|.*_test.go")
.PHONY: help
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 " update to update git submodules"
@echo " generate to generate service code"
@echo " build to build the SDK"
@echo " test to run test"
@echo " test-coverage to run test with coverage"
@echo " test-race to run test with race"
@echo " integration-test to run integration test"
@echo " clean to clean the coverage files"
.PHONY: all
all: check build unit release
.PHONY: check
check: vet lint format
.PHONY: format
format:
@echo "go fmt, skipping vendor packages"
@for pkg in ${PKGS_TO_CHECK}; do go fmt $${pkg}; done;
@echo "ok"
.PHONY: vet
vet:
@echo "Go tool vet, skipping vendor packages"
@for pkg in ${PKGS_TO_RELEASE}; do go vet -all $${pkg}; done;
@echo "Done"
.PHONY: lint
lint:
@echo "Golint, skipping vendor packages"
@lint=$$(for pkg in ${PKGS_TO_CHECK}; do golint $${pkg}; done); \
lint=$$(echo "$${lint}"); \
if [[ -n $${lint} ]]; then echo "$${lint}"; exit 1; fi
@echo "Done"
.PHONY: update
update:
git submodule update --remote
@echo "Done"
.PHONY: generate
generate:
@if [[ ! -f "$$(which snips)" ]]; then \
echo "ERROR: Command \"snips\" not found."; \
fi
snips -f="./specs/qingstor/2016-01-06/swagger/api_v2.0.json" -t="./template" -o="./service"
snips -f="./specs/qingstor/2016-01-06/swagger/api_v2.0.json" -t="./interface" -o="./interface"
gofmt -w .
@echo "Done"
.PHONY: build
build: format
@echo "Build the SDK"
go build ${PKGS_TO_RELEASE}
@echo "Done"
.PHONY: test
test:
@echo "Run test"
go test -v ${PKGS_TO_RELEASE}
@echo "Done"
.PHONY: test-coverage
test-coverage:
@echo "Run test with coverage"
for pkg in ${PKGS_TO_RELEASE}; do \
output="coverage$${pkg#github.com/yunify/qingstor-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 "Done"
.PHONY: test-race
test-race:
@echo "Run test with race"
go test -v -race -cpu=1,2,4 ${PKGS_TO_RELEASE}
@echo "Done"
.PHONY: integration-test
integration-test:
@echo "Run integration test"
pushd "./test"; go test; popd
@echo "Done"
.PHONY: clean
clean:
rm -rf $${PWD}/coverage
@echo "Done"