-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
98 lines (71 loc) · 2.46 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
96
97
98
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
# constants
GOLANGCI_VERSION = 1.52.2
DOCKER_REPO = healthgroup
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/healthgroup/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 "$(@)"
.PHONY: test
test: ## Runs all tests
@go test -v $(ARGS) ./...
.PHONY: integration-test
integration-test: ## Runs all tests
@go test -v -tags integration -run TestServer -run TestReadConfigMap $(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
## Release
.PHONY: changelog
changelog: ## Generate changelog
git-chglog --next-tag $(VERSION) -o CHANGELOG.md
.PHONY: release
release: changelog ## Release a new tag
git add CHANGELOG.md
git commit -m "chore: update changelog for $(VERSION)"
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 ''