-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (59 loc) · 1.68 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
# Variables
SOURCES := $(shell find . -name '*.go')
BINARY := kubectl-envsubst
COV_REPORT := coverage.txt
TEST_FLAGS := -v -race -timeout 30s
KIND_CLUSTER_NAME := kubectl-envsubst
INSTALL_DIR := /usr/local/bin
# Default target
.PHONY: all
all: build
# Build the binary (GOARCH=amd64 GOOS=linux; -o $(BINARY))
.PHONY: build
build: $(SOURCES)
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/ ./cmd/kubectl-envsubst
# Install the binary to /usr/local/bin
.PHONY: install
install: build
@echo "Installing bin/$(BINARY) to $(INSTALL_DIR)..."
@install -m 0755 bin/$(BINARY) $(INSTALL_DIR)
# Run unit tests
.PHONY: test
test:
go test $(TEST_FLAGS) ./...
# Run tests with coverage
.PHONY: test-cov
test-cov:
go test -coverprofile=$(COV_REPORT) -coverpkg=./pkg/...,!./integration/... ./...
go tool cover -html=$(COV_REPORT)
# Setup kind-cluster (for running integration tests in a sandbox)
.PHONY: kind-setup
kind-setup:
kind create cluster --name $(KIND_CLUSTER_NAME)
kubectl config set-context kind-$(KIND_CLUSTER_NAME)
# Cleanup kind-cluster
.PHONY: kind-teardown
kind-teardown:
kind delete clusters $(KIND_CLUSTER_NAME)
# Run integration tests
.PHONY: test-integration
test-integration: install kind-setup
KUBECTL_ENVSUBST_INTEGRATION_TESTS_AVAILABLE=0xcafebabe go test -v integration/*.go
KUBECTL_ENVSUBST_INTEGRATION_TESTS_AVAILABLE=0xcafebabe go test -v cmd/kubectl-envsubst/*.go
$(MAKE) kind-teardown
# Lint the code
.PHONY: lint
lint:
golangci-lint run ./...
# Check goreleaser
.PHONY: snapshot
snapshot:
goreleaser release --skip sign --skip publish --snapshot --clean
# Format the code
.PHONY: format
format:
go fmt ./...
# Clean build artifacts
.PHONY: clean
clean:
@rm -rf bin/ $(COV_REPORT)