-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
184 lines (157 loc) · 4.61 KB
/
Copy pathTaskfile.yml
File metadata and controls
184 lines (157 loc) · 4.61 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
version: '3'
vars:
BINARY: codex-api-gateway
CONFIG: config.yaml
# 默认取 git 描述(去掉 tag 的 v 前缀,管理页展示时统一加 v);CI/手动可覆盖:task build VERSION=1.2.3
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null | sed 's/^v//'
LDFLAGS: -w -s -X main.version={{.VERSION}}
tasks:
default:
desc: Run task check
cmds:
- task: check
build:
desc: Build the server binary
cmds:
- go build -ldflags '{{.LDFLAGS}}' -o {{.BINARY}} ./cmd/server
cli:
desc: Build all cli binaries for all platforms
deps:
- cli-linux-amd64
- cli-linux-arm64
- cli-darwin-amd64
- cli-darwin-arm64
- cli-windows-amd64
- cli-windows-arm64
build-cross:
internal: true
cmds:
- mkdir -p bin
# CGO_ENABLED=0:交叉编译无法用宿主 gcc;全仓依赖均纯 Go(D-Bus 走 socket)。
- CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags '{{.LDFLAGS}}' -o bin/{{.BINARY}}-{{.GOOS}}-{{.GOARCH}}{{.EXT}} ./cmd/server
cli-linux-amd64:
desc: Build cli binary for linux amd64
cmds:
- task: build-cross
vars: { GOOS: linux, GOARCH: amd64 }
cli-linux-arm64:
desc: Build cli binary for linux arm64
cmds:
- task: build-cross
vars: { GOOS: linux, GOARCH: arm64 }
cli-darwin-amd64:
desc: Build cli binary for darwin amd64
cmds:
- task: build-cross
vars: { GOOS: darwin, GOARCH: amd64 }
cli-darwin-arm64:
desc: Build cli binary for darwin arm64
cmds:
- task: build-cross
vars: { GOOS: darwin, GOARCH: arm64 }
cli-windows-amd64:
desc: Build cli binary for windows amd64
cmds:
- task: build-cross
vars: { GOOS: windows, GOARCH: amd64, EXT: .exe }
cli-windows-arm64:
desc: Build cli binary for windows arm64
cmds:
- task: build-cross
vars: { GOOS: windows, GOARCH: arm64, EXT: .exe }
run:
desc: Run the server (requires {{.CONFIG}})
cmds:
- go run ./cmd/server -config {{.CONFIG}}
up:
desc: 后台启动(-d,类似 docker compose up -d);已在跑则先不动
deps: [build]
cmds:
- |
set -e
f=${GATEWAY_PID_FILE:-gateway.pid}
if [ -f "$f" ] && ps -p "$(tr -dc 0-9 < "$f")" >/dev/null 2>&1; then
echo "up: already running pid=$(cat "$f")"
exit 0
fi
./{{.BINARY}} -config {{.CONFIG}} -d
stop:
desc: kill gateway.pid 指向的进程(无文件/进程不在也不失败)
cmds:
- sh -c 'f=${GATEWAY_PID_FILE:-gateway.pid}; p=$(cat "$f" 2>/dev/null) && /bin/kill "$p"; rm "$f" 2>/dev/null; true'
restart:
desc: stop 后后台启动(build + -d);等待 /v1/models 与 gateway.pid
cmds:
- task: stop
- task: build
- |
set -e
PORT=$(grep -E '^[[:space:]]*listen:' {{.CONFIG}} | head -1 | sed -E 's/.*:([0-9]+).*/\1/')
PORT=${PORT:-8383}
./{{.BINARY}} -config {{.CONFIG}} -d
code=000
for _ in $(seq 1 80); do
code=$(curl -sS -o /dev/null -w '%{http_code}' --connect-timeout 1 "http://127.0.0.1:${PORT}/v1/models" 2>/dev/null || echo 000)
if [ "$code" = "200" ] && [ -f "${GATEWAY_PID_FILE:-gateway.pid}" ]; then
echo "restart: OK http=200 pid=$(cat ${GATEWAY_PID_FILE:-gateway.pid})"
exit 0
fi
sleep 0.25
done
echo "restart: FAIL last_http=$code" >&2
exit 1
test:
desc: Run all tests
cmds:
- go test ./...
test-race:
desc: Run all tests with race detector
cmds:
- go test -race ./...
test-verbose:
desc: Run all tests verbose
cmds:
- go test -v ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
fmt:
desc: Format go code
cmds:
- gofmt -w cmd/ internal/
fmt-check:
desc: Check go code format
cmds:
- gofmt -l cmd/ internal/ | diff - /dev/null
tidy:
desc: go mod tidy
cmds:
- go mod tidy
cover:
desc: Generate coverage report
cmds:
- go test -coverprofile=coverage.out ./...
- go tool cover -func=coverage.out
check:
desc: Run all check before commit
deps:
- fmt-check
- vet
- test
cmds: []
smoke:
desc: Smoke test binary
deps: [build]
cmds:
- ./{{.BINARY}} -config {{.CONFIG}}
install-autostart:
desc: 安装桌面自启(~/.config/autostart + applications)
deps: [build]
cmds:
- ./packaging/install-autostart.sh
uninstall-autostart:
desc: 移除桌面自启入口
cmds:
- ./packaging/uninstall-autostart.sh