-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (94 loc) · 3.6 KB
/
Copy pathMakefile
File metadata and controls
119 lines (94 loc) · 3.6 KB
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
SHELL := /usr/bin/env bash
BINARY := bin/sandbox-operator
MAIN := ./cmd/sandbox-operator
APISERVER_BINARY := bin/sandbox-apiserver
APISERVER_MAIN := ./cmd/sandbox-apiserver
APISERVER_IMG ?= ghcr.io/cocoonstack/sandbox-apiserver:dev
VERSION_PKG := github.com/cocoonstack/sandbox-operator/internal/version
GIT_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo unknown)
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
LD_FLAGS := -s -w -X $(VERSION_PKG).gitVersion=$(GIT_VERSION) -X $(VERSION_PKG).gitSHA=$(GIT_SHA) -X $(VERSION_PKG).buildDate=$(BUILD_DATE)
## Build-tagged harnesses under test/, one tag per directory
TAGGED_HARNESSES := e2e e2ebench l2bench l3bench poolbench scalebench scalestress
## Target OSes for vet / lint
GOOSES ?= linux darwin
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool versions
GOLANGCILINT_VERSION ?= v2.12.2
GOLANGCILINT_ROOT := $(LOCALBIN)/golangci-lint-$(GOLANGCILINT_VERSION)
GOLANGCILINT := $(GOLANGCILINT_ROOT)/golangci-lint
.DEFAULT_GOAL := all
## Tool download targets
.PHONY: golangci-lint
golangci-lint: $(GOLANGCILINT)
$(GOLANGCILINT):
GOBIN=$(GOLANGCILINT_ROOT) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
.PHONY: all
all: fmt-check vet test build
.PHONY: build
build: ## Build the operator binary.
mkdir -p bin
go build -ldflags "$(LD_FLAGS)" -o $(BINARY) $(MAIN)
.PHONY: apiserver-build
apiserver-build: ## Build the aggregated sandbox-apiserver binary.
mkdir -p bin
go build -ldflags "-s -w" -o $(APISERVER_BINARY) $(APISERVER_MAIN)
.PHONY: apiserver-image
apiserver-image: ## Build the aggregated sandbox-apiserver image (override APISERVER_IMG).
docker build -f Dockerfile.apiserver -t $(APISERVER_IMG) .
.PHONY: test
test: vet ## Run unit tests.
go test ./...
.PHONY: test-race
test-race: ## Run unit tests with the race detector.
go test -race ./...
.PHONY: coverage
coverage: vet ## Write unit-test coverage to bin/coverage.out.
mkdir -p bin
go test -coverprofile=bin/coverage.out ./...
.PHONY: vet
vet: ## Run go vet on every target OS.
@for goos in $(GOOSES); do \
echo "==> go vet GOOS=$$goos"; \
GOOS=$$goos go vet ./... || exit 1; \
done
.PHONY: vet-tagged
vet-tagged: ## Type-check the build-tagged e2e/bench harnesses.
@for t in $(TAGGED_HARNESSES); do \
echo "go vet -tags $$t ./test/$$t"; \
go vet -tags $$t ./test/$$t || exit 1; \
done
.PHONY: lint
lint: golangci-lint ## Run golangci-lint on every target OS.
@for goos in $(GOOSES); do \
echo "==> golangci-lint GOOS=$$goos"; \
GOOS=$$goos $(GOLANGCILINT) run ./... || exit 1; \
done
.PHONY: fmt
fmt: ## Format Go source files.
gofmt -w $$(find . -name '*.go' -not -path './.git/*')
.PHONY: fmt-check
fmt-check: ## Fail if a Go source file is not gofmt-clean.
@test -z "$$(gofmt -l $$(find . -name '*.go' -not -path './.git/*'))"
.PHONY: generate
generate: ## Regenerate CRDs, deep copies, and RBAC.
go mod download -modfile=tools.mod
go generate ./...
.PHONY: deps
deps: ## Download module dependencies.
go mod download
go mod download -modfile=tools.mod
.PHONY: clean
clean: ## Remove build and coverage outputs.
rm -rf bin
go clean -testcache
.PHONY: cloc
cloc: ## Count lines of code excluding tests (requires cloc).
cloc --exclude-dir=vendor,dist,bin --exclude-ext=json --not-match-f='_test\.go$$' .
.PHONY: help
help: ## Show available targets.
@awk 'BEGIN {FS = ":.*## "; printf "Usage: make <target>\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*## / {printf " %-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST)