-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
85 lines (71 loc) · 2.65 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
# GO_BUILD_ARGS should be set when running 'go build' or 'go install'.
VERSION_PKG = "$(shell go list -m)/internal/version"
export SCAFFOLD_VERSION = $(shell git describe --tags --abbrev=0)
export GIT_VERSION = $(shell git describe --dirty --tags --always)
export GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_DIR = $(PWD)/bin
GO_BUILD_ARGS = \
-gcflags "all=-trimpath=$(shell dirname $(shell pwd))" \
-asmflags "all=-trimpath=$(shell dirname $(shell pwd))" \
-ldflags " \
-s \
-w \
-X '$(VERSION_PKG).ScaffoldVersion=$(SCAFFOLD_VERSION)' \
-X '$(VERSION_PKG).GitVersion=$(GIT_VERSION)' \
-X '$(VERSION_PKG).GitCommit=$(GIT_COMMIT)' \
" \
# Always use Go modules
export GO111MODULE = on
# Setup project-local paths and build settings
SHELL=/bin/bash
TOOLS_DIR=$(PWD)/tools
TOOLS_BIN_DIR=$(TOOLS_DIR)/bin
SCRIPTS_DIR=$(TOOLS_DIR)/scripts
export PATH := $(BUILD_DIR):$(TOOLS_BIN_DIR):$(SCRIPTS_DIR):$(PATH)
##@ Development
.PHONY: generate
generate: build # Generate CLI docs and samples
rm -rf testdata/
go run ./hack/generate/samples/generate_testdata.go
go generate ./...
.PHONY: all
all: test lint build
# Run tests
.PHONY: test
# Use envtest based on the version of kubernetes/client-go configured in the go.mod file.
# If this version of envtest is not available yet, submit a PR similar to
# https://github.com/kubernetes-sigs/kubebuilder/pull/2287 targeting the kubebuilder
# "tools-releases" branch. Make sure to look up the appropriate etcd version in the
# kubernetes release notes for the minor version you're building tools for.
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
TESTPKG ?= ./...
test: build
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
eval $$(setup-envtest use -p env $(ENVTEST_VERSION)) && go test -race -covermode atomic -coverprofile cover.out $(TESTPKG)
.PHONY: test-sanity
test-sanity: generate fix lint ## Test repo formatting, linting, etc.
go vet ./...
git diff --exit-code # diff again to ensure other checks don't change repo
# Build manager binary
.PHONY: build
build:
mkdir -p $(BUILD_DIR) && go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./
.PHONY: setup-lint
setup-lint: ## Setup the lint
fetch golangci-lint 1.51.2
# Run various checks against code
.PHONY: lint
lint: setup-lint
golangci-lint run
.PHONY: fix
fix: setup-lint ## Fixup files in the repo.
go mod tidy
go fmt ./...
golangci-lint run --fix
.PHONY: release
release: GORELEASER_ARGS ?= --snapshot --rm-dist --skip-sign
release:
fetch goreleaser 0.177.0 && goreleaser $(GORELEASER_ARGS)
.PHONY: clean
clean:
rm -rf $(TOOLS_BIN_DIR) $(BUILD_DIR)