-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
103 lines (84 loc) · 2.62 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
NAME=etcd-discovery
AUTHOR=gambol99
HARDWARE=$(shell uname -m)
GOVERSION=1.6.0
GIT_COMMIT=$(shell git log --pretty=format:'%h' -n 1)
ROOT_DIR=${PWD}
VERSION=$(shell awk '/version.*=/ { print $$3 }' doc.go | sed 's/"//g')
DEPS=$(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
PACKAGES=$(shell go list ./...)
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr
.PHONY: test authors changelog build docker static release lint cover vet
default: build
golang:
@echo "--> Go Version"
@go version
build:
@echo "--> Compiling the project"
mkdir -p bin
go build -o bin/${NAME}
static: golang deps
@echo "--> Compiling the static binary"
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' -o bin/${NAME}
docker-build:
@echo "--> Compiling the project"
sudo docker run --rm -v ${ROOT_DIR}:/go/src/github.com/gambol99/etcd-discovery \
-w /go/src/github.com/gambol99/etcd-discovery -e GOOS=linux golang:${GOVERSION} make static
docker: static
@echo "--> Building the docker image"
sudo docker build -t docker.io/${AUTHOR}/${NAME}:${VERSION} .
release: static
@echo "--> Building a release for version ${VERSION}"
mkdir -p release
gzip -c bin/${NAME} > release/${NAME}_${VERSION}_linux_${HARDWARE}.gz
rm -f release/${NAME}
clean:
@echo "--> Performing a cleanup"
rm -rf ./bin 2>/dev/null
rm -rf ./release 2>/dev/null
authors:
@echo "--> Updating the AUTHORS"
git log --format='%aN <%aE>' | sort -u > AUTHORS
deps:
@echo "--> Installing build dependencies"
@go get github.com/tools/godep
vet:
@echo "--> Running go vet $(VETARGS) ."
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
go get golang.org/x/tools/cmd/vet; \
fi
@go tool vet $(VETARGS) *.go
lint:
@echo "--> Running golint"
@which golint 2>/dev/null ; if [ $$? -eq 1 ]; then \
go get -u github.com/golang/lint/golint; \
fi
@golint .
gofmt:
@echo "--> Running gofmt check"
@gofmt -s -l *.go \
| grep -q \.go ; if [ $$? -eq 0 ]; then \
echo "You need to runn the make format, we have file unformatted"; \
gofmt -s -l *.go; \
exit 1; \
fi
format:
@echo "--> Running go fmt"
@gofmt -s -w *.go
coverage:
@echo "--> Running go coverage"
@godep go test -coverprofile cover.out
@godep go tool cover -html=cover.out -o cover.html
cover:
@echo "--> Running go cover"
@godep go test --cover
test: deps
@echo "--> Running the tests"
@go test -v
@$(MAKE) gofmt
@$(MAKE) vet
@$(MAKE) cover
changelog: release
@echo "--> Creating a changelog"
git log $(shell git tag | tail -n1)..HEAD --no-merges --format=%B > changelog