-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·83 lines (59 loc) · 2.06 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
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
# constants
GOLANGCI_VERSION = 1.45.2
DOCKER_REPO = awesomecli
DOCKER_TAG = latest
all: git-hooks tidy ## Initializes all tools
out:
@mkdir -p out
git-hooks:
@git config --local core.hooksPath .githooks/
download: ## Downloads the dependencies
@go mod download
tidy: ## Cleans up go.mod and go.sum
@go mod tidy
fmt: ## Formats all code with go fmt
@go fmt ./...
run: fmt ## Run the app
@go run ./cmd/awesomecli/main.go
test-build: ## Tests whether the code compiles
@go build -o /dev/null ./...
build: out/bin ## Builds all binaries
GO_BUILD = mkdir -pv "$(@)" && go build -ldflags="-w -s" -o "$(@)" ./...
.PHONY: out/bin
out/bin:
$(GO_BUILD)
GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION)
$(GOLANGCI_LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v$(GOLANGCI_VERSION)
@mv bin/golangci-lint "$(@)"
lint: fmt $(GOLANGCI_LINT) download ## Lints all code with golangci-lint
@$(GOLANGCI_LINT) run
lint-reports: out/lint.xml
.PHONY: out/lint.xml
out/lint.xml: $(GOLANGCI_LINT) out download
@$(GOLANGCI_LINT) run ./... --out-format checkstyle | tee "$(@)"
test: ## Runs all tests
@go test $(ARGS) ./...
coverage: out/report.json ## Displays coverage per func on cli
go tool cover -func=out/cover.out
html-coverage: out/report.json ## Displays the coverage results in the browser
go tool cover -html=out/cover.out
test-reports: out/report.json
.PHONY: out/report.json
out/report.json: out
@go test -count 1 ./... -coverprofile=out/cover.out --json | tee "$(@)"
clean: ## Cleans up everything
@rm -rf bin out
docker: ## Builds docker image
docker buildx build -t $(DOCKER_REPO):$(DOCKER_TAG) .
ci: lint-reports test-reports ## Executes lint and test and generates reports
help: ## Shows the help
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ''