forked from iter8-tools/iter8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (66 loc) · 2.05 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
BINDIR := $(CURDIR)/bin
INSTALL_PATH ?= /usr/local/bin
BINNAME ?= iter8
GOBIN = $(shell go env GOBIN)
ifeq ($(GOBIN),)
GOBIN = $(shell go env GOPATH)/bin
endif
# go options
TAGS :=
LDFLAGS := -w -s
GOFLAGS :=
# Rebuild the binary if any of these files change
SRC := $(shell find . -type f -name '*.(go|proto|tpl)' -print) go.mod go.sum
# Required for globs to work correctly
SHELL = /usr/bin/env bash
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_TAG = $(shell git describe --tags --dirty)
ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
BINARY_VERSION ?= ${GIT_TAG}
# Only set Version if GIT_TAG or VERSION is set
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/iter8-tools/iter8/base.Version=${BINARY_VERSION}
endif
LDFLAGS += -X github.com/iter8-tools/iter8/cmd.gitCommit=${GIT_COMMIT}
.PHONY: all
all: build
# ------------------------------------------------------------------------------
# build
.PHONY: build
build: $(BINDIR)/$(BINNAME)
$(BINDIR)/$(BINNAME): $(SRC)
GO111MODULE=on go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./
# ------------------------------------------------------------------------------
# install
.PHONY: install
install: build
@install "$(BINDIR)/$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)"
# ------------------------------------------------------------------------------
# dependencies
.PHONY: clean
clean:
@rm -rf '$(BINDIR)'
# ------------------------------------------------------------------------------
# test
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code
go vet ./...
.PHONY: golangci-lint
golangci-lint:
golangci-lint run ./...
.PHONY: lint
lint: vet golangci-lint
.PHONY: test
test: fmt vet ## Run tests.
go test -v ./... -coverprofile=coverage.out
.PHONY: coverage
coverage: test
@echo "test coverage: $(shell go tool cover -func coverage.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}')"
.PHONY: htmlcov
htmlcov: coverage
go tool cover -html=coverage.out