-
Notifications
You must be signed in to change notification settings - Fork 257
101 lines (95 loc) · 3.73 KB
/
Copy pathci.yml
File metadata and controls
101 lines (95 loc) · 3.73 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
name: CI
on:
push:
branches: [main]
pull_request:
# **显式只读。** 没有这一块时它继承仓库级默认,而那个默认要为
# star-history 改成读写——CI 是每次推送、每个 PR 都跑的那个 workflow,
# 不该因为别处的需要顺带拿到写权限。写在这里,仓库默认怎么变都与它无关
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all --check
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
- name: Test
run: cargo test --workspace
- name: Build
run: cargo build --workspace
# 迁移得真的在库上跑一遍。此前 CI 只有 fmt/clippy/test/build,于是两个 PR
# 各带一个 0025、各自通过,合进 main 之后服务直接起不来——sqlx 按版本号索引,
# 而**合并后的状态从来没有被任何一次 CI 跑过**。
migrations:
runs-on: ubuntu-latest
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: utopia
POSTGRES_PASSWORD: utopia
POSTGRES_DB: utopia
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready --health-interval 5s
--health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v4
# 撞号在文件层面不是冲突,git 合得干干净净——只能显式查
- name: 版本号不得重复
run: |
dupes=$(ls migrations/ | cut -d_ -f1 | sort | uniq -d)
if [ -n "$dupes" ]; then
echo "::error::迁移版本号重复:$dupes"
ls migrations/
exit 1
fi
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: 装 sqlx-cli
run: cargo install sqlx-cli --no-default-features --features rustls,postgres --locked
- name: 全新库上跑一遍
run: sqlx migrate run --database-url postgres://utopia:utopia@localhost:5432/utopia
# 第二遍必须也过:迁移改号后要能在已经跑过旧号的库上安全重放
- name: 再跑一遍
run: sqlx migrate run --database-url postgres://utopia:utopia@localhost:5432/utopia
# 连库的测试只有这个 job 跑得动——rust job 没有数据库,那些测试在那边
# 会跳过并显示绿色。不在这里跑一遍,等于写了测试却永远没执行过,
# 比没写更糟:它会让人以为 SQL 有覆盖
- name: 连库测试
run: cargo test -p utopia-store --test graph_changes
env:
UTOPIA_DATABASE_URL: postgres://utopia:utopia@localhost:5432/utopia
web:
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v4
# 版本来自 web/package.json 的 packageManager 字段——这里再写一次
# 就成了第二个事实来源,两边迟早分叉(镜像构建就是这么炸的)。
# package_json_file 必须显式给:上面的 working-directory 只管 run 步骤,
# 这个 action 默认在仓库根找 package.json,而根目录是 Cargo workspace。
- uses: pnpm/action-setup@v4
with:
package_json_file: web/package.json
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- name: Install
run: pnpm install --frozen-lockfile
- name: Build (含类型检查)
run: pnpm build