-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (70 loc) · 2.13 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
# Workaround when docker run with -u.
ifeq ($(HOME),/)
export GOCACHE = /tmp/.cache
export HOME =
endif
ROOTDIR ?= $(CURDIR)
SHELL := /bin/bash
GO := $(shell command -v go 2> /dev/null)
GOFUMPT := $(shell command -v gofumpt 2> /dev/null)
REVIVE := $(shell command -v revive 2> /dev/null)
GINKGO := $(shell command -v ginkgo 2> /dev/null)
GOCOV := $(shell command -v gocov 2> /dev/null)
GOCOVXML := $(shell command -v gocov-xml 2> /dev/null)
COVERAGE_DIR := $(CURDIR)/coverage
ZENKIT_BUILD_VERSION := 1.18.0
BUILD_IMG := zenoss/zenkit-build:$(ZENKIT_BUILD_VERSION)
DOCKER_PARAMS := --rm \
--volume $(ROOTDIR):/workspace/:rw \
--env CGO_ENABLED=1 \
--env LOCAL_USER_ID=$(shell id -u) \
--workdir /workspace/
DOCKER_CMD := docker run -t $(DOCKER_PARAMS) $(BUILD_IMG)
M = $(shell printf "\033[34;1m▶\033[0m")
RED = $(shell printf "\033[31;1m▶\033[0m")
# Static Checks
.PHONY: fmt
fmt:
@echo "$(M) gofumpt: running"
@if [[ "$(shell $(GOFUMPT) -l -w .)" ]]; then \
echo "$(RED) gofumpt: Please commit formatted files"; \
exit 1; \
else \
echo "$(M) gofumpt: files look good"; \
fi
.PHONY: lint
lint:
@echo "$(M) running revive linter…"
$(REVIVE) \
-config $(ROOTDIR)/.revive.toml \
-formatter=friendly \
-exclude $(ROOTDIR)/vendor/... \
$(ROOTDIR)/...
@echo "$(M) linted with revive linter"
# Test
.PHONY: test
test: COVERAGE_PROFILE := coverprofile.out
test: COVERAGE_HTML := $(COVERAGE_DIR)/index.html
test: COVERAGE_XML := $(COVERAGE_DIR)/coverage.xml
test: fmt lint
@mkdir -p $(COVERAGE_DIR)
@$(GINKGO) \
run \
-r \
--tags integration \
--cover \
--coverprofile $(COVERAGE_PROFILE) \
--covermode=atomic \
--race \
--junit-report=junit.xml
$Q $(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML)
$Q $(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML)
.PHONY: test-containerized
test-containerized:
$(DOCKER_CMD) make test
# Misc
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything.
@rm -f junit.xml internal/junit.xml
@rm -f coverprofile.out internal/coverprofile.out
@rm -rf $(COVERAGE_DIR)