Elffuss BraidHub

kikocis/utopia public

2d1966ff85f5 · 3.4 KiBRawPermalink
1name: CI
2
3on:
4 push:
5 branches: [main]
6 pull_request:
7
8env:
9 CARGO_TERM_COLOR: always
10
11jobs:
12 backend:
13 runs-on: ubuntu-latest
14 steps:
15 - uses: actions/checkout@v4
16 - uses: dtolnay/rust-toolchain@stable
17 with:
18 components: rustfmt, clippy
19 - uses: Swatinem/rust-cache@v2
20 - name: Format
21 run: cargo fmt --all --check
22 - name: Clippy
23 run: cargo clippy --workspace --all-targets -- -D warnings
24 - name: Test
25 run: cargo test --workspace
26 - name: Build
27 run: cargo build --workspace
28
29 # 迁移得真的在库上跑一遍。此前 CI 只有 fmt/clippy/test/build,于是两个 PR
30 # 各带一个 0025、各自通过,合进 main 之后服务直接起不来——sqlx 按版本号索引,
31 # 而**合并后的状态从来没有被任何一次 CI 跑过**。
32 migrations:
33 runs-on: ubuntu-latest
34 services:
35 postgres:
36 image: pgvector/pgvector:pg16
37 env:
38 POSTGRES_USER: utopia
39 POSTGRES_PASSWORD: utopia
40 POSTGRES_DB: utopia
41 ports: ["5432:5432"]
42 options: >-
43 --health-cmd pg_isready --health-interval 5s
44 --health-timeout 5s --health-retries 10
45 steps:
46 - uses: actions/checkout@v4
47 # 撞号在文件层面不是冲突,git 合得干干净净——只能显式查
48 - name: 版本号不得重复
49 run: |
50 dupes=$(ls migrations/ | cut -d_ -f1 | sort | uniq -d)
51 if [ -n "$dupes" ]; then
52 echo "::error::迁移版本号重复:$dupes"
53 ls migrations/
54 exit 1
55 fi
56 - uses: dtolnay/rust-toolchain@stable
57 - uses: Swatinem/rust-cache@v2
58 - name: 装 sqlx-cli
59 run: cargo install sqlx-cli --no-default-features --features rustls,postgres --locked
60 - name: 全新库上跑一遍
61 run: sqlx migrate run --database-url postgres://utopia:utopia@localhost:5432/utopia
62 # 第二遍必须也过:迁移改号后要能在已经跑过旧号的库上安全重放
63 - name: 再跑一遍
64 run: sqlx migrate run --database-url postgres://utopia:utopia@localhost:5432/utopia
65 # 连库的测试只有这个 job 跑得动——rust job 没有数据库,那些测试在那边
66 # 会跳过并显示绿色。不在这里跑一遍,等于写了测试却永远没执行过,
67 # 比没写更糟:它会让人以为 SQL 有覆盖
68 - name: 连库测试
69 run: cargo test -p utopia-store --test graph_changes
70 env:
71 UTOPIA_DATABASE_URL: postgres://utopia:utopia@localhost:5432/utopia
72
73 web:
74 runs-on: ubuntu-latest
75 defaults:
76 run:
77 working-directory: web
78 steps:
79 - uses: actions/checkout@v4
80 # 版本来自 web/package.json 的 packageManager 字段——这里再写一次
81 # 就成了第二个事实来源,两边迟早分叉(镜像构建就是这么炸的)。
82 # package_json_file 必须显式给:上面的 working-directory 只管 run 步骤,
83 # 这个 action 默认在仓库根找 package.json,而根目录是 Cargo workspace。
84 - uses: pnpm/action-setup@v4
85 with:
86 package_json_file: web/package.json
87 - uses: actions/setup-node@v4
88 with:
89 node-version: 20
90 cache: pnpm
91 cache-dependency-path: web/pnpm-lock.yaml
92 - name: Install
93 run: pnpm install --frozen-lockfile
94 - name: Build (含类型检查)
95 run: pnpm build