forked from songquanpeng/one-api
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (103 loc) · 4.51 KB
/
Copy pathMakefile
File metadata and controls
122 lines (103 loc) · 4.51 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
.PHONY: install
install:
# https://golangci-lint.run/docs/welcome/install/local/
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.10.1
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
# go install go.uber.org/nilaway/cmd/nilaway@latest
# go install github.com/mitranim/gow@latest
# go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
.PHONY: lint
GO_FILE_FIND = find . \
-path './.git' -prune -o \
-path './node_modules' -prune -o \
-path './web/*/node_modules' -prune -o \
-path './web/build' -prune -o \
-path './.mypy_cache' -prune -o \
-name '*.go' -print0
lint:
$(GO_FILE_FIND) | xargs -0 -n 50 goimports -local module,github.com/Laisky/one-api -w
go mod tidy
$(GO_FILE_FIND) | xargs -0 -n 50 gofmt -s -w
go vet ./...
# nilaway ./...
golangci-lint run -c .golangci.yml
govulncheck ./...
$(MAKE) lint-goroutine-guard
$(MAKE) lint-entity-response
# lint-goroutine-guard enforces the structural rule that no background goroutine may
# reference the request *gin.Context (gin recycles it via sync.Pool after the handler
# returns). See .ast-grep/rules/no-gin-context-in-goroutine.yml and
# docs/proposals/20260608_relay-billing-async-sync-race-fixes.md.
# Requires ast-grep (install: `pipx install ast-grep-cli`, `cargo install ast-grep --locked`,
# or a prebuilt binary from https://github.com/ast-grep/ast-grep/releases); skips gracefully
# when not installed.
.PHONY: lint-goroutine-guard
lint-goroutine-guard:
@command -v ast-grep >/dev/null 2>&1 || { echo "ast-grep not installed; skipping goroutine *gin.Context guardrail (install: pipx install ast-grep-cli, or a prebuilt binary from https://github.com/ast-grep/ast-grep/releases)"; exit 0; }
ast-grep test --skip-snapshot-tests
ast-grep scan
# lint-entity-response enforces the boundary rule that no management-API entity
# (model.User/Token/Channel/Redemption/Log) is serialized raw at the HTTP
# boundary. It is a type-aware go/analysis analyzer (ast-grep is syntactic and
# cannot see that gin.H{"data": users} carries []*model.User). See
# tools/analyzers/noentityresponse and docs/proposals/20260714_boundary-response-dtos.md.
.PHONY: lint-entity-response
lint-entity-response:
go run ./tools/analyzers/noentityresponse/cmd/noentityresponse ./...
# Development targets - Template specific
.PHONY: dev-air dev-berry dev-modern
dev-air:
@./web/air/dev.sh dev
dev-berry:
@./web/berry/dev.sh dev
dev-modern:
@cd web/modern && CHOKIDAR_USEPOLLING=$${CHOKIDAR_USEPOLLING:-1} CHOKIDAR_INTERVAL=$${CHOKIDAR_INTERVAL:-1000} yarn dev
# Default dev target
.PHONY: dev
dev: dev-modern
# Build targets - Template specific
.PHONY: build-frontend-air build-frontend-berry build-frontend-modern
build-frontend-air:
@./web/air/dev.sh build
build-frontend-berry:
@./web/berry/dev.sh build
build-frontend-modern:
@cd web/modern && yarn && yarn build
# Default build target
.PHONY: build-frontend
build-frontend: build-frontend-modern
# Build development versions - Template specific
.PHONY: build-frontend-dev-air build-frontend-dev-berry build-frontend-dev-modern
build-frontend-dev-air:
@./web/air/dev.sh build-dev
build-frontend-dev-berry:
@./web/berry/dev.sh build-dev
build-frontend-dev-modern:
@cd web/modern && yarn run build
# Default dev build target
.PHONY: build-frontend-dev
build-frontend-dev: build-frontend-dev-modern
# Build all templates
.PHONY: build-all-templates
build-all-templates: build-frontend-air build-frontend-berry build-frontend-modern
# Help target
.PHONY: help-dev
help-dev:
@echo "Development targets:"
@echo " dev-air Start air template development server (port 3002)"
@echo " dev-berry Start berry template development server (port 3003)"
@echo " dev-modern Start modern template development server (port 3001)"
@echo " dev Start modern template development server (default)"
@echo ""
@echo "Build targets:"
@echo " build-frontend-air Build air template for production"
@echo " build-frontend-berry Build berry template for production"
@echo " build-frontend-modern Build modern template for production"
@echo " build-all-templates Build all templates for production"
@echo ""
@echo "Development build targets:"
@echo " build-frontend-dev-air Build air template for development"
@echo " build-frontend-dev-berry Build berry template for development"
@echo " build-frontend-dev-modern Build modern template for development"