-
Notifications
You must be signed in to change notification settings - Fork 594
Expand file tree
/
Copy pathMakefile
More file actions
333 lines (294 loc) · 10.9 KB
/
Copy pathMakefile
File metadata and controls
333 lines (294 loc) · 10.9 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# App-Store-Connect-CLI Makefile
# Variables
BINARY_NAME := asc
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Keep local build metadata stable so unchanged builds can reuse Go's link cache.
# Release builds set their actual build timestamp in the release workflow.
DATE := $(shell git show -s --format=%cI HEAD 2>/dev/null || echo "unknown")
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
# Release builds strip symbol/DWARF tables (-s -w) and file-system paths
# (-trimpath) for smaller, reproducible binaries. Dev builds (`make build`)
# stay unstripped for debuggability.
RELEASE_LDFLAGS := -s -w $(LDFLAGS)
RELEASE_BUILD_FLAGS := -trimpath
# Go variables
GO := go
GOMOD := go.mod
GOBIN := $(shell $(GO) env GOPATH)/bin
GO_TOOLCHAIN_VERSION := $(shell $(GO) env GOVERSION)
# Cold hosted runners can require more than ten minutes for the full-module lint.
GOLANGCI_LINT_TIMEOUT ?= 15m
INSTALL_PREFIX ?= /usr/local/bin
GOFUMPT_VERSION ?= v0.10.0
GOLANGCI_LINT_VERSION ?= v2.12.1
GOVULNCHECK_VERSION ?= v1.6.0
# Directories
SRC_DIR := .
BUILD_DIR := build
DIST_DIR := dist
RELEASE_DIR := release
# Colors
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m # No Color
# Default target
.PHONY: all
all: build
# Build the binary
.PHONY: build
build:
@echo "$(BLUE)Building $(BINARY_NAME)...$(NC)"
$(GO) build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) .
@echo "$(GREEN)✓ Build complete: $(BINARY_NAME)$(NC)"
# Build release-style binaries for supported platforms
.PHONY: build-all
build-all: clean
@echo "$(BLUE)Building for multiple platforms...$(NC)"
@mkdir -p "$(RELEASE_DIR)"
@for target in "darwin amd64 macOS" "darwin arm64 macOS" "linux amd64 linux" "linux arm64 linux" "windows amd64 windows"; do \
set -- $$target; \
os="$$1"; arch="$$2"; label="$$3"; suffix=""; \
if [ "$$os" = "windows" ]; then suffix=".exe"; fi; \
if [ "$$os" = "darwin" ]; then cgo="1"; else cgo="0"; fi; \
echo "Building $$label/$$arch..."; \
CGO_ENABLED="$$cgo" GOOS="$$os" GOARCH="$$arch" $(GO) build $(RELEASE_BUILD_FLAGS) -ldflags "$(RELEASE_LDFLAGS)" -o "$(RELEASE_DIR)/$(BINARY_NAME)_$(VERSION)_$${label}_$${arch}$${suffix}" . || exit $$?; \
done
@echo "$(GREEN)✓ Release binaries written to $(RELEASE_DIR)/$(NC)"
# Build with debug symbols
.PHONY: build-debug
build-debug:
$(GO) build -gcflags="all=-N -l" -o $(BINARY_NAME)-debug .
# Run tests
.PHONY: test
test:
@echo "$(BLUE)Running tests...$(NC)"
ASC_BYPASS_KEYCHAIN=1 $(GO) test -v ./...
# Run tests with parallel package compilation
# Defaults to GOMAXPROCS; set PARALLEL to override (e.g. PARALLEL=4)
.PHONY: test-parallel
test-parallel:
@echo "$(BLUE)Running tests (parallel=$(or $(PARALLEL),auto))...$(NC)"
ASC_BYPASS_KEYCHAIN=1 $(GO) test -v -count=1 $(if $(PARALLEL),-p=$(PARALLEL)) ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "$(BLUE)Running tests with coverage...$(NC)"
ASC_BYPASS_KEYCHAIN=1 $(GO) test -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)Coverage report: coverage.html$(NC)"
# Run integration tests (opt-in)
.PHONY: test-integration
test-integration:
@echo "$(BLUE)Running integration tests (requires ASC_* env vars)...$(NC)"
$(GO) test -tags=integration -v ./internal/asc -run Integration
# Lint the code
.PHONY: lint
lint:
@echo "$(BLUE)Linting code...$(NC)"
@if command -v golangci-lint >/dev/null 2>&1; then \
GOLANGCI_LINT_CACHE="$(CURDIR)/.golangci-cache" golangci-lint run --timeout=$(GOLANGCI_LINT_TIMEOUT) ./...; \
else \
echo "$(YELLOW)golangci-lint not found; falling back to 'go vet ./...'.$(NC)"; \
echo "$(YELLOW)Install with: make tools (or: GOTOOLCHAIN=$(GO_TOOLCHAIN_VERSION) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest)$(NC)"; \
$(GO) vet ./...; \
fi
# Format code
.PHONY: format
format:
@echo "$(BLUE)Formatting code...$(NC)"
@if ! command -v gofumpt >/dev/null 2>&1; then \
echo "$(YELLOW)gofumpt not found; install with: make tools (or: $(GO) install mvdan.cc/gofumpt@latest)$(NC)"; \
exit 1; \
fi
$(GO) fmt ./...
gofumpt -w .
.PHONY: format-check
format-check:
@echo "$(BLUE)Checking formatting (no writes)...$(NC)"
@if ! command -v gofumpt >/dev/null 2>&1; then \
echo "$(YELLOW)gofumpt not found; install with: make tools (or: $(GO) install mvdan.cc/gofumpt@latest)$(NC)"; \
exit 1; \
fi
@unformatted_gofmt="$$(gofmt -l .)"; \
unformatted_gofumpt="$$(gofumpt -l .)"; \
if [ -n "$$unformatted_gofmt" ] || [ -n "$$unformatted_gofumpt" ]; then \
echo "Formatting issues detected."; \
if [ -n "$$unformatted_gofmt" ]; then \
echo "gofmt:"; \
echo "$$unformatted_gofmt"; \
fi; \
if [ -n "$$unformatted_gofumpt" ]; then \
echo "gofumpt:"; \
echo "$$unformatted_gofumpt"; \
fi; \
exit 1; \
fi
# Install dev tools
.PHONY: tools
tools:
@echo "$(BLUE)Installing dev tools...$(NC)"
$(GO) install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
GOTOOLCHAIN=$(GO_TOOLCHAIN_VERSION) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@echo "$(GREEN)✓ Tools installed$(NC)"
@echo "$(YELLOW)Make sure '$(GOBIN)' is on your PATH$(NC)"
.PHONY: install-govulncheck
install-govulncheck:
$(GO) install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)
# Install local git hooks
.PHONY: install-hooks
install-hooks:
@echo "$(BLUE)Installing git hooks...$(NC)"
git config core.hooksPath .githooks
chmod +x .githooks/pre-commit
@echo "$(GREEN)✓ Hooks installed (core.hooksPath=.githooks)$(NC)"
# Install dependencies
.PHONY: deps
deps:
@echo "$(BLUE)Installing dependencies...$(NC)"
$(GO) mod download
$(GO) mod tidy
# Update dependencies
.PHONY: update-deps
update-deps:
@echo "$(BLUE)Updating dependencies...$(NC)"
$(GO) get -u ./...
$(GO) mod tidy
# Update OpenAPI index
.PHONY: update-openapi
update-openapi:
@echo "$(BLUE)Updating OpenAPI paths index...$(NC)"
python3 scripts/update-openapi-index.py
.PHONY: update-schema-index
update-schema-index:
@echo "$(BLUE)Updating schema index...$(NC)"
python3 scripts/generate-schema-index.py
# Generate docs/COMMANDS.md from live CLI help
.PHONY: generate-command-docs
generate-command-docs:
@echo "$(BLUE)Generating command docs...$(NC)"
python3 ./scripts/generate-command-docs.py
# Validate docs command lists against live CLI output
.PHONY: check-command-docs
check-command-docs:
@echo "$(BLUE)Checking command docs sync...$(NC)"
python3 ./scripts/test_generate_command_docs.py
python3 ./scripts/generate-command-docs.py --check
python3 ./scripts/check-commands-docs.py
.PHONY: check-repo-docs
check-repo-docs:
@echo "$(BLUE)Checking repository docs links...$(NC)"
python3 ./scripts/check_repo_docs.py
.PHONY: check-website-docs
check-website-docs:
@echo "$(BLUE)Checking Mintlify website docs...$(NC)"
python3 ./scripts/check_website_docs.py
python3 ./scripts/check_website_commands.py
.PHONY: check-agent-skills
check-agent-skills:
@echo "$(BLUE)Checking repository agent skills...$(NC)"
python3 ./scripts/test_check_agent_skills.py
python3 ./scripts/check_agent_skills.py
.PHONY: check-openapi
check-openapi:
@echo "$(BLUE)Checking OpenAPI generated artifacts...$(NC)"
python3 ./scripts/test_update_openapi_index.py
python3 ./scripts/test_generate_schema_index.py
python3 ./scripts/update-openapi-index.py --check
python3 ./scripts/generate-schema-index.py --check
.PHONY: check-docs
check-docs: check-command-docs check-repo-docs check-website-docs check-agent-skills check-openapi
.PHONY: check-wall-of-apps
check-wall-of-apps:
@echo "$(BLUE)Checking Wall of Apps source...$(NC)"
$(GO) test ./internal/cli/apps -run TestCommunityWallSourceFileIsCanonical -count=1
# Clean build artifacts
.PHONY: clean
clean:
@echo "$(BLUE)Cleaning...$(NC)"
rm -f $(BINARY_NAME) $(BINARY_NAME)-debug
rm -rf $(BUILD_DIR) $(DIST_DIR) "$(RELEASE_DIR)"
rm -f coverage.out coverage.html
# Install the binary
.PHONY: install
install: build
@echo "$(BLUE)Installing to $(INSTALL_PREFIX)...$(NC)"
install -d $(INSTALL_PREFIX)
install -m 755 $(BINARY_NAME) $(INSTALL_PREFIX)/$(BINARY_NAME)
# Uninstall the binary
.PHONY: uninstall
uninstall:
@echo "$(BLUE)Uninstalling...$(NC)"
rm -f $(INSTALL_PREFIX)/$(BINARY_NAME)
# Run the CLI locally
.PHONY: run
run: build
@echo "$(BLUE)Running locally...$(NC)"
./$(BINARY_NAME) --help
# Create a release
.PHONY: release
release: clean
@echo "$(BLUE)Creating release...$(NC)"
@echo "$(YELLOW)Note: Use GitHub Actions for releases$(NC)"
# Run the non-publishing checks used by the release rehearsal workflow
.PHONY: release-guardrails
release-guardrails:
python3 scripts/test_release_rehearsal.py
python3 scripts/test_check_docs.py
$(MAKE) format-check
$(MAKE) check-docs
$(MAKE) check-wall-of-apps
$(MAKE) lint
ASC_BYPASS_KEYCHAIN=1 $(MAKE) test
# Show help
.PHONY: help
help:
@echo ""
@echo "$(GREEN)App-Store-Connect-CLI$(NC) - Build System"
@echo ""
@echo "Targets:"
@echo " build Build the binary"
@echo " build-all Build release binaries for supported platforms"
@echo " build-debug Build with debug symbols"
@echo " test Run tests"
@echo " test-parallel Run tests with optional package parallelism (PARALLEL=<n>)"
@echo " test-coverage Run tests with coverage"
@echo " test-integration Run opt-in integration tests"
@echo " lint Lint the code"
@echo " format Format code"
@echo " format-check Check formatting without writing files"
@echo " tools Install dev tools"
@echo " install-govulncheck Install the pinned vulnerability scanner"
@echo " install-hooks Install local git hooks"
@echo " deps Install dependencies"
@echo " update-deps Update dependencies"
@echo " update-openapi Update OpenAPI paths index"
@echo " update-schema-index Update runtime schema index"
@echo " generate-command-docs Generate docs/COMMANDS.md from live CLI help"
@echo " check-command-docs Validate docs command lists against live CLI help"
@echo " check-repo-docs Validate local links in repository markdown docs"
@echo " check-website-docs Validate Mintlify website navigation, links, and CLI examples"
@echo " check-agent-skills Validate repository-scoped Codex skills"
@echo " check-openapi Validate generated OpenAPI indexes"
@echo " check-docs Run all documentation checks"
@echo " release-guardrails Run non-publishing release checks"
@echo " clean Clean build artifacts"
@echo " install Install binary"
@echo " uninstall Uninstall binary"
@echo " run Run CLI locally"
@echo " help Show this help"
@echo ""
# Development shortcuts
.PHONY: dev
dev: format lint test build
@echo "$(GREEN)✓ Ready for development!$(NC)"
# Check for security vulnerabilities
.PHONY: security
security:
@echo "$(BLUE)Checking for security vulnerabilities...$(NC)"
@if command -v gosec > /dev/null 2>&1; then \
gosec ./...; \
else \
echo "$(YELLOW)Install gosec for security checks$(NC)"; \
fi