-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
101 lines (88 loc) · 2.86 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
SHELL := /bin/bash
VERSION=$(shell cat constants/version.go | grep "Version\ =" | sed -e s/^.*\ //g | sed -e s/\"//g)
DIRS_WITHOUT_VENDOR=$(shell ls -d */ | grep -vE "vendor")
PKGS_WITHOUT_VENDOR=$(shell go list ./... | grep -v "/vendor/")
.PHONY: help
help:
@echo "Please use \`make <target>\` where <target> is one of"
@echo " all to check, build, test and release snips"
@echo " check to vet and lint snips"
@echo " build to create bin directory and build snips"
@echo " test to run test"
@echo " test-coverage to test with coverage"
@echo " install to install snips to ${GOPATH}/bin"
@echo " uninstall to uninstall snips"
@echo " release to build and release snips"
@echo " clean to clean build and test files"
.PHONY: all
all: check build release clean unit-test unit-coverage
.PHONY: check
check: vet lint
.PHONY: vet
vet:
@echo "Running go tool vet, on snips packages"
@go tool vet -all ${DIRS_WITHOUT_VENDOR}
@echo "Done"
.PHONY: lint
lint:
@echo "Running golint, on snips packages"
@lint=$$(for pkg in ${PKGS_WITHOUT_VENDOR}; do golint $${pkg}; done); \
if [[ -n $${lint} ]]; then echo "$${lint}"; exit 1; fi
@echo "Done"
.PHONY: build
build:
@echo "Building snips"
mkdir -p ./bin
go build -o ./bin/snips .
@echo "Done"
.PHONY: test
test:
@echo "Running test"
go test -v ${PKGS_WITHOUT_VENDOR}
@echo "Done"
.PHONY: test-coverage
test-coverage:
@echo "Running test with coverage"
for pkg in ${PKGS_WITHOUT_VENDOR}; do \
output="coverage$${pkg#github.com/yunify/snips}"; \
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: install
install: build
@if [[ -z "${GOPATH}" ]]; then echo "ERROR: $GOPATH not found."; exit 1; fi
@echo "Installing into ${GOPATH}/bin/snips..."
@cp ./bin/snips ${GOPATH}/bin/snips
@echo "Done"
.PHONY: uninstall
uninstall:
@if [[ -z "${GOPATH}" ]]; then echo "ERROR: $GOPATH not found."; exit 1; fi
@echo "Uninstalling snips..."
rm -f ${GOPATH}/bin/snips
@echo "Done"
.PHONY: release
release:
@echo "Release snips"
mkdir -p ./release
@echo "for Linux"
GOOS=linux GOARCH=amd64 go build -o ./bin/linux/snips .
mkdir -p ./release
tar -C ./bin/linux/ -czf ./release/snips-v${VERSION}-linux_amd64.tar.gz snips
@echo "for macOS"
mkdir -p ./bin/linux
GOOS=darwin GOARCH=amd64 go build -o ./bin/darwin/snips .
tar -C ./bin/darwin/ -czf ./release/snips-v${VERSION}-darwin_amd64.tar.gz snips
@echo "for Windows"
mkdir -p ./bin/windows
GOOS=windows GOARCH=amd64 go build -o ./bin/windows/snips.exe .
cd ./bin/windows/ && zip ../../release/snips-v${VERSION}-windows_amd64.zip snips.exe
@echo "Done"
.PHONY: clean
clean:
rm -rf ./bin
rm -rf ./release
rm -rf ./coverage