-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (150 loc) · 6.62 KB
/
Makefile
File metadata and controls
194 lines (150 loc) · 6.62 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
SHELL := /bin/bash
# ── Project metadata ──────────────────────────────────────────────
BINARY := bunny
MODULE := github.com/built-fast/bunny-cli
BUILD_DIR := ./bin
# ── Version info (injected via ldflags) ───────────────────────────
VERSION := $(shell git describe --tags --always --dirty)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X $(MODULE)/cmd.version=$(VERSION) \
-X $(MODULE)/cmd.commit=$(COMMIT) \
-X $(MODULE)/cmd.date=$(DATE)
# ── Go tool aliases ───────────────────────────────────────────────
GOCMD := go
GOBUILD := CGO_ENABLED=0 $(GOCMD) build -trimpath
GOTEST := $(GOCMD) test
GOVET := $(GOCMD) vet
GOFMT := gofmt
GOMOD := $(GOCMD) mod
.DEFAULT_GOAL := build
# ── Build ─────────────────────────────────────────────────────────
.PHONY: all build install run clean
all: fmt vet lint test build
build:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o $(BUILD_DIR)/$(BINARY) .
install:
$(GOCMD) install -ldflags '$(LDFLAGS)' ./...
run: build
$(BUILD_DIR)/$(BINARY)
clean:
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# ── Format & Lint ─────────────────────────────────────────────────
.PHONY: fmt fmt-check vet lint tidy tidy-check
fmt:
$(GOFMT) -w .
fmt-check:
@test -z "$$($(GOFMT) -l .)" || ($(GOFMT) -l . && exit 1)
vet:
$(GOVET) ./...
lint:
golangci-lint run
tidy:
$(GOMOD) tidy
tidy-check:
@cp go.mod go.mod.bak && cp go.sum go.sum.bak
@$(GOMOD) tidy
@diff -q go.mod go.mod.bak > /dev/null 2>&1 && diff -q go.sum go.sum.bak > /dev/null 2>&1; \
STATUS=$$?; \
mv go.mod.bak go.mod; \
mv go.sum.bak go.sum; \
if [ $$STATUS -ne 0 ]; then \
echo "go.mod/go.sum not tidy — run: make tidy"; \
exit 1; \
fi
# ── Test ──────────────────────────────────────────────────────────
.PHONY: test test-race test-coverage coverage test-e2e
test:
$(GOTEST) ./...
test-race:
$(GOTEST) -race ./...
test-e2e:
./e2e/run.sh
test-coverage:
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
coverage: test-coverage
@open coverage.html 2>/dev/null || xdg-open coverage.html 2>/dev/null || true
# ── Surface & Skill Drift ────────────────────────────────────────
.PHONY: surface check-surface check-skill-drift
surface:
$(GOCMD) run ./internal/surface/cmd/gensurface > .surface
check-surface:
@$(GOCMD) run ./internal/surface/cmd/gensurface | diff -u .surface - || \
(echo "CLI surface has changed. If intentional, run: make surface" && exit 1)
check-skill-drift:
@./scripts/check-skill-drift.sh
# ── Security ──────────────────────────────────────────────────────
.PHONY: vuln secrets security
vuln:
govulncheck ./...
secrets:
gitleaks detect --source . --verbose
security: vuln secrets
# ── CI Gate ───────────────────────────────────────────────────────
.PHONY: check
check: fmt-check vet lint tidy-check check-surface check-skill-drift test test-e2e vuln
# ── Module ────────────────────────────────────────────────────────
.PHONY: verify
verify:
$(GOMOD) verify
# ── GitHub Actions ────────────────────────────────────────────────
.PHONY: lint-actions
lint-actions:
actionlint
zizmor .github/workflows/
# ── Release ───────────────────────────────────────────────────────
.PHONY: test-release
test-release:
goreleaser release --snapshot --clean
# ── Tools ─────────────────────────────────────────────────────────
.PHONY: tools
tools:
brew bundle
# ── Help ──────────────────────────────────────────────────────────
.PHONY: help
help:
@echo "Usage: make [target]"
@echo ""
@echo "Build:"
@echo " build Build binary to $(BUILD_DIR)/$(BINARY)"
@echo " install Install binary via go install"
@echo " run Build and run"
@echo " clean Remove build artifacts and coverage files"
@echo ""
@echo "Format & Lint:"
@echo " fmt Format Go source files"
@echo " fmt-check Check formatting (fails if not formatted)"
@echo " vet Run go vet"
@echo " lint Run golangci-lint"
@echo " tidy Run go mod tidy"
@echo " tidy-check Check that go.mod/go.sum are tidy"
@echo ""
@echo "Test:"
@echo " test Run unit tests"
@echo " test-race Run unit tests with race detector"
@echo " test-e2e Run e2e tests (BATS + Prism)"
@echo " test-coverage Generate coverage report"
@echo " coverage Generate and open coverage report"
@echo ""
@echo "Security:"
@echo " vuln Run govulncheck"
@echo " secrets Run gitleaks secret scanning"
@echo " security Run all security checks"
@echo ""
@echo "Surface & Skills:"
@echo " surface Regenerate .surface snapshot"
@echo " check-surface Verify .surface is up to date"
@echo " check-skill-drift Check SKILL.md matches .surface"
@echo ""
@echo "CI:"
@echo " check Run full CI gate"
@echo ""
@echo "Other:"
@echo " verify Verify module dependencies"
@echo " lint-actions Lint GitHub Actions workflows"
@echo " test-release Goreleaser dry-run"
@echo " tools Install dev tools via Brewfile"
@echo " help Show this help"