forked from jhunt/shout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
254 lines (201 loc) · 8.92 KB
/
Makefile
File metadata and controls
254 lines (201 loc) · 8.92 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
NAME := shout
MODULE := github.com/cloudfoundry-community/shout
SHELL := /bin/bash
# Coverage settings
# COVERAGE_MIN — gate threshold (default 50, set 0 to disable gate)
# COVERAGE_REPORT — report type: full (HTML report), default is gate
COVERAGE_MIN ?= 50
COVERAGE_REPORT ?=
include version.mk
# ── Platform selection ──────────────────────────────────────────
# Usage:
# make build — build both Go and Lisp
# make build go — build Go only
# make build lisp — build Lisp only
# make test go — test Go only
# (same pattern for: test, clean, coverage, docker, release,
# security, help)
WANT_GO :=
WANT_LISP :=
ifneq ($(filter go,$(MAKECMDGOALS)),)
WANT_GO := yes
endif
ifneq ($(filter lisp,$(MAKECMDGOALS)),)
WANT_LISP := yes
endif
# Default: both when neither specified
ifeq ($(WANT_GO)$(WANT_LISP),)
WANT_GO := yes
WANT_LISP := yes
endif
GO_TARGETS = $(if $(WANT_GO),$1)
LISP_TARGETS = $(if $(WANT_LISP),$1)
# No-op targets so "make build go" doesn't error on target "go"
.PHONY: go lisp
go lisp:
@:
# ── Common targets ─────────────────────────────────────────────
.PHONY: build test check clean coverage docker release security help
build: $(call GO_TARGETS,go-build) $(call LISP_TARGETS,lisp-build)
test: $(call GO_TARGETS,go-test) $(call LISP_TARGETS,lisp-test)
check: $(call GO_TARGETS,go-check) $(call LISP_TARGETS,lisp-check)
clean: $(call GO_TARGETS,go-clean) $(call LISP_TARGETS,lisp-clean)
coverage: $(call GO_TARGETS,go-coverage) $(call LISP_TARGETS,lisp-coverage)
docker: $(call GO_TARGETS,go-docker) $(call LISP_TARGETS,lisp-docker)
release: $(call GO_TARGETS,go-release) $(call LISP_TARGETS,lisp-release)
security: $(call GO_TARGETS,go-security) $(call LISP_TARGETS,lisp-security)
define SHOUT_HELP
Shout! build system
Usage:
make <target> [go|lisp]
make coverage [go|lisp] [COVERAGE_MIN=N] [COVERAGE_REPORT=full]
make build [go|lisp] [VERSION=x.y.z]
Targets:
build Build binaries
test Run test suites
check Run static analysis
coverage Run coverage with gate
security Run security scanners
docker Build Docker image
release Build release binaries
clean Remove build artifacts
debug-version Print resolved version variables
help Show this help
When go or lisp is omitted, the target runs for both.
Target Go Lisp
------ -- ----
check go fmt + go vet sblint
coverage go tool cover sb-cover expressions
docker linux + darwin multi-arch linux/amd64 only
release Cross-compile all platforms No -dev prerelease tag
security gosec + govulncheck + trivy sblint + trivy
test fmt + vet + race detection prove framework
Variables:
COVERAGE_MIN Gate threshold [default: 50, 0 to disable]
COVERAGE_REPORT Report type [default: gate, full for HTML]
VERSION Override semver version
endef
help:
@$(info $(SHOUT_HELP)):
# ── Go targets ─────────────────────────────────────────────────
VERPKG := $(MODULE)/pkg/version
GO_LDFLAGS = -s -w \
-X '$(VERPKG).SemVerMajor=$(SEMVER_MAJOR)' \
-X '$(VERPKG).SemVerMinor=$(SEMVER_MINOR)' \
-X '$(VERPKG).SemVerPatch=$(SEMVER_PATCH)' \
-X '$(VERPKG).SemVerPrerelease=$(SEMVER_PRERELEASE)' \
-X '$(VERPKG).SemVerBuild=$(SEMVER_BUILDMETA)' \
-X '$(VERPKG).BuildDate=$(BUILD_DATE)' \
-X '$(VERPKG).BuildVcsUrl=$(BUILD_VCS_URL)' \
-X '$(VERPKG).BuildVcsId=$(BUILD_VCS_ID)' \
-X '$(VERPKG).BuildVcsIdDate=$(BUILD_VCS_ID_DATE)'
.PHONY: go-build go-test go-check go-clean go-coverage go-docker
.PHONY: go-release go-security go-help
# dev builds get -dev prerelease tag
go-build: SEMVER_PRERELEASE := $(or $(SEMVER_PRERELEASE),dev)
go-build:
go build -ldflags="$(GO_LDFLAGS)" -o $(NAME) ./cmd/shout
go-test: go-check
go test -race ./cmd/... ./internal/... ./pkg/...
go-check:
go fmt ./...
go vet ./...
go-coverage:
@go test -coverprofile=coverage.out ./cmd/... ./internal/... ./pkg/...
ifeq ($(COVERAGE_REPORT),full)
@go tool cover -func=coverage.out
@go tool cover -html=coverage.out -o coverage.html
@echo "HTML report: coverage.html"
else
@TOTAL=$$(go tool cover -func=coverage.out | grep ^total: | awk '{print $$3}' | tr -d '%'); \
echo "Total coverage: $${TOTAL}%"; \
if [ $(COVERAGE_MIN) -gt 0 ] && [ $$(echo "$${TOTAL} < $(COVERAGE_MIN)" | bc) -eq 1 ]; then \
echo "FAIL: coverage $${TOTAL}% is below $(COVERAGE_MIN)% threshold"; \
exit 1; \
else \
echo "OK: coverage meets $(COVERAGE_MIN)% threshold"; \
fi
endif
go-clean:
rm -f $(NAME) $(NAME)-linux-* $(NAME)-darwin-* coverage.out coverage.html
go-docker:
docker build -t $(NAME):latest .
go-release: go-release-linux-amd64 go-release-linux-arm64 go-release-darwin-amd64 go-release-darwin-arm64
@echo "Go release binaries built:"
@ls -lh $(NAME)-linux-* $(NAME)-darwin-* 2>/dev/null
go-security: go-security-gosec go-security-govulncheck go-security-trivy
go-help:
@echo "Go targets:"
@echo " build Build binary for current platform"
@echo " test Run fmt + vet + tests with race detection"
@echo " check Run go fmt + go vet"
@echo " clean Remove build artifacts and coverage files"
@echo " coverage Coverage gate at COVERAGE_MIN=$(COVERAGE_MIN)% (COVERAGE_REPORT=full for HTML)"
@echo " docker Build Docker image"
@echo " release Cross-compile all platform binaries"
@echo " security Run gosec + govulncheck + trivy"
@echo " debug-version Print resolved version variables"
@echo ""
# ── Go release (cross-compilation) ────────────────────────────
.PHONY: go-release-linux-amd64 go-release-linux-arm64
.PHONY: go-release-darwin-amd64 go-release-darwin-arm64
go-release-linux-amd64:
GOOS=linux GOARCH=amd64 go build -ldflags="$(GO_LDFLAGS)" -o $(NAME)-linux-amd64 ./cmd/shout
go-release-linux-arm64:
GOOS=linux GOARCH=arm64 go build -ldflags="$(GO_LDFLAGS)" -o $(NAME)-linux-arm64 ./cmd/shout
go-release-darwin-amd64:
GOOS=darwin GOARCH=amd64 go build -ldflags="$(GO_LDFLAGS)" -o $(NAME)-darwin-amd64 ./cmd/shout
go-release-darwin-arm64:
GOOS=darwin GOARCH=arm64 go build -ldflags="$(GO_LDFLAGS)" -o $(NAME)-darwin-arm64 ./cmd/shout
# ── Go security scanning ─────────────────────────────────────
.PHONY: go-security-gosec go-security-govulncheck go-security-trivy
go-security-gosec:
gosec ./...
go-security-govulncheck:
govulncheck ./...
go-security-trivy:
trivy fs --scanners vuln,secret,misconfig .
# ── Lisp targets (delegate to lisp/Makefile) ───────────────────
.PHONY: lisp-build lisp-test lisp-check lisp-clean lisp-coverage lisp-docker
.PHONY: lisp-release lisp-security lisp-help
lisp-build:
@$(MAKE) --no-print-directory -C lisp build
lisp-test:
@$(MAKE) --no-print-directory -C lisp test
lisp-check:
@$(MAKE) --no-print-directory -C lisp check
lisp-clean:
@$(MAKE) --no-print-directory -C lisp clean
lisp-coverage:
@$(MAKE) --no-print-directory -C lisp coverage COVERAGE_MIN=$(COVERAGE_MIN) COVERAGE_REPORT=$(COVERAGE_REPORT)
lisp-docker:
@$(MAKE) --no-print-directory -C lisp docker
lisp-release:
@$(MAKE) --no-print-directory -C lisp release
lisp-security:
@$(MAKE) --no-print-directory -C lisp security
lisp-help:
@echo "Lisp targets:"
@echo " build Build standalone executable"
@echo " test Run test suite (prove framework)"
@echo " check Run sblint static analysis"
@echo " clean Remove build artifacts"
@echo " coverage Coverage gate at COVERAGE_MIN=$(COVERAGE_MIN)% (COVERAGE_REPORT=full for HTML)"
@echo " docker Build Docker image (linux/amd64)"
@echo " release Build release executable"
@echo " security Run sblint + trivy"
@echo " debug-version Print resolved version variables"
@echo ""
# ── Version ────────────────────────────────────────────────────
.PHONY: debug-version
debug-version:
@echo "SEMVER_VERSION $(SEMVER_VERSION)"
@echo "SEMVER_MAJOR $(SEMVER_MAJOR)"
@echo "SEMVER_MINOR $(SEMVER_MINOR)"
@echo "SEMVER_PATCH $(SEMVER_PATCH)"
@echo "SEMVER_PRERELEASE $(SEMVER_PRERELEASE)"
@echo "SEMVER_BUILDMETA $(SEMVER_BUILDMETA)"
@echo "BUILD_DATE $(BUILD_DATE)"
@echo "BUILD_VCS_URL $(BUILD_VCS_URL)"
@echo "BUILD_VCS_ID $(BUILD_VCS_ID)"
@echo "BUILD_VCS_ID_DATE $(BUILD_VCS_ID_DATE)"