-
Notifications
You must be signed in to change notification settings - Fork 2
300 lines (247 loc) · 8.22 KB
/
Copy pathnode.js.yml
File metadata and controls
300 lines (247 loc) · 8.22 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
name: CI
on:
push:
branches: ["main", "develop"]
paths-ignore:
- "docs/**"
- "examples/**"
- "**/*.md"
- "LICENSE"
- ".gitignore"
pull_request:
branches: ["main", "develop"]
paths-ignore:
- "docs/**"
- "examples/**"
- "**/*.md"
- "LICENSE"
- ".gitignore"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
MONGODB_URI: mongodb://localhost:27017/test
REDIS_URL: redis://localhost:6379
ACCESS_TOKEN_SECRET: testAccessSecret
REFRESH_TOKEN_SECRET: testRefreshSecret
INTERNAL_SECRET: testInternalSecret
INTERNAL_SECRET_SOCKET: testInternalSecret
INTERNAL_SECRET_WORKER: testInternalWorkerSecret
TURBO_ENV_MODE: loose
jobs:
quality:
name: Quality (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
node-version: [22.x, 24.x]
services:
mongodb:
image: mongo:7
ports:
- 27017:27017
options: >-
--health-cmd="mongosh --eval 'db.runCommand({ ping: 1 })'"
--health-interval=10s
--health-timeout=5s
--health-retries=5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Enable Corepack
run: corepack enable
- name: Configure mongodb-memory-server cache
run: |
echo "MONGOMS_DOWNLOAD_DIR=$RUNNER_TEMP/mongodb-binaries" >> "$GITHUB_ENV"
echo "MONGOMS_PREFER_GLOBAL_PATH=0" >> "$GITHUB_ENV"
- name: Restore MongoDB memory server binaries
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ runner.temp }}/mongodb-binaries
key: ${{ runner.os }}-mongo-binaries-7.0.37-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-mongo-binaries-7.0.37-
${{ runner.os }}-mongo-binaries-
- name: Use Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Restore Turbo cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ matrix.node-version }}-${{ github.ref_name }}-${{ hashFiles('pnpm-lock.yaml', 'turbo.json') }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Pre-download MongoDB memory server binary
run: pnpm --filter @semantask/auth run test:download-mongo
- name: Build shared packages
run: pnpm exec turbo run build --filter=./packages/*
- name: Unit tests
run: pnpm run test
- name: Type check
run: pnpm run typecheck
- name: Lint
run: pnpm run lint
- name: Build monorepo
run: pnpm run build
- name: Verify build artifacts
run: pnpm run ci:verify-artifacts
web-runtime:
name: Web Runtime Smoke Test
runs-on: ubuntu-latest
needs: quality
timeout-minutes: 25
services:
mongodb:
image: mongo:7
ports:
- 27017:27017
redis:
image: redis:7
ports:
- 6379:6379
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Enable Corepack
run: corepack enable
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Build shared types package
run: pnpm --filter @semantask/types build
- run: pnpm run build
- name: Start web app
run: |
pnpm --filter @semantask/web start &
sleep 10
- name: Check web health
run: curl -f http://127.0.0.1:3000 || exit 1
socket-runtime:
name: Socket Runtime + WS Test
runs-on: ubuntu-latest
needs: quality
timeout-minutes: 30
services:
mongodb:
image: mongo:7
ports:
- 27017:27017
redis:
image: redis:7
ports:
- 6379:6379
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Enable Corepack
run: corepack enable
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Build shared types package
run: pnpm --filter @semantask/types build
- name: Build web app
run: pnpm --filter @semantask/web build
- name: Start web app
run: |
pnpm --filter @semantask/web start &
sleep 10
- name: Wait for web health
run: |
for i in {1..30}; do
curl -f http://127.0.0.1:3000 && exit 0
sleep 2
done
exit 1
- name: Build socket image
run: docker build -f docker/socket.Dockerfile -t chat-socket:ci .
- name: Start socket container
run: |
docker run -d --name chat-socket-ci -p 3001:3001 \
--add-host=host.docker.internal:host-gateway \
-e REDIS_URL=redis://host.docker.internal:6379 \
-e WEB_SERVER_URL=http://host.docker.internal:3000 \
-e INTERNAL_SECRET=testInternalSecret \
-e INTERNAL_SECRET_SOCKET=testInternalSecret \
-e INTERNAL_SECRET_WORKER=testInternalWorkerSecret \
-e ACCESS_TOKEN_SECRET=testAccessSecret \
-e ORIGIN=http://localhost \
chat-socket:ci
- name: Wait for health
run: |
for i in {1..30}; do
curl -f http://127.0.0.1:3001/health && exit 0
sleep 2
done
exit 1
- name: WebSocket authenticated connection test
working-directory: apps/web
run: |
node <<'NODE'
const { io } = require("socket.io-client");
const email = `ci-${Date.now()}@example.com`;
const password = "Password@123";
async function createAccessCookie() {
const registerResponse = await fetch("http://127.0.0.1:3000/api/auth/register", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
username: "ci-user",
email,
password,
}),
});
if (!registerResponse.ok) {
const errorText = await registerResponse.text();
throw new Error(`Register failed: ${registerResponse.status} ${errorText}`);
}
const setCookies = registerResponse.headers.getSetCookie?.() || [];
const accessCookie = setCookies.find((cookie) => cookie.startsWith("accessToken="));
if (!accessCookie) {
throw new Error("Missing accessToken cookie from register response");
}
return accessCookie.split(";")[0];
}
createAccessCookie().then((cookieHeader) => {
const socket = io("http://localhost:3001", {
path: "/api/socket",
transports: ["websocket"],
timeout: 5000,
extraHeaders: {
Cookie: cookieHeader,
},
});
socket.on("connect", () => {
console.log("WS connected");
process.exit(0);
});
socket.on("connect_error", (err) => {
console.error("WS failed", err.message);
process.exit(1);
});
}).catch((error) => {
console.error("Auth bootstrap failed", error.message);
process.exit(1);
});
NODE
- name: Cleanup
if: always()
run: docker rm -f chat-socket-ci || true