Elffuss BraidHub

kikocis/utopia public

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