-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (55 loc) · 2.33 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
# Setup name variables for the package/tool.
NAME := stacktrace
PKG := github.com/rdeusser/$(NAME)
GIT_COMMIT := $(PKG)/version
VERSION := $(shell grep -oE "[0-9]+[.][0-9]+[.][0-9]+" version/version.go)
SEMVER := patch
OLDPWD := $(PWD)
export OLDPWD
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)
# Set ldflags.
LDFLAGS ?= -ldflags "-w -X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE)"
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO111MODULE ?= on
export GO111MODULE
GOIMPORTS_VERSION ?= master
GOIMPORTS ?= $(GOBIN)/goimports
GOLANGCILINT_VERSION ?= v1.32.0
GOLANGCILINT ?= $(GOBIN)/golangci-lint
.DEFAULT_GOAL := help
define fetch_go_bin_version
@cd /tmp
@go get $(1)@$(2)
@cd -
endef
.PHONY: help
help: ## Display this help text.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nAvailable targets:\n"} /^[\/0-9a-zA-Z_-]+:.*?##/ { printf " \x1b[32;01m%-20s\x1b[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
.PHONY: fmt
fmt: $(GOIMPORTS) ## Formats Go code including imports and cleans up noise.
@echo ">> formatting code"
@$(GOIMPORTS) -local $(PKG) -w $(FILES_TO_FMT)
@echo ">> cleaning up noise"
@find . -type f \( -name "*.md" -o -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-noise.sh
.PHONY: lint
lint: $(GOLANGCILINT) ## Run various static analysis tools against our code.
@echo ">> linting all of the Go files"
@$(GOLANGCILINT) run
.PHONY: test
test: ## Runs all unit tests.
@echo ">> running unit tests (without /test/e2e)"
@go test -timeout=30s -race -coverprofile=coverage.out $(shell go list ./... | grep -v /test/e2e);
.PHONY: update-testdata
update-testdata: ## Updates all files in testdata directories.
@echo ">> updating files in testdata directories"
@go run tools/update-testdata/main.go
.PHONY: bump-version
bump-version: ## Bump the version in the version file. Set SEMVER to [ patch (default) | major | minor ].
@./scripts/bump-version.sh $(SEMVER)
.PHONY: tag
tag: ## Create and push a new git tag (creates tag using version/version.go file).
@./scripts/tag.sh
$(GOIMPORTS):
$(call fetch_go_bin_version,golang.org/x/tools/cmd/goimports,$(GOIMPORTS_VERSION))
$(GOLANGCILINT):
$(call fetch_go_bin_version,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCILINT_VERSION))