-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (107 loc) · 4.63 KB
/
Copy pathci.yml
File metadata and controls
122 lines (107 loc) · 4.63 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
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
strategy:
fail-fast: false
matrix:
# ubuntu 是基线;windows 是本项目的主要部署形态(start.cmd / 计划任务 /
# pkg exe / 注册表通知),必须同缸回归路径分隔符与 spawn 行为差异
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
# 22 是同时满足 vitest@5(^22.12 || ^24 || >=26)与 eslint@10
# (^20.19 || ^22.13 || >=24)的版本。此前固定在 20:vitest 5 的 engines
# 下限是 22.12,CI 一直把测试 Runner 跑在它自己声明的支持范围之下——
# engines 只是建议、npm 默认不拦,所以现在是"恰好能跑",
# vitest 补丁版一旦用到 20 没有的 API 就会莫名其妙炸 CI。
# 真正交付给用户的 Node ≥20 下限由下面的 smoke job 覆盖(那里跑不了 vitest)。
- uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Typecheck
run: npm run typecheck
# 先 build:集成测试 spawn 的是 dist/index.js
- name: Build
run: npm run build
- name: Test
run: npx vitest run
# 覆盖率只在基线系统跑一份,避免矩阵重复。
# 带阈值:此前只打印 text-summary,覆盖率全靠人往 CHANGELOG 里手抄,
# 跌回去不会有任何人知道。锁在 65(当前 statements 约 67)。
- name: Coverage
if: matrix.os == 'ubuntu-latest'
run: npx vitest run --coverage --coverage.reporter=text-summary --coverage.thresholds.statements=65
# 把构建产物交给 smoke job 用,省掉在 Node 20 上装整套 devDependencies
# (vitest@5 在 20 上根本装不干净)。
- name: Upload dist
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 1
# 交付运行时冒烟:package.json 声明 engines >=20,而主 job 跑在 22 上
# (vitest@5 要求 >=22.12),于是**声明的支持面下限没有任何人验证过**。
# 这里验的就是那个下限:能起得来,说明 >=20 这句话是真的,也顺带覆盖了
# pkg 打包进去的 node22 运行时(22 只会比 20 更宽)。
# 不跑测试框架,只起真实进程打两个请求:/health 与仪表盘 HTML。
smoke-node20:
needs: test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '20'
# 只装生产依赖:这里验的是运行时能起来,不需要 vitest/eslint
# (vitest@5 在 20 上也装不干净,而本 job 本来也不跑它)
- name: Install production dependencies only
run: npm ci --omit=dev
- name: Download built dist
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Start proxy and probe it
shell: bash
run: |
set -euo pipefail
DIR="$(mktemp -d)"
printf '%s' '{"port":9099,"host":"127.0.0.1"}' > "$DIR/config.json"
: > "$DIR/.env"
COMMANDCODE_CONFIG_PATH="$DIR/config.json" \
COMMANDCODE_ENV_FILE_PATH="$DIR/.env" \
COMMANDCODE_MODELS_CACHE_PATH="$DIR/models.json" \
COMMANDCODE_PRICING_CACHE_PATH="$DIR/pricing.json" \
COMMANDCODE_LOG_PATH="$DIR/proxy.log" \
USAGE_HISTORY_PATH="$DIR/usage.jsonl" \
NO_OPEN_BROWSER=1 HOST=127.0.0.1 PORT=9099 \
node dist/index.js > "$DIR/stdout.log" 2>&1 &
SRV=$!
trap 'kill $SRV 2>/dev/null || true' EXIT
# 轮询到就绪,而不是 sleep 一个固定值赌调度
for i in $(seq 1 40); do
if curl -fsS --max-time 3 http://127.0.0.1:9099/health > "$DIR/health.json"; then break; fi
sleep 1
if [ "$i" = 40 ]; then echo "服务未能在 40s 内就绪"; cat "$DIR/stdout.log"; exit 1; fi
done
cat "$DIR/health.json"
grep -q '"status":"ok"' "$DIR/health.json"
# 仪表盘 HTML 必须发得出来(public/ 是 pkg assets,也是运行时依赖)
curl -fsS --max-time 5 -o "$DIR/index.html" http://127.0.0.1:9099/
grep -qi "<title" "$DIR/index.html"
echo "Node 20 smoke OK: $(node -v)"