-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
57 lines (46 loc) · 1.76 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
NAME := minectl
FILES := $(shell find * -type f ! -path 'vendor/*' -name '*.go')
.DEFAULT_GOAL := help
Version := $(shell git describe --tags --dirty)
GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-s -w -X main.version=$(Version) -X main.commit=$(GitCommit)"
.PHONY: lint
lint: golangci-lint
.PHONY: golangci-lint
golangci-lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
export BINARY="golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.41.1; \
fi
golangci-lint run --timeout 10m -E goimports --fix
.PHONY: test
test: ## Run the tests against the codebase
go test -v ./...
.PHONY: install
install: ## Build and install locally the binary (dev purpose)
go install .
.PHONY: build-local
build-local: ## Build the binaries using local GOOS
go build .
.PHONY: run-local
run-local: ## Run the binaries locals
go run .
.PHONY: build
build: ## Build the binaries
rm -rf bin/
mkdir -p bin/
CGO_ENABLED=0 GOOS=linux go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/$(NAME)
CGO_ENABLED=0 GOOS=darwin go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/$(NAME)-darwin
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/$(NAME).exe
.PHONY: clean
clean: ## Remove binary if it exists
rm -f $(NAME)
.PHONY: coverage
coverage: ## Generates coverage report
rm -rf *.out
go test -v ./... -coverpkg=./... -coverprofile=coverage.out
.PHONY: all
all: test build coverage ## Test, builds and ship package for all supported platforms
.PHONY: help
help: ## Displays this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'