main
text 110 lines 3.33 KB
Raw
1 .PHONY: help install fmt vet lint lint-auto test vuln tidy all run build build-frontend build-docs build-tunnel build-server clean load-test
2
3 .DEFAULT_GOAL := help
4
5 GO_PACKAGES := ./cmd/... ./portal/... ./sdk/... ./types/...
6 GO_TOOLCHAIN_VERSION := $(shell awk '/^go / { print "go" $$2; exit }' go.mod)
7 GOIMPORTS_VERSION := v0.41.0
8 GOLANGCI_LINT_VERSION := v2.11.1
9 GOVULNCHECK_VERSION := v1.1.4
10
11 export GOTOOLCHAIN := $(GO_TOOLCHAIN_VERSION)
12
13 help:
14 @echo "Available targets:"
15 @echo " make install - Install Go developer tools used by this repo"
16 @echo " make fmt - Apply gofmt/goimports"
17 @echo " make lint-auto - Run autofix lint/format pipeline"
18 @echo " make test - Run Go tests"
19 @echo " make build - Build Go tunnel and relay server artifacts"
20 @echo " make build-frontend - Build React frontend (Tailwind CSS 4)"
21 @echo " make build-docs - Build documentation site (SvelteKit)"
22 @echo " make build-tunnel - Build portal-tunnel binaries"
23 @echo " make build-server - Build Go relay server"
24 @echo " make run - Run relay server"
25 @echo " make clean - Remove build artifacts"
26
27 install:
28 go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
29 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
30 go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)
31
32 fmt:
33 gofmt -w .
34 goimports -w .
35
36 vet:
37 go vet $(GO_PACKAGES)
38
39 lint:
40 golangci-lint run $(GO_PACKAGES)
41
42 lint-auto:
43 gofmt -w .
44 goimports -w .
45 golangci-lint run --fix $(GO_PACKAGES)
46
47 test:
48 go test -v -coverprofile=coverage.out $(GO_PACKAGES)
49
50 vuln:
51 govulncheck $(GO_PACKAGES)
52
53 tidy:
54 go get -u ./...
55 go mod tidy
56 go mod verify
57
58 all: fmt vet lint test vuln build
59
60 run:
61 ./bin/relay-server
62
63 # Convenience target
64 build: build-tunnel build-server
65
66 # Build React frontend with Tailwind CSS 4
67 build-frontend:
68 @echo "[frontend] building React frontend..."
69 @cd frontend && npm i && npm run build
70 @echo "[frontend] build complete"
71
72 # Build documentation site
73 build-docs:
74 @echo "[docs] building documentation site..."
75 @cd docs && bun install --frozen-lockfile && bun run build
76 @echo "[docs] build complete"
77
78 # Build portal-tunnel binaries for installer distribution
79 build-tunnel:
80 @echo "[tunnel] building portal-tunnel binaries..."
81 @mkdir -p cmd/relay-server/dist/tunnel
82 @for GOOS in linux darwin windows; do \
83 for GOARCH in amd64 arm64; do \
84 EXT=""; \
85 if [ "$${GOOS}" = "windows" ]; then EXT=".exe"; fi; \
86 OUT="cmd/relay-server/dist/tunnel/portal-$${GOOS}-$${GOARCH}$${EXT}"; \
87 echo " - $${OUT}"; \
88 CGO_ENABLED=0 GOOS=$${GOOS} GOARCH=$${GOARCH} go build -trimpath -ldflags "-s -w" -o "$${OUT}" ./cmd/portal-tunnel; \
89 done; \
90 done
91
92 # Build Go relay server
93 build-server:
94 @echo "[server] building Go portal..."
95 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o bin/relay-server ./cmd/relay-server
96
97 clean:
98 rm -rf bin
99 rm -rf cmd/relay-server/dist/tunnel
100 rm -rf frontend/dist
101
102 # Run the uniformity probe. Extra flags are passed through after the target name:
103 # make load-test -- -clients 1000 -relays 5
104 # GNU make consumes '--' and forwards remaining goals; the catch-all '%:' rule
105 # below silently absorbs them so make does not error with "no rule to make target."
106 load-test:
107 go run ./cmd/portal-loadtest $(filter-out $@,$(MAKECMDGOALS))
108
109 %:
110 @: