-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
93 lines (75 loc) · 3.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
90
91
92
93
NAME ?= vmotion4bosh
OUTPUT = ./bin/$(NAME)
GO_SOURCES = $(shell find . -type f -name '*.go')
GOBIN ?= $(shell go env GOPATH)/bin
VERSION ?= 0.0.0
GITSHA = $(shell git rev-parse HEAD)
GITDIRTY = $(shell git diff --quiet HEAD || echo "dirty")
GOLANGCI_LINT_VERSION := $(shell golangci-lint --version 2>/dev/null)
LDFLAGS_VERSION = -X github.com/vmware-tanzu/vmotion-migration-tool-for-bosh-deployments/command.VERSION=$(VERSION) \
-X github.com/vmware-tanzu/vmotion-migration-tool-for-bosh-deployments/command.COMMIT=$(GITSHA)
.PHONY: all
all: build lint test ## Runs build, lint and test
.PHONY: clean
clean: ## Clean testcache and delete build output
go clean -testcache
@rm -rf bin/
@rm -rf dist/
@rm -f coverage.html
$(OUTPUT): $(GO_SOURCES)
@echo "Building $(VERSION)"
go build -o $(OUTPUT) -ldflags "$(LDFLAGS_VERSION)" ./cmd/$(NAME)
.PHONY: build
build: $(OUTPUT) ## Build the main binary
.PHONY: test
test: ## Run the unit tests
go test -short ./...
test-bench: ## Run all the benchmark tests
go test -bench=. -benchmem ./...
test-all: test test-bench ## Run all of the tests
.PHONY: install
install: build ## Copy build to GOPATH/bin
@cp $(OUTPUT) $(GOBIN)
@echo "[OK] CLI binary installed under $(GOBIN)"
.PHONY: coverage
coverage: ## Run the tests with coverage and race detection
go test -v --race -coverprofile=c.out -covermode=atomic ./...
.PHONY: report
report: ## Show coverage in an html report
go tool cover -html=c.out -o coverage.html
.PHONY: generate
generate: ## Generate fakes
go generate ./...
.PHONY: clean-docs
clean-docs: ## Delete the generated docs
mkdir -p docs/
rm -f docs/*.md
.PHONY: docs
docs: clean-docs ## Generate documentation
go run cmd/generate_docs/main.go
.PHONY: release
release: $(GO_SOURCES) ## Cross-compile binary for various operating systems
@rm -rf dist
@mkdir -p dist
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-w $(LDFLAGS_VERSION)" -o $(OUTPUT) ./cmd/$(NAME) && tar -czf dist/$(NAME)-darwin-amd64.tgz -C bin $(NAME) && rm -f $(OUTPUT)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-w $(LDFLAGS_VERSION)" -o $(OUTPUT) ./cmd/$(NAME) && tar -czf dist/$(NAME)-linux-amd64.tgz -C bin $(NAME) && rm -f $(OUTPUT)
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS_VERSION)" -o $(OUTPUT).exe ./cmd/$(NAME) && zip -j dist/$(NAME)-windows-amd64.zip $(OUTPUT).exe && rm -f $(OUTPUT).exe
.PHONY: lint
lint: ## Validate style and syntax
ifdef GOLANGCI_LINT_VERSION
golangci-lint run
else
@echo "Installing latest golangci-lint"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
@echo "[OK] golangci-lint installed"
./bin/golangci-lint run
endif
.PHONY: tidy
tidy: ## Remove unused dependencies
go mod tidy
.PHONY: list
list: ## Print the current module's dependencies.
go list -m all
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Print help for each make target
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'