-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (140 loc) · 6.62 KB
/
Copy pathMakefile
File metadata and controls
164 lines (140 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
BINARY := nself
MODULE := github.com/nself-org/cli
DIST_DIR := dist
VERSION := $(shell cat .github/VERSION 2>/dev/null || git describe --tags 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
NSELF_LICENSE_PUBKEY_HEX ?=
LDFLAGS := -s -w \
-X $(MODULE)/internal/version.Version=$(VERSION) \
-X $(MODULE)/internal/version.Commit=$(COMMIT) \
-X $(MODULE)/internal/version.BuildDate=$(BUILD_DATE) \
-X $(MODULE)/internal/license.licensePubKeyHex=$(NSELF_LICENSE_PUBKEY_HEX)
BUILDFLAGS := -trimpath
.PHONY: build clean test vet install cross dist verify-prod sport-f21 sport-f02 cmd-inventory core-services wiki-commands wiki-check flag-drift-audit parity sbom man fmt fmt-check
verify-prod:
@bash scripts/prod-verify/p87-verification.sh
sport-f21:
@bash scripts/sport/generate-f21.sh
## cmd-inventory — CLI-R06. Regenerate the command inventory from the cobra tree.
## Writes .github/command-inventory.json and .github/wiki/COMMANDS.md.
## Set NSELF_SPORT_DIR to also refresh SPORT F02 (it lives in the PPI, not here).
## internal/repoqa asserts the committed copies match, so run this after adding,
## renaming, or removing any command.
cmd-inventory:
@bash scripts/sport/generate-f02.sh
sport-f02: cmd-inventory
## core-services — CLI-R07. Regenerate .github/wiki/Core-Services.md from the
## compose service catalog. Set NSELF_SPORT_DIR to also refresh SPORT F08.
core-services:
@bash scripts/sport/generate-core-services.sh
## wiki-commands — CLI-R08. Regenerate one wiki page per top-level command, plus
## the sidebar index and llms.txt. Human prose inside PROSE blocks is preserved;
## only the cobra-derived parts are rewritten. Use -report to list pages that
## still carry placeholder prose.
wiki-commands:
@CGO_ENABLED=0 go run -mod=vendor ./tools/wikigen -report
## wiki-check — verify the wiki is current and every [[link]] resolves.
wiki-check:
@CGO_ENABLED=0 go run -mod=vendor ./tools/wikigen -check
@bash scripts/ci/wiki-link-audit.sh
## flag-drift-audit — checks every `nself <path> --flag` invocation in
## .github/wiki/ and scripts/ against the live cobra tree, so a documented or
## scripted flag that was never registered on the command it names fails the
## build instead of shipping silently (see scripts/ci/flag-drift-audit.sh).
flag-drift-audit:
@bash scripts/ci/flag-drift-audit.sh
## mcp-docs — CLI-R15. Print the current MCP tool/resource/prompt list,
## generated from cmd/commands/mcp*.go — paste into cmd-mcp.md's PROSE blocks
## by hand after adding/removing a tool, resource, or prompt.
mcp-docs:
@CGO_ENABLED=0 go run -mod=vendor ./tools/mcpdoc
## parity — CLI-R17. Regenerate the four-surface parity matrix (wiki page, MCP
## tool, env var docs, OpenAPI route) for every top-level command. Writes
## .github/surface-parity.md and .github/surface-parity.json. internal/repoqa
## asserts the committed copies match; run this after adding, renaming, or
## removing a command, an MCP tool, or an env var.
parity:
@CGO_ENABLED=0 go run -mod=vendor ./tools/parity
## Q04 — SBOM generation (local dev target)
## Requires: syft (https://github.com/anchore/syft)
## Generates sbom.spdx.json (SPDX) and sbom.cdx.json (CycloneDX 1.5) from the source tree.
## Run `make sbom` before a release to verify SBOM generation works locally.
sbom:
@echo "Checking for syft..."
@if ! command -v syft >/dev/null 2>&1; then \
echo "syft not found. Install via:"; \
echo " curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin"; \
exit 1; \
fi
@echo "Generating SPDX SBOM..."
@syft packages . --output spdx-json=sbom.spdx.json
@echo "Generating CycloneDX 1.5 SBOM (Q04)..."
@syft packages . --output cyclonedx-json=sbom.cdx.json
@echo ""
@echo "SBOMs written:"
@echo " sbom.spdx.json (SPDX 2.3) $$(wc -c < sbom.spdx.json) bytes"
@echo " sbom.cdx.json (CycloneDX 1.5) $$(wc -c < sbom.cdx.json) bytes"
@echo ""
@echo "Verify a release SBOM signature:"
@echo " bash tools/sbom/verify.sh v$(VERSION)"
@echo ""
@echo "Query SBOM for a package:"
@echo " bash tools/sbom/query.sh --local sbom.cdx.json --pkg cobra"
## man — generate man pages for all nself commands into ./man/
man: build
@mkdir -p man
@./$(BINARY) man --output man
@echo "Man pages written to man/"
build:
CGO_ENABLED=0 go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(BINARY) ./cmd/nself/
install: build
cp $(BINARY) /usr/local/bin/$(BINARY)
clean:
rm -f $(BINARY)
rm -rf $(DIST_DIR)
test:
CGO_ENABLED=0 go test -mod=vendor ./...
vet:
CGO_ENABLED=0 go vet -mod=vendor ./...
## fmt — format all first-party Go source (cmd/ internal/ tools/).
fmt:
gofmt -w cmd internal tools
## fmt-check — CLI-R01 gate. Same script CI runs; fails on any unformatted file.
fmt-check:
@bash scripts/ci/gofmt-check.sh
cross: cross-linux cross-darwin
cross-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(BINARY)-linux-amd64 ./cmd/nself/
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(BINARY)-linux-arm64 ./cmd/nself/
cross-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(BINARY)-darwin-amd64 ./cmd/nself/
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(BINARY)-darwin-arm64 ./cmd/nself/
dist:
@mkdir -p $(DIST_DIR)
@for platform in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do \
os=$$(echo $$platform | cut -d/ -f1); \
arch=$$(echo $$platform | cut -d/ -f2); \
name=$(BINARY)-$(VERSION)-$$os-$$arch; \
echo "Building $$os/$$arch..."; \
mkdir -p $(DIST_DIR)/$$name; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/$$name/$(BINARY) ./cmd/nself/; \
cp README.md LICENSE $(DIST_DIR)/$$name/; \
tar -czf $(DIST_DIR)/$$name.tar.gz -C $(DIST_DIR) $$name; \
rm -rf $(DIST_DIR)/$$name; \
done
@for arch in amd64 arm64; do \
name=$(BINARY)-$(VERSION)-windows-$$arch; \
echo "Building windows/$$arch..."; \
mkdir -p $(DIST_DIR)/$$name; \
CGO_ENABLED=0 GOOS=windows GOARCH=$$arch go build $(BUILDFLAGS) -mod=vendor -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/$$name/$(BINARY).exe ./cmd/nself/; \
cp README.md LICENSE $(DIST_DIR)/$$name/; \
cd $(DIST_DIR) && zip -qr $$name.zip $$name && cd ..; \
rm -rf $(DIST_DIR)/$$name; \
done
@cd $(DIST_DIR) && if command -v sha256sum >/dev/null 2>&1; then \
sha256sum *.tar.gz *.zip > checksums.txt; \
else \
shasum -a 256 *.tar.gz *.zip > checksums.txt; \
fi
@echo "dist/ ready."