-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (101 loc) · 4.81 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
# ------------------------------------------------------- ENVS ------------------------------------------------------- #
PROJECT := ipxer
COMMIT_SHA := $(shell git rev-parse --short HEAD)
TIMESTAMP := $(shell date --utc --iso-8601=seconds)
VERSION ?= $(shell git describe --tags --always --dirty)
GO_BUILD_LDFLAGS ?= -X main.BuildTimestamp=$(TIMESTAMP) -X main.CommitSHA=$(COMMIT_SHA) -X main.Version=$(VERSION)
# ------------------------------------------------------- VERSIONS --------------------------------------------------- #
# renovate: datasource=github-release depName=kubernetes-sigs/controller-tools
CONTROLLER_GEN_VERSION := v0.14.0
# renovate: datasource=github-release depName=mvdan/gofumpt
GOFUMPT_VERSION := v0.6.0
# renovate: datasource=github-release depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION := v1.59.1
# renovate: datasource=github-release depName=gotestyourself/gotestsum
GOTESTSUM_VERSION := v1.12.0
# renovate: datasource=github-release depName=vektra/mockery
MOCKERY_VERSION := v2.42.0
# renovate: datasource=github-release depName=oapi-codegen/oapi-codegen
OAPI_CODEGEN_VERSION := v2.3.0
# ------------------------------------------------------- TOOLS ------------------------------------------------------ #
CONTAINER_ENGINE ?= docker
KIND_BINARY ?= kind
KIND_BINARY_PREFIX ?= sudo
KINDENV_ENVS := KIND_BINARY_PREFIX="$(KIND_BINARY_PREFIX)" KIND_BINARY="$(KIND_BINARY)"
CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
GO_GEN := go generate
GOFUMPT := go run mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
GOLANGCI_LINT := go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
GOTESTSUM := go run gotest.tools/gotestsum@$(GOTESTSUM_VERSION) --format pkgname
MOCKERY := go run github.com/vektra/mockery/v2@$(MOCKERY_VERSION)
OAPI_CODEGEN := go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@$(OAPI_CODEGEN_VERSION)
BUILD_BINARY := GO_BUILD_LDFLAGS="$(GO_BUILD_LDFLAGS)" go run ./cmd/build-binary
BUILD_CONTAINER := CONTAINER_ENGINE="$(CONTAINER_ENGINE)" BUILD_ARGS="GO_BUILD_LDFLAGS=$(GO_BUILD_LDFLAGS)" go run ./cmd/build-container
KINDENV := $(KINDENV_ENVS) go run ./cmd/kindenv
OAPI_CODEGEN_HELPER := OAPI_CODEGEN="$(OAPI_CODEGEN)" go run ./cmd/oapi-codegen-helper
TEST_GO := GOTESTSUM="$(GOTESTSUM)" go run ./cmd/test-go
CLEAN_MOCKS := rm -rf ./internal/util/mocks
# ------------------------------------------------------- GENERATE --------------------------------------------------- #
.PHONY: generate
generate: ## Generate REST API server/client code, CRDs and other go generators.
$(OAPI_CODEGEN_HELPER)
$(GO_GEN) "./..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) paths="./..." \
crd:generateEmbeddedObjectMeta=true \
output:crd:artifacts:config=charts/$(PROJECT)/templates/crds
$(CONTROLLER_GEN) paths="./..." \
rbac:roleName=$(PROJECT) \
webhook \
output:rbac:dir=charts/$(PROJECT)/templates/rbac \
output:webhook:dir=charts/$(PROJECT)/templates/webhook
$(CLEAN_MOCKS)
$(MOCKERY)
# ------------------------------------------------------- BUILD BINARIES --------------------------------------------- #
.PHONY: build-binary
build-binary:
$(BUILD_BINARY)
# ------------------------------------------------------- BUILD CONTAINERS -------------------------------------------- #
.PHONY: build-container
build-container:
$(BUILD_CONTAINER)
# ------------------------------------------------------- FMT -------------------------------------------------------- #
.PHONY: fmt
fmt:
$(GOFUMPT) -w .
# ------------------------------------------------------- LINT ------------------------------------------------------- #
.PHONY: lint
lint:
$(GOLANGCI_LINT) run --fix
# ------------------------------------------------------- TEST ------------------------------------------------------- #
.PHONY: test-chart
test-chart:
echo TODO: implement 'make `test-chart`'.
.PHONY: test-unit
test-unit:
TEST_TAG=unit $(TEST_GO)
.PHONY: test-integration
test-integration:
TEST_TAG=integration $(TEST_GO)
.PHONY: test-functional
test-functional:
TEST_TAG=functional $(TEST_GO)
.PHONY: test-e2e
test-e2e:
echo "DISCLAIMER: this is still a work in progress"
CONTAINER_ENGINE=$(CONTAINER_ENGINE) ./cmd/e2e/main.sh
.PHONY: test-setup
test-setup:
$(KINDENV) setup
.PHONY: test-teardown
test-teardown:
$(KINDENV) teardown
.PHONY: test
test: test-unit test-setup test-integration test-functional test-teardown
# ------------------------------------------------------- PRE-PUSH --------------------------------------------------- #
.PHONY: githooks
githooks: ## Set up git hooks to run before a push.
git config core.hooksPath .githooks
.PHONY: pre-push
pre-push: generate fmt lint test
git status --porcelain