Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (106 loc) · 5.83 KB
/
Copy pathMakefile
File metadata and controls
133 lines (106 loc) · 5.83 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Canonical graycode-eco Makefile for Go LIBRARY repos.
# flux is a versioned Go library consumed by Rho (no standalone binary).
# ---------------------------------------------------------------------------
# Project metadata
# ---------------------------------------------------------------------------
NAME := flux
# ---------------------------------------------------------------------------
# Versioning — sourced from VERSION file; falls back to git describe.
# See https://github.com/GrayCodeAI/rho/blob/main/VERSIONING.md.
# ---------------------------------------------------------------------------
VERSION ?= $(shell cat VERSION 2>/dev/null | head -n1 | tr -d '[:space:]' || git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# No LDFLAGS — flux is a library; the version comes from the VERSION file
# via go:embed (version.go), not from linker-injected package-main vars.
# ---------------------------------------------------------------------------
# Tooling — pinned, install if missing.
# ---------------------------------------------------------------------------
GOBIN_DIR := $(shell go env GOPATH)/bin
GOLANGCI := $(GOBIN_DIR)/golangci-lint
GOFUMPT := $(GOBIN_DIR)/gofumpt
GOIMPORTS := $(GOBIN_DIR)/goimports
GOVULNCHECK := $(GOBIN_DIR)/govulncheck
# ---------------------------------------------------------------------------
# Phony declarations (alphabetical).
# ---------------------------------------------------------------------------
.PHONY: all bench boundaries build check-replace ci clean cover fmt help lint lint-fix \
security test test-10x test-race tidy version vet
boundaries: ## Enforce support-repo import boundaries.
bash ./scripts/check-ecosystem-boundaries.sh
bash ./scripts/check-provider-layering.sh
.PHONY: check-replace
check-replace: ## Fail if go.mod has local replace directives (run before tagging)
@bash scripts/check-no-replace-directives.sh
# ---------------------------------------------------------------------------
# Default target.
# ---------------------------------------------------------------------------
all: lint test build ## Default — lint, test, build.
# ---------------------------------------------------------------------------
# Build / install / release.
# ---------------------------------------------------------------------------
build: ## Build all library packages (flux is a library consumed by rho; no standalone binary).
go build ./...
# ---------------------------------------------------------------------------
# Tests.
# ---------------------------------------------------------------------------
test: ## Run unit tests.
go test ./... -count=1 -timeout=120s
test-race: ## Run unit tests with the race detector.
go test ./... -race -count=1 -timeout=180s
test-10x: ## Run tests 10 times to surface flakes.
go test ./... -race -count=10 -timeout=600s
cover: ## Generate a coverage report (coverage.out + coverage.html).
go test ./... -race -coverprofile=coverage.out -covermode=atomic -timeout=180s
@go tool cover -func=coverage.out | grep "^total:"
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
bench: ## Run benchmarks.
go test ./... -bench=. -benchmem -count=3 -timeout=300s
# ---------------------------------------------------------------------------
# Quality gates.
# ---------------------------------------------------------------------------
fmt: ## Format source files (gofumpt + goimports).
@command -v $(GOFUMPT) >/dev/null 2>&1 || (echo "install: go install mvdan.cc/gofumpt@latest" && exit 1)
@command -v $(GOIMPORTS) >/dev/null 2>&1 || (echo "install: go install golang.org/x/tools/cmd/goimports@latest" && exit 1)
$(GOFUMPT) -w .
$(GOIMPORTS) -w .
vet: ## Run go vet.
go vet ./...
lint: ## Run golangci-lint.
@command -v $(GOLANGCI) >/dev/null 2>&1 || (echo "install: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest" && exit 1)
$(GOLANGCI) run ./... --timeout=5m
lint-fix: ## Run golangci-lint with --fix.
@command -v $(GOLANGCI) >/dev/null 2>&1 || (echo "install: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest" && exit 1)
$(GOLANGCI) run ./... --fix --timeout=5m
security: ## Run govulncheck.
@command -v $(GOVULNCHECK) >/dev/null 2>&1 || (echo "install: go install golang.org/x/vuln/cmd/govulncheck@latest" && exit 1)
$(GOVULNCHECK) ./...
tidy: ## Tidy go.mod / go.sum.
go mod tidy
go mod verify
# ---------------------------------------------------------------------------
# Composite gate used by CI and pre-push.
# ---------------------------------------------------------------------------
ci: tidy fmt vet lint boundaries check-replace test-race security ## Run everything CI runs.
@echo "All CI checks passed."
# ---------------------------------------------------------------------------
# Misc.
# ---------------------------------------------------------------------------
version: ## Print the version that will be embedded.
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(DATE)"
clean: ## Remove build artefacts.
rm -rf bin/ dist/ coverage.out coverage.html
go clean -testcache
help: ## Show this help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.PHONY: hooks sync-clone
hooks: ## Install git hooks via lefthook (format, lint, conventional commits, co-author strip).
@command -v lefthook >/dev/null 2>&1 || (echo "install: go install github.com/evilmartians/lefthook@latest" && exit 1)
git config --unset core.hooksPath 2>/dev/null || true
lefthook install
sync-clone: ## Hard-reset flux to origin/main (post history rewrite).
@chmod +x scripts/sync-clone.sh scripts/commit-clean.sh
@./scripts/sync-clone.sh