-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
80 lines (63 loc) · 3.24 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
GOCMD=go
GOTEST=$(GOCMD) test
BIN_DIR:=bin
SOURCES=$(shell find . -name '*.go' -not -name '*_test.go' -not -name "main.go")
EXPORT_RESULT?=FALSE
IS_CI?=FALSE
.PHONY: pre clean build run format lint-docker lint-go lint-yaml goconvey test coverage help
.DEFAULT_GOAL := help
##################################### Binary #####################################
pre: ## Create the bin directory
mkdir -p $(BIN_DIR)
clean: ## Clean the bin directory
rm -rf $(BIN_DIR)
rm -f ./checkstyle-report.xml checkstyle-report.xml yamllint-checkstyle.xml
build: pre ## Create the main binary
GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -ldflags="-s -w" -o bin/webhook cmd/*.go
run: ## Run the application
GO111MODULE=on go run cmd/*.go
##################################### Beautify #####################################
format: ## Format the source code
find . -name '*.go' -not -path './vendor/*' | xargs -n1 go fmt
lint-docker: ## Lint Dockerfiles
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint - < ./build/clickhouse/Dockerfile || true
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint - < ./docs/Dockerfile || true
for target in master; do \
echo "Linting $$target"; \
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint - < ./docker/$$target.Dockerfile || true; \
done
lint-go: ## Lint Go source code
ifeq ($(EXPORT_RESULT), TRUE)
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "TRUE" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
endif
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)
lint-yaml: ## Lint YAML files
ifeq ($(EXPORT_RESULT), TRUE)
$(GOCMD) install github.com/thomaspoignant/yamllint-checkstyle@latest
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
##################################### Test #####################################
goconvey: ## Run goconvey
go install github.com/smartystreets/goconvey@latest
goconvey -port 1234
test: ## Run the tests
ifeq ($(EXPORT_RESULT), TRUE)
$(GOCMD) install github.com/jstemmer/go-junit-report/v2@latest
$(eval OUTPUT_OPTIONS = | go-junit-report -iocopy -set-exit-code -out junit-report.xml)
endif
$(GOCMD) clean -testcache
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
coverage: $(wildcard **/**/*.go) ## Run the tests and generate the coverage reports
$(GOTEST) -cover -covermode=count -coverprofile=coverage.out ./...
ifeq ($(EXPORT_RESULT), TRUE)
$(GOCMD) install github.com/axw/gocov/gocov@latest
$(GOCMD) install github.com/AlekSi/gocov-xml@latest
$(GOCMD) tool cover -html=coverage.out -o coverage.html
gocov convert coverage.out | gocov-xml > coverage.xml
rm -f coverage.out
endif
##################################### Help #####################################
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'