-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
100 lines (81 loc) · 2.11 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
PROJECT_NAME := prometheus-cachethq
PKG := github.com/oxyno-zeta/$(PROJECT_NAME)
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
# go option
GO ?= go
TAGS :=
TESTS := .
TESTFLAGS :=
LDFLAGS := -w -s
GOFLAGS := -i
BINDIR := $(CURDIR)/bin
DISTDIR := dist
# Required for globs to work correctly
SHELL=/usr/bin/env bash
# Version
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
DATE = $(shell date +%F_%T%Z)
BINARY_VERSION = ${GIT_SHA}
LDFLAGS += -X ${PKG}/pkg/version.Version=${BINARY_VERSION}
LDFLAGS += -X ${PKG}/pkg/version.GitCommit=${GIT_COMMIT}
LDFLAGS += -X ${PKG}/pkg/version.BuildDate=${DATE}
HAS_GORELEASER := $(shell command -v goreleaser;)
#############
# Build #
#############
.PHONY: all
all: lint test build
.PHONY: lint
lint: dep
golint -set_exit_status ${PKG_LIST}
.PHONY: build
build: clean dep
GOBIN=$(BINDIR) colorgo install $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' $(PKG)/cmd/${PROJECT_NAME}
.PHONY: build-cross
build-cross: clean dep
ifdef HAS_GORELEASER
goreleaser --snapshot --skip-publish
endif
ifndef HAS_GORELEASER
curl -sL https://git.io/goreleaser | bash -s -- --snapshot --skip-publish
endif
.PHONY: release
release: clean dep
ifdef HAS_GORELEASER
goreleaser
endif
ifndef HAS_GORELEASER
curl -sL https://git.io/goreleaser | bash
endif
test: dep ## Run unittests
$(GO) test -short -cover -coverprofile=c.out ${PKG_LIST}
.PHONY: coverage-report
coverage-report:
$(GO) tool cover -html=c.out -o coverage.html
.PHONY: clean
clean:
@rm -rf $(BINDIR) $(DISTDIR)
.PHONY: update-dep
update-dep:
go get -u ./...
#############
# Bootstrap #
#############
HAS_GIT := $(shell command -v git;)
HAS_GOLINT := $(shell command -v golint;)
HAS_COLORGO := $(shell command -v colorgo;)
.PHONY: dep
dep:
ifndef HAS_GOLINT
GO111MODULE=off go get -u golang.org/x/lint/golint
endif
ifndef HAS_COLORGO
GO111MODULE=off go get -u github.com/songgao/colorgo
endif
ifndef HAS_GIT
$(error You must install Git)
endif
go mod download
go mod tidy