-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
88 lines (63 loc) · 2.34 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
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
# constants
DOCKER_REPO = chathub-reverse-api
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/chathub-reverse-api/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)
lint: fmt download ## Lints all code with golangci-lint
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run
lint-reports: out/lint.xml
.PHONY: out/lint.xml
out/lint.xml: out download
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run ./... --out-format checkstyle | tee "$(@)"
govulncheck: ## Vulnerability detection using govulncheck
@go run golang.org/x/vuln/cmd/govulncheck ./...
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 --cache-to type=inline -t $(DOCKER_REPO):$(DOCKER_TAG) .
define make-go-dependency
# target template for go tools, can be referenced e.g. via /bin/<tool>
bin/$(notdir $1):
GOBIN=$(PWD)/bin go install $1
endef
# this creates a target for each go dependency to be referenced in other targets
$(foreach dep, $(GO_DEPENDENCIES), $(eval $(call make-go-dependency, $(dep))))
ci: lint-reports test-reports govulncheck ## Executes vulnerability scan, lint, 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 ''