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
name: Rust CI
on:
push:
branches:
- master # 仅在 master 分支推送时触发
jobs:
test:
name: Run Unit and Integration Tests
runs-on: ubuntu-latest # 使用 Ubuntu 作为运行环境
steps:
# 检出代码库
- name: Checkout Code
uses: actions/checkout@v4 # 更新到最新版本的 checkout action
# 设置 Rust 环境为 nightly 版本
- name: Set up Rust (nightly)
uses: dtolnay/rust-toolchain@stable # 推荐使用最新的 rust-toolchain
with:
toolchain: nightly # 使用 nightly 版本
components: rustfmt, clippy # 可选:添加常用组件
# 缓存 Cargo 依赖项,提高运行速度
- name: Cache Cargo dependencies
uses: actions/cache@v4 # 使用最新版本的 cache action
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
# 编译项目(确保没有编译错误)
- name: Build Project
run: cargo build --verbose
# 运行单元测试
- name: Run Unit Tests
run: cargo test --verbose
# 运行集成测试(tests 文件夹中的所有测试)
- name: Run Integration Tests
run: cd tests && cargo test --test '*' --verbose