-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (76 loc) · 3.26 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
APPNAME = gobana-agent
PACKAGE = github.com/thomasglachant/gobana-agent
DATE ?= $(shell date +%FT%T%z)
COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat $(CURDIR)/.version 2> /dev/null || echo v0)
BIN = $(CURDIR)/bin
GOPATH = $(CURDIR)/.gopath~
BASE = $(CURDIR)
NEXT_VERSION_MINOR=$(shell bin/semver.sh "minor")
NEXT_VERSION_MAJOR=$(shell bin/semver.sh "major")
NEXT_VERSION_PATCH=$(shell bin/semver.sh "patch")
GO = GO111MODULE=on go
GOFMT = $(shell go env GOPATH)/bin/gofumpt
GOLINT = $(shell go env GOPATH)/bin/golangci-lint
TIMEOUT = 15
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m▶\033[0m")
Y = $(shell printf "\033[33;1m▶\033[0m")
.DEFAULT_GOAL := help
.PHONY: build
build: $(BASE) ; $(info $(M) building executable…) @ ## Build program binary (without checking lint and format)
$Q cd $(BASE) && $(GO) build \
-tags release \
-ldflags "-X main.version=$(VERSION) -X main.date=$(DATE) -X main.commit=$(COMMIT)" \
-o $(BIN)/$(APPNAME) main.go
.PHONY: start
start: build $(BASE) ; $(info $(M) launch agent…) @ ## Launch application
@$(BIN)/$(APPNAME) $(RUN_ARGS) $(if $(config), -config=$(config), "")
$(GOLINT): | $(BASE) ; $(info $(M) building lint…)
$Q GOPATH=$(shell go env GOPATH) go install github.com/golangci/golangci-lint/cmd/[email protected]
.PHONY: lint
lint: $(BASE) fmt $(GOLINT) ; $(info $(M) apply linter…) @ ## Run lint
$Q cd $(BASE) && $(GOLINT) run --color auto --fix
$(GOFMT): | $(BASE) ; $(info $(M) building fmt…)
$Q GOPATH=$(shell go env GOPATH) go install mvdan.cc/[email protected]
.PHONY: fmt
fmt: $(BASE) $(GOFMT) ; $(info $(M) running gofmt…) @ ## Run gofmt on all source files
@ret=0 && for d in $$($(GO) list -f '{{.Dir}}' ./... | grep -v /vendor/); do \
$(GOFMT) -l -w $$d/*.go || ret=$$? ; \
done ; exit $$ret
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything
@rm -rf $(GOPATH)
@find bin ! -name '.gitkeep' -type f -exec rm -f {} +
@rm -rf test/tests.* test/coverage.*
.PHONY: upgrade-dependencies
upgrade-dependencies: ; $(info $(M) upgrading dependencies…)
$Q GOPATH=$(shell go env GOPATH) go get -u
$Q GOPATH=$(shell go env GOPATH) go mod tidy
##
## test
.PHONY: test
test: fmt lint build test-unit ## Run tests
.PHONY: test-unit
test-unit: ; $(info $(M) run unit tests…) ## Run tests
$(GO) test -v ./...
##
## repository management
.PHONY: tag-version-minor
tag-version-minor: ; $(info $(M) Tag version…) @
@read -p "Create tag $(NEXT_VERSION_MINOR)? [y/N] " ans && [ $${ans:-N} == y ]
$Q git tag $(NEXT_VERSION_MINOR) && git push origin $(NEXT_VERSION_MINOR)
.PHONY: tag-version-major
tag-version-major: ; $(info $(M) Tag version…) @
@read -p "Create tag $(NEXT_VERSION_MAJOR)? [y/N] " ans && [ $${ans:-N} == y ]
$Q git tag $(NEXT_VERSION_MAJOR) && git push origin $(NEXT_VERSION_MAJOR)
.PHONY: tag-version-patch
tag-version-patch: ; $(info $(M) Tag version…) @
@read -p "Create tag $(NEXT_VERSION_PATCH)? [y/N] " ans && [ $${ans:-N} == y ]
$Q git tag $(NEXT_VERSION_PATCH) && git push origin $(NEXT_VERSION_PATCH)
.PHONY: help
help:
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'