Repository navigation
187 lines (159 loc) · 4.96 KB
/
Copy pathci.yml
File metadata and controls
187 lines (159 loc) · 4.96 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
name: CI Checks
# 日常质量门禁:PR 与非 dev 分支推送触发
on:
pull_request:
branches: [dev, main]
push:
branches: [dev, main]
permissions:
contents: read
env:
NODE_VERSION: "24.20.0"
jobs:
server:
name: Go server checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: Vet
working-directory: server
run: go vet ./...
- name: Test
working-directory: server
run: go test -v ./...
- name: Build
working-directory: server
env:
CGO_ENABLED: "0"
run: go build -trimpath -o /tmp/knowforge-server .
server-db:
# 同一套 Go 测试在 PostgreSQL 与 MySQL 上再跑一遍(默认的 server 任务使用 SQLite);
# 每个测试在服务容器中新建独立的库(见 internal/testdb),结束后删除
name: Go tests on ${{ matrix.db }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- db: postgres
port: 5432
user: postgres
- db: mysql
port: 3306
user: root
services:
postgres:
image: ${{ matrix.db == 'postgres' && 'postgres:16-alpine' || '' }}
env:
POSTGRES_PASSWORD: kftest
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-timeout 5s --health-retries 20
mysql:
image: ${{ matrix.db == 'mysql' && 'mysql:8.4' || '' }}
env:
MYSQL_ROOT_PASSWORD: kftest
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -pkftest"
--health-interval 5s --health-timeout 5s --health-retries 30
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: Test
working-directory: server
env:
KNOWFORGE_TEST_DB: ${{ matrix.db }}
KNOWFORGE_TEST_DB_HOST: 127.0.0.1
KNOWFORGE_TEST_DB_PORT: ${{ matrix.port }}
KNOWFORGE_TEST_DB_USER: ${{ matrix.user }}
KNOWFORGE_TEST_DB_PASSWORD: kftest
# 限制并行的测试包数,避免同时建库与连接数过多
run: go test -p 4 ./...
web:
name: Web checks (typecheck + lint + test + build)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
cache-dependency-path: app/web/pnpm-lock.yaml
- name: Install dependencies
working-directory: app/web
run: pnpm install --frozen-lockfile
- name: Typecheck
working-directory: app/web
run: pnpm exec tsc --noEmit
- name: i18n check
working-directory: app/web
run: python3 scripts/check_i18n.py
- name: Test
working-directory: app/web
run: pnpm test
- name: Lint
working-directory: app/web
run: pnpm exec next lint
- name: Build (SSR standalone)
working-directory: app/web
env:
NEXT_DIST_DIR: .next-build
run: pnpm build
e2e:
# 端到端测试:启动全新的后端(SQLite)、假 AI 服务与前端开发服务,用 Chromium 走通会员购买、优惠券、礼品卡、试用、
# 邀请奖励、退款、付费墙与问答实时推送(见 app/web/e2e)
name: End-to-end tests (Playwright)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
cache-dependency-path: app/web/pnpm-lock.yaml
- name: Install dependencies
working-directory: app/web
run: pnpm install --frozen-lockfile
- name: Install Chromium
working-directory: app/web
run: pnpm exec playwright install --with-deps chromium
- name: Run end-to-end tests
working-directory: app/web
run: pnpm e2e
- name: Upload report
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
app/web/playwright-report
app/web/test-results
retention-days: 7