-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
90 lines (73 loc) · 2.61 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
FORMAT ?= csv
DEST_DIR ?= .
DEBUG ?=
SUITE ?= all
GO_SRC := cmd/main.go
EXECUTABLE := commatrix-gen
export GOLANGCI_LINT_CACHE = /tmp/.cache
.DEFAULT_GOAL := run
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
CURPATH=$(PWD)
BIN_DIR=$(CURPATH)/bin
GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
# golangci-lint version should be updated periodically
# we keep it fixed to avoid it from unexpectedly failing on the project
# in case of a version bump
GOLANGCI_LINT_VER = v1.55.2
.PHONY: build
build:
go build -o $(EXECUTABLE) $(GO_SRC)
.PHONY: generate
generate: build
rm -rf $(DEST_DIR)/communication-matrix
mkdir -p $(DEST_DIR)/communication-matrix
./$(EXECUTABLE) -format=$(FORMAT) -destDir=$(DEST_DIR)/communication-matrix -customEntriesPath=$(CUSTOM_ENTRIES_PATH) -customEntriesFormat=$(CUSTOM_ENTRIES_FORMAT) $(if $(DEBUG),-debug=true)
.PHONY: clean
clean:
@rm -f $(EXECUTABLE)
mock-generate: gomock
go generate ./...
# Run go fmt against code
fmt-code:
go fmt ./...
GOMOCK = $(shell pwd)/bin/mockgen
gomock:
$(call go-install-tool,$(GOMOCK),github.com/golang/mock/[email protected])
GINKGO = $(BIN_DIR)/ginkgo
ginkgo:
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo)
deps-update:
go mod tidy
check-deps: deps-update
@set +e; git diff --quiet HEAD go.sum go.mod; \
if [ $$? -eq 1 ]; \
then echo -e "\ngo modules are out of date. Please commit after running 'make deps-update' command\n"; \
exit 1; fi
$(GOLANGCI_LINT): ; $(info installing golangci-lint...)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VER))
.PHONY: lint
lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint
GOFLAGS="" $(GOLANGCI_LINT) run --timeout=10m
.PHONY: test
test:
GOFLAGS="" go test ./pkg/...
.PHONY: e2e-test
e2e-test: ginkgo
@if [ "$(SUITE)" = "Validation" ] || [ "$(SUITE)" = "Nftables" ]; then \
echo "Running e2e '$(SUITE)' test suite"; \
EXTRA_NFTABLES_MASTER_FILE="$(EXTRA_NFTABLES_MASTER_FILE)" EXTRA_NFTABLES_WORKER_FILE="$(EXTRA_NFTABLES_WORKER_FILE)" $(GINKGO) -v --focus "$(SUITE)" ./test/e2e/...; \
elif [ "$(SUITE)" = "all" ]; then \
echo "Running all e2e test suites"; \
EXTRA_NFTABLES_MASTER_FILE="$(EXTRA_NFTABLES_MASTER_FILE)" EXTRA_NFTABLES_WORKER_FILE="$(EXTRA_NFTABLES_WORKER_FILE)" $(GINKGO) -v ./test/e2e/...; \
else \
echo "Env var 'SUITE' must be set (Options: 'all', 'Validation', 'Nftables')"; \
fi
# go-install-tool will 'go install' any package $2 and install it to $1.
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(BIN_DIR) GOFLAGS="" go install $(2) ;\
}
endef