-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (49 loc) · 2.35 KB
/
Copy pathMakefile
File metadata and controls
63 lines (49 loc) · 2.35 KB
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
# The name of the executable (default is current directory name)
BINARY := ico-analyzer
ARTIFACTS_DIR := artifacts
ASSETS_DIR = assets
VERSION ?= vlatest
COMMIT := $(shell git rev-parse HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
BUILD_TIME := $(shell TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ')
M = $(shell printf "\033[32;1m▶▶▶▶▶\033[0m")
GO_LDFLAGS := "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitHash=$(COMMIT) -X main.Branch=$(BRANCH)"
TOOLS = golang.org/x/tools/cmd/goimports \
github.com/Masterminds/glide \
golang.org/x/lint/golint \
honnef.co/go/tools/cmd/staticcheck \
honnef.co/go/tools/cmd/unused
.PHONY: all
all: clean test ; $(info $(M) building executable…) @ ## Build program binary
mkdir -p $(ARTIFACTS_DIR)
go build --ldflags=$(GO_LDFLAGS) -o $(ARTIFACTS_DIR)/$(BINARY)
echo export VERSION=$(VERSION) > $(ARTIFACTS_DIR)/VERSION
.PHONY: test
test: vendor fmt-check vet unused static-check lint ; $(info $(M) running tests…)
go test -timeout 20s -race -v $$(glide novendor)
.PHONY: tools
tools: ; $(info $(M) building tools…)
go get -v $(TOOLS)
.PHONY: vendor
vendor: tools ; $(info $(M) retrieving dependencies…)
glide install
.PHONY: fmt-check
fmt-check: vendor tools ; $(info $(M) checking formattation…)
gofiles=$$(go list -f {{.Dir}} $$(glide novendor) | grep -v mock) && [ -z "$$gofiles" ] || unformatted=$$(for d in $$gofiles; do goimports -l $$d/*.go; done) && [ -z "$$unformatted" ] || (echo >&2 "Go files must be formatted with goimports. Following files has problem:\n$$unformatted" && false)
.PHONY: fmt
fmt: vendor tools ; $(info $(M) formatting the code…)
gofiles=$$(go list -f {{.Dir}} $$(glide novendor) | grep -v mock) && [ -z "$$gofiles" ] || for d in $$gofiles; do goimports -l -w $$d/*.go; done
.PHONY: vet
vet: vendor tools ; $(info $(M) checking correctness of the code…)
go vet $$(glide novendor)
.PHONY: unused
unused: vendor tools ; $(info $(M) checking Go code for unused constants, variables, functions and types…)
unused $$(glide novendor)
.PHONY: static-check
static-check: vendor tools ; $(info $(M) detecting bugs and inefficiencies in code…)
staticcheck $$(glide novendor)
.PHONY: lint
lint: vendor tools ; $(info $(M) running golint…)
for i in $$(go list ./... | grep -v /vendor/); do golint $$i; done
clean:
rm -rf $(ARTIFACTS_DIR)