forked from newrelic/nri-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (82 loc) · 3.4 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
INTEGRATION := redis
BINARY_NAME = nri-$(INTEGRATION)
SRC_DIR = ./src/
GO_PKGS := $(shell go list ./... | grep -v "/vendor/")
VALIDATE_DEPS = golang.org/x/lint/golint
TEST_DEPS = github.com/axw/gocov/gocov github.com/AlekSi/gocov-xml
INTEGRATIONS_DIR = /var/db/newrelic-infra/newrelic-integrations/
CONFIG_DIR = /etc/newrelic-infra/integrations.d
GO_FILES := ./src/
WORKDIR := $(shell pwd)
TARGET := target
TARGET_DIR = $(WORKDIR)/$(TARGET)
all: build
build: clean validate-deps validate compile test
clean:
@echo "=== $(INTEGRATION) === [ clean ]: removing binaries and coverage file..."
@rm -rfv bin coverage.xml $(TARGET)
validate-deps:
@echo "=== $(INTEGRATION) === [ validate-deps ]: installing validation dependencies..."
@go get -v $(VALIDATE_DEPS)
validate-only:
ifeq ($(strip $(GO_FILES)),)
@echo "=== $(INTEGRATION) === [ validate ]: no Go files found. Skipping validation."
else
@printf "=== $(INTEGRATION) === [ validate ]: running gofmt... "
# `gofmt` expects files instead of packages. `go fmt` works with
# packages, but forces -l -w flags.
@OUTPUT="$(shell gofmt -l $(GO_FILES))" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Incorrect syntax in the following files:" ;\
echo "$$OUTPUT" ;\
exit 1 ;\
fi
@printf "=== $(INTEGRATION) === [ validate ]: running golint... "
@OUTPUT="$(shell golint $(SRC_DIR)...)" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Issues found:" ;\
echo "$$OUTPUT" ;\
exit 1 ;\
fi
@printf "=== $(INTEGRATION) === [ validate ]: running go vet... "
@OUTPUT="$(shell go vet $(SRC_DIR)...)" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Issues found:" ;\
echo "$$OUTPUT" ;\
exit 1;\
fi
endif
validate: validate-deps validate-only
compile-deps:
@echo "=== $(INTEGRATION) === [ compile-deps ]: installing build dependencies..."
@go get -v -d -t ./...
bin/$(BINARY_NAME):
@echo "=== $(INTEGRATION) === [ compile ]: building $(BINARY_NAME)..."
@go build -v -o bin/$(BINARY_NAME) $(GO_FILES)
compile: compile-deps bin/$(BINARY_NAME)
test-deps: compile-deps
@echo "=== $(INTEGRATION) === [ test-deps ]: installing testing dependencies..."
@go get -v $(TEST_DEPS)
test-only:
@echo "=== $(INTEGRATION) === [ test ]: running unit tests..."
@gocov test ./... | gocov-xml > coverage.xml
test: test-deps test-only
integration-test: test-deps
@echo "=== $(INTEGRATION) === [ test ]: running integration tests..."
@docker-compose -f tests/integration/docker-compose.yml up -d --build
@go test -tags=integration ./tests/integration/. || (ret=$$?; docker-compose -f tests/integration/docker-compose.yml down && exit $$ret)
@docker-compose -f tests/integration/docker-compose.yml down
install: bin/$(BINARY_NAME)
@echo "=== $(INTEGRATION) === [ install ]: installing bin/$(BINARY_NAME)..."
@sudo install -D --mode=755 --owner=root --strip $(ROOT)bin/$(BINARY_NAME) $(INTEGRATIONS_DIR)/bin/$(BINARY_NAME)
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-definition.yml $(INTEGRATIONS_DIR)/$(INTEGRATION)-definition.yml
@sudo install -D --mode=644 --owner=root $(ROOT)$(INTEGRATION)-config.yml.sample $(CONFIG_DIR)/$(INTEGRATION)-config.yml.sample
# Include thematic Makefiles
include Makefile-*.mk
.PHONY: all build clean validate-deps validate-only validate compile-deps compile test-deps test-only test integration-test install