-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
82 lines (65 loc) · 2 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
GO := go
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
KUSTOMIZE := kustomize
IMG := ghcr.io/doodlescheduling/kubectl-del-namespace:latest
pkgs := $(shell $(GO) list ./... | grep -v /vendor/)
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
all: deps vet fmt lint test build
style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
test:
@echo ">> running unit tests"
@$(GO) test -short -race -v -coverprofile=coverage.out -tags unit ./...
GOLANGCI_LINT = $(GOBIN)/golangci-lint
.PHONY: golangci-lint
golangci-lint: ## Download golint locally if necessary
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2)
.PHONY: lint
lint: golangci-lint ## Run golangci-lint against code
$(GOLANGCI_LINT) run ./...
deps:
@echo ">> install dependencies"
@$(GO) mod download
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
gofmt -s -w .
.PHONY: tidy
tidy: ## Run go mod tidy
go mod tidy
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
build:
@echo ">> building binaries"
CGO_ENABLED=0 go build -o kubectl-del-namespace main.go
.PHONY: run
run:
go run ./main.go
.PHONY: docker-build
docker-build: build ## Build docker image with the manager.
docker build -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
.PHONY: all style fmt build test vet
# go-install-tool will 'go install' any package $2 and install it to $1
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
env -i bash -c "GOBIN=$(GOBIN) PATH=$(PATH) GOPATH=$(shell go env GOPATH) GOCACHE=$(shell go env GOCACHE) go install $(2)" ;\
rm -rf $$TMP_DIR ;\
}
endef