-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (127 loc) · 4.37 KB
/
Copy pathMakefile
File metadata and controls
153 lines (127 loc) · 4.37 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
# Forge — Makefile (DEV-M0-01)
#
# Single entry point for contributors and CI. Per ADR-001 the toolchain is Go
# (CGO_ENABLED=0 default). Per DEV-M0-01 acceptance, `make build` must succeed
# on a fresh clone with no extra setup beyond Go + the tools listed in
# `make tools`.
GO ?= go
GOFLAGS ?=
PKG ?= ./...
BIN_DIR ?= dist
BIN_NAME ?= forge
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo 0.0.0-dev)
LDFLAGS ?= -s -w -X main.Version=$(VERSION)
CGO_ENABLED ?= 0
export CGO_ENABLED
.PHONY: all
all: lint test build
.PHONY: build
build:
$(GO) build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BIN_DIR)/$(BIN_NAME) ./cmd/forge
.PHONY: test
test:
$(GO) test -race -count=1 $(PKG)
.PHONY: test-short
test-short:
$(GO) test -race -short -count=1 $(PKG)
.PHONY: cover
cover:
$(GO) test -race -coverprofile=coverage.out -covermode=atomic $(PKG)
$(GO) tool cover -func=coverage.out | tail -n 1
.PHONY: lint
lint:
golangci-lint run ./...
.PHONY: fmt
fmt:
gofmt -s -w .
goimports -w .
.PHONY: fmt-check
fmt-check:
@if [ -n "$$(gofmt -s -l .)" ]; then \
echo 'gofmt -s violations:'; gofmt -s -l .; exit 1; \
fi
@if [ -n "$$(goimports -l .)" ]; then \
echo 'goimports violations:'; goimports -l .; exit 1; \
fi
.PHONY: vuln
vuln:
govulncheck ./...
.PHONY: tidy
tidy:
$(GO) mod tidy
$(GO) mod verify
# Cross-compile matrix (DEV-M0-01 TC-01-06): 6 binaries, CGO_ENABLED=0.
.PHONY: cross
cross:
@set -e; \
for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do \
os=$${target%/*}; arch=$${target#*/}; \
ext=""; if [ "$$os" = "windows" ]; then ext=".exe"; fi; \
out=$(BIN_DIR)/$(BIN_NAME)-$$os-$$arch$$ext; \
echo "==> $$out"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 \
$(GO) build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $$out ./cmd/forge; \
done
.PHONY: tools
tools:
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GO) install golang.org/x/vuln/cmd/govulncheck@latest
$(GO) install golang.org/x/tools/cmd/goimports@latest
$(GO) install gotest.tools/gotestsum@latest
$(GO) install github.com/goreleaser/goreleaser/v2@latest
# ── npm distribution ──────────────────────────────────────────────────────────
# Build a local snapshot with goreleaser (no tag / GitHub token needed).
# Produces dist/ with all 5 platform binaries.
.PHONY: release-snapshot
release-snapshot:
goreleaser build --snapshot --clean
# Regenerate CHANGELOG.md from conventional-commit history (DEV-M0-31).
# Requires goreleaser >=2.0. Optionally scope with TAG=vX.Y.Z.
# Usage:
# make changelog — regenerate from last tag to HEAD
# make changelog TAG=v0.9.0 — regenerate from that tag to HEAD
.PHONY: changelog
changelog:
goreleaser changelog --output CHANGELOG.md $(if $(TAG),--tag $(TAG),)
# Copy snapshot binaries into packages/ and stamp package.json versions.
# Does NOT publish — use this for local inspection.
.PHONY: npm-stage
npm-stage: release-snapshot
bash scripts/npm-publish.sh --version $(VERSION) --dry-run true
# Full release: tag first, then push — CI picks it up and runs goreleaser + npm publish.
# Usage: make tag VERSION=1.2.3
.PHONY: tag
tag:
@if [ -z "$(VERSION)" ]; then echo "Usage: make tag VERSION=x.y.z" >&2; exit 1; fi
git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
@echo "Tag v$(VERSION) created. Push with: git push origin v$(VERSION)"
# Register the repo's own git hooks (runs once per clone after `make tools`).
.PHONY: hooks
hooks:
git config core.hooksPath .githooks
@echo "pre-push hook active — checks: fmt, vet, lint, build, test, vuln, mod verify, forge qa"
# Run the real-command QA integration suite against a throwaway project.
.PHONY: qa
qa: build
bash scripts/forge-qa-real.sh
# Run every quality gate locally in the same order as the pre-push hook.
.PHONY: check
check: fmt-check
$(GO) vet $(PKG)
golangci-lint run ./...
CGO_ENABLED=0 $(GO) build $(PKG)
$(GO) test -count=1 $(PKG)
govulncheck ./...
$(GO) mod verify
.PHONY: docs
docs:
$(GO) run ./cmd/gen-errors --out docs/ERROR_CODES.md
.PHONY: docs-check
docs-check:
$(GO) run ./cmd/gen-errors --out docs/ERROR_CODES.md --check
.PHONY: bench
bench:
$(GO) test -bench=. -benchmem -run='^$$' ./...
.PHONY: clean
clean:
rm -rf $(BIN_DIR) coverage.out