forked from elastic/geneve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (115 loc) · 3.64 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
PYTEST_VERBOSE := $(if $(filter-out 0,$(V)),$(if $(filter-out 1,$(V)),$(if $(filter-out 2,$(V)),-vvv,-vv),-v) -r aP,-qq)
GO_VERBOSE := $(if $(filter-out 0,$(V)),,-q)
ifeq ($(VENV),)
ACTIVATE :=
else
ACTIVATE := source $(VENV)/bin/activate;
endif
ifeq ($(PYTHON),)
PYTHON := $(ACTIVATE)python3
endif
PYGOLO_DIR := $(shell go list -f '{{.Dir}}' -m gitlab.com/pygolo/py)
ifeq ($(PYGOLO_DIR),)
PYGOLO_DIR := $(shell go get gitlab.com/pygolo/py && go list -f '{{.Dir}}' -m gitlab.com/pygolo/py)
endif
ifneq ($(PYGOLO_DIR),)
include $(PYGOLO_DIR)/Python.mk
GO_TAGS := $(if $(PYGOLO_TAGS),-tags "$(PYGOLO_TAGS)")
else
define embed-python
$(error Embedding Python is not supported on this platform)
endef
endif
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
all: lint tests
prereq:
$(PYTHON) -m pip install --user --upgrade pip
$(PYTHON) -m pip install --user -r requirements.txt
prereq-lint: prereq
go install golang.org/x/lint/golint@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
lint:
$(PYTHON) -m ruff check geneve tests
$(PYTHON) -m black -q --check geneve tests || ($(PYTHON) -m black geneve tests; false)
$(PYTHON) -m isort -q --check geneve tests || ($(PYTHON) -m isort geneve tests; false)
license-check:
bash scripts/license_check.sh
tests: tests/*.py
$(PYTHON) -m pytest $(PYTEST_VERBOSE) tests/test_*.py
online-tests: tests/*.py
$(PYTHON) -m pytest $(PYTEST_VERBOSE) tests/test_emitter_*.py
up:
@$(call print_server_version,ES,ELASTICSEARCH)
@$(call print_server_version,KB,KIBANA)
docker compose up --wait --quiet-pull
down:
docker compose down
jupyter:
jupyter-notebook
gnv: main.go $(call rwildcard,cmd,*.go)
$(embed-python)
go build $(GO_TAGS) -race -o $@ .
cli-build: gnv
./gnv version
@if [ $$(./gnv version | grep "version:" | head -2 | sort | uniq | wc -l) -ne 1 ]; then \
echo "\nApplication and module versions do not match"; \
false; \
fi
cli-lint:
golint .
go vet $(GO_TAGS) .
staticcheck $(GO_TAGS) .
cli-test:
$(embed-python)
go test $(strip $(GO_VERBOSE) $(GO_TAGS)) -race ./...
cli-bench:
$(embed-python)
go test $(strip $(GO_VERBOSE) $(GO_TAGS)) -bench=. ./cmd/geneve/source
clean:
go clean -cache -testcache
rm -rf gnv
pkg-build:
$(PYTHON) -m build
pkg-install:
$(PYTHON) -m pip install --force-reinstall dist/geneve-*.whl
package: VENV := .venv-test
package: pkg-build
rm -rf $(VENV)
$(PYTHON) -mvenv $(VENV)
$(MAKE) pkg-install VENV=$(VENV)
rm -rf $(VENV)
CREDS_FILE=credentials-cloud-stack.json
cloud-stack-up:
touch $(CREDS_FILE)
chmod 600 $(CREDS_FILE)
ecctl deployment create --file tests/deployment.json --track | tee /dev/stderr | (jq >$(CREDS_FILE) 2>/dev/null; cat >/dev/null)
cloud-stack-down: $(CREDS_FILE)
ecctl deployment shutdown --force $(shell jq -r .id $(CREDS_FILE))
rm $(CREDS_FILE)
define print_server_version
if [ -n "$$TEST_$(2)_IMAGE" ]; then \
echo "$(1): $$TEST_$(2)_IMAGE"; \
else \
echo "$(1): $$TEST_STACK_VERSION"; \
fi
endef
export TEST_STACK_VERSION
ifeq ($(TEST_STACK_VERSION)$(TEST_ELASTICSEARCH_IMAGE),)
override TEST_STACK_VERSION = latest
endif
ifeq ($(TEST_STACK_VERSION)$(TEST_KIBANA_IMAGE),)
override TEST_STACK_VERSION = latest
endif
ifeq ($(TEST_STACK_VERSION),latest)
override TEST_STACK_VERSION := $(shell \
curl -s -L https://artifacts-api.elastic.co/v1/versions | \
jq -r 'last(.versions[] | select(contains("SNAPSHOT") | not))' \
)
endif
ifeq ($(TEST_STACK_VERSION),latest-snapshot)
override TEST_STACK_VERSION := $(shell \
curl -s -L https://artifacts-api.elastic.co/v1/versions | \
jq -r 'last(.versions[] | select(contains("SNAPSHOT")))' \
)
endif
.PHONY: lint tests online_tests run up down