-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (52 loc) · 1.96 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
export VERSION ?= $(shell git describe 2>/dev/null | sed -e 's/^v//g' || echo "dev")
export REVISION ?= $(shell git rev-parse --short HEAD || echo "unknown")
export BRANCH ?= $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
export BUILT ?= $(shell date +%Y-%m-%dT%H:%M:%S%:z)
PROJECT_PACKAGES ?= $(shell go list ./... | grep -v vendor)
VERSION_PACKAGE ?= $(shell go list ./version)
export CGO_ENABLED := 0
GO_LDFLAGS := -X $(VERSION_PACKAGE).VERSION=$(VERSION) \
-X $(VERSION_PACKAGE).REVISION=$(REVISION) \
-X $(VERSION_PACKAGE).BRANCH=$(BRANCH) \
-X $(VERSION_PACKAGE).BUILT=$(BUILT) \
-s -w
version: FORCE
@echo Current version: $(VERSION)
@echo Current revision: $(REVISION)
@echo Current branch: $(BRANCH)
static_code_analysis: fmt vet lint complexity
deps:
# Installing required dependencies
@go get github.com/golang/dep/cmd/dep
@go get github.com/golang/lint/golint
@go get golang.org/x/tools/cmd/cover
@go get github.com/fzipp/gocyclo
@go install cmd/vet
@dep ensure
fmt:
# Checking project code formatting...
@go fmt $(PROJECT_PACKAGES) | awk '{if (NF > 0) {if (NR == 1) print "Please run go fmt for:"; print "- "$$1}} END {if (NF > 0) {if (NR > 0) exit 1}}'
vet:
# Checking for suspicious constructs...
@go vet $(PROJECT_PACKAGES)
lint:
# Checking project code style...
@golint $(PROJECT_PACKAGES) | ( ! grep -v -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" )
complexity:
# Checking code complexity
@gocyclo -over 5 $(shell find . -name '*.go' | grep -v -e "/vendor/")
test:
# Running unit tests
@go test $(PROJECT_PACKAGES)
compile:
# Compile binary
@go build -ldflags "$(GO_LDFLAGS)"
# Test run
@./hanging-droplets-cleaner --version
release_image:
# Release image
@./scripts/release_image
release_ci_image:
# Release CI image
@./scripts/release_ci_image
FORCE: