-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
89 lines (73 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
# git options
GIT_COMMIT ?= $(shell git rev-parse HEAD)
GIT_TAG ?= $(shell git tag --points-at HEAD)
DIST_TYPE ?= snapshot
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
PROJECT_NAME := grafana-annotation
PKG_ORG := Contentsquare
PKG := grafana-annotation
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
BINARY_NAME := grafana-annotation
M = $(shell printf "\033[34;1m▶\033[0m")
GO := go
GOFMT := gofmt
OS := $(shell uname -s)
GOOS ?= $(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
GOARCH ?= amd64
BUILD_CONSTS = -X main.buildRevision=$(GIT_COMMIT) -X main.buildTag=$(GIT_TAG)
BUILD_OPTS = -ldflags="$(BUILD_CONSTS)" -gcflags="-trimpath=$(GOPATH)/src"
tidy:
$(info ===== $@ =====)
GO111MODULE=on go mod tidy
deps:
$(info ===== $@ =====)
GO111MODULE=on go mod vendor
format:
$(info ===== $@ =====)
$(GOFMT) -w -s $(GO_FILES)
build:
$(info ===== $@ =====)
GO111MODULE=on GOOS=$(GOOS) $(GO) build -tags static -o $(BINARY_NAME) $(BUILD_OPTS)
test:
$(info ===== $@ =====)
$(GO) test -v -race -cover -coverprofile=coverage.out ./...
fmt:
$(info ===== gofmt =====)
$(GOFMT) -d -e -s $(GO_FILES)
#lint:
# $(info ===== $@ =====)
# $(GO) vet $(PKG_LIST)
# $(GO) list ./... | grep -Ev /vendor/ | sed -e 's/${PROJECT_NAME}/./' | xargs -L1 golint -set_exit_status
#
lint:
$(info ===== $@ =====)
golangci-lint run . -v
tarball: version
$(info ===== $@ =====)
ifneq ($(GIT_TAG),)
tar czf $(BINARY_NAME)-$(GOOS)-$(GOARCH)-$(GIT_TAG).tar.gz $(BINARY_NAME)
else
tar czf $(BINARY_NAME)-$(GOOS)-$(GOARCH)-$(VERSION_FILE).tar.gz $(BINARY_NAME)
endif
version:
$(info ===== $@ =====)
ifneq ($(GIT_TAG),)
$(eval VERSION := $(GIT_TAG))
$(eval VERSION_FILE := $(GIT_TAG))
else
$(eval VERSION := $(subst /,-,$(BRANCH)))
$(eval VERSION_FILE := $(GIT_COMMIT)-SNAPSHOT)
endif
@test -n "$(VERSION)"
$(info Building $(VERSION)/$(VERSION_FILE) on sha1 $(GIT_COMMIT))
get_version: version
$(info $(VERSION_FILE))
.PHONY: tidy \
deps \
format \
build \
test \
fmt \
lint \
tarball