forked from Azure/azure-event-hubs-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
95 lines (76 loc) · 3.18 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
PACKAGE = github.com/Azure/azure-event-hubs-go
DATE ?= $(shell date +%FT%T%z)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat $(CURDIR)/.version 2> /dev/null || echo v0)
BIN = $(GOPATH)/bin
GO_FILES = find . -iname '*.go' -type f | grep -v /vendor/
GO = go
GODOC = godoc
GOFMT = gofmt
GOCYCLO = gocyclo
GOLINT = $(BIN)/golangci-lint
GOSTATICCHECK = $(BIN)/staticcheck
GOJUNITRPT = go-junit-report
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m▶\033[0m")
TIMEOUT = 720
.PHONY: all
all: fmt lint vet tidy build
.PHONY: build
build: | ; $(info $(M) building library…) @ ## Build program
$Q $(GO) build all
# Tests
TEST_TARGETS := test-default test-bench test-verbose test-race test-debug test-cover test-full
.PHONY: $(TEST_TARGETS) test-xml check test tests
test-bench: ARGS=-run=__absolutelynothing__ -bench=. ## Run benchmarks
test-verbose: ARGS=-v ## Run tests in verbose mode
test-debug: ARGS=-v -debug ## Run tests in verbose mode with debug output
test-race: ARGS=-race ## Run tests with race detector
test-cover: ARGS=-cover -coverprofile=cover.out -v ## Run tests in verbose mode with coverage
test-full: ARGS=-cover -coverprofile=cover.out -v -race ## Run tests with code coverage and race detection
$(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%)
$(TEST_TARGETS): test
check test tests: cyclo lint vet terraform.tfstate; $(info $(M) running $(NAME:%=% )tests…) @ ## Run tests
$(GO) test -timeout $(TIMEOUT)s $(ARGS) ./... 2>&1 | tee gotestoutput.log && \
$(GOJUNITRPT) < gotestoutput.log > report.xml && \
rm -f gotestoutput.log
.PHONY: vet
vet: ; $(info $(M) running vet…) @ ## Run vet
$Q $(GO) vet ./...
.PHONY: tidy
tidy: ; $(info $(M) running go mod tidy…) @ ## Run tidy
$Q $(GO) mod tidy
.PHONY: lint
lint: ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint
$Q $(GOLINT) run
.PHONY: staticcheck
staticcheck: ; $(info $(M) running staticcheck…) @ ## Run staticcheck
$Q $(GOSTATICCHECK) ./...
.PHONY: fmt
fmt: ; $(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: cyclo
cyclo: ; $(info $(M) running gocyclo...) @ ## Run gocyclo on all source files
$Q $(GOCYCLO) -over 19 $$($(GO_FILES))
terraform.tfstate: azuredeploy.tf $(wildcard terraform.tfvars) .terraform ; $(info $(M) running terraform...) @ ## Run terraform to provision infrastructure needed for testing
$Q TF_VAR_azure_client_secret="$${ARM_CLIENT_SECRET}" terraform apply -auto-approve
$Q terraform output -json | jq -r 'keys[] as $$k | "\($$k) = \(.[$$k].value)"' > .env
.terraform:
$Q terraform init
.Phony: destroy
destroy: ; $(info $(M) running terraform destroy...)
$(Q) terraform destroy --auto-approve
# Misc
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything
@rm -rf test/tests.* test/coverage.*
.PHONY: help
help:
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.PHONY: version
version:
@echo $(VERSION)