-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (78 loc) · 3.02 KB
/
Makefile
File metadata and controls
100 lines (78 loc) · 3.02 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
# kubeswarm-cli Makefile
# Run `make help` for all available targets.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
BINARY ?= swarm
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X main.version=$(VERSION)"
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
@mkdir -p "$(LOCALBIN)"
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.8.0
# ---------------------------------------------------------------------------
##@ Development
# ---------------------------------------------------------------------------
.PHONY: help
help: ## Show this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: setup
setup: ## One-time dev setup: install git hooks.
@ln -sf ../../scripts/commit-msg .git/hooks/commit-msg
@ln -sf ../../scripts/pre-push .git/hooks/pre-push
@echo "Installed git hooks (commit-msg, pre-push)."
.PHONY: build
build: ## Build the swarm CLI binary.
@go build $(LDFLAGS) -o bin/$(BINARY) ./cmd/swarm
.PHONY: install
install: ## Install the swarm CLI to GOPATH/bin.
@go install $(LDFLAGS) ./cmd/swarm
.PHONY: clean
clean: ## Remove build artifacts and Go test cache.
@rm -f bin/$(BINARY)
@go clean -testcache
# ---------------------------------------------------------------------------
##@ Quality
# ---------------------------------------------------------------------------
.PHONY: fmt
fmt: ## Format all Go code.
@gofmt -w .
.PHONY: verify
verify: ## Verify module dependencies (requires go.work for workspace-only deps).
@go mod verify
.PHONY: test
test: ## Run all tests.
@go test ./...
.PHONY: lint
lint: fmt golangci-lint ## Format and run linter.
@"$(GOLANGCI_LINT)" run
.PHONY: lint-fix
lint-fix: fmt golangci-lint ## Format and run linter with auto-fix.
@"$(GOLANGCI_LINT)" run --fix
.PHONY: tidy
tidy: ## Run go mod tidy.
@go mod tidy
# ---------------------------------------------------------------------------
##@ CI
# ---------------------------------------------------------------------------
.PHONY: ci
ci: clean fmt verify lint test ## Run the full CI pipeline locally.
@echo "CI passed."
# ---------------------------------------------------------------------------
##@ Dependencies (auto-installed, pinned versions)
# ---------------------------------------------------------------------------
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
define go-install-tool
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f "$(1)" ;\
GOBIN="$(LOCALBIN)" go install $${package} ;\
mv "$(LOCALBIN)/$$(basename "$(1)")" "$(1)-$(3)" ;\
} ;\
ln -sf "$$(realpath "$(1)-$(3)")" "$(1)"
endef