1- name : Rust CI (Optimized)
1+ # 工作流名称
2+ name : Rust CI (Full Cross-Platform Checks)
23
4+ # 触发工作流的事件
35on :
46 push :
57 branches : [ "main" ]
68 pull_request :
79 branches : [ "main" ]
810
11+ # 全局环境变量
912env :
1013 CARGO_TERM_COLOR : always
14+ # 设置 RUSTFLAGS 以在 Windows 上处理一些 Clippy 的链接问题(可选但推荐)
15+ RUSTFLAGS : -D warnings
1116
1217jobs :
13- # 任务1:只在 Linux 上运行格式化和 Clippy 检查
14- lints :
15- name : Lints (fmt & clippy)
16- runs-on : ubuntu-latest
17- steps :
18- - uses : actions/checkout@v4
19- - name : Install Rust toolchain
20- uses : dtolnay/rust-toolchain@stable
21- with :
22- components : clippy, rustfmt
23- - uses : swatinem/rust-cache@v2
24- - name : Check formatting
25- run : cargo fmt --all -- --check
26- - name : Run Clippy
27- run : cargo clippy --all-targets --all-features -- -D warnings
18+ # 定义一个名为 "full-check" 的任务
19+ full-check :
20+ # 任务的描述性名称,会显示在 GitHub UI 中
21+ # ${{ matrix.os }} 会被替换为当前运行的操作系统
22+ name : Check on ${{ matrix.os }}
2823
29- # 任务2:在所有平台上运行测试
30- tests :
31- name : Tests (${{ matrix.os }})
32- # 这个任务需要等待 'lints' 任务成功后才能开始
33- needs : lints
24+ # 关键部分:定义构建矩阵
3425 strategy :
26+ # 设置为 false,这样即使一个平台的任务失败,其他平台的任务也会继续运行
27+ # 这能让你看到所有平台的完整报告
3528 fail-fast : false
3629 matrix :
30+ # 定义一个名为 os 的变量,包含我们想测试的所有平台
3731 os : [ubuntu-latest, macos-latest, windows-latest]
32+
33+ # 使用矩阵中的变量来指定运行环境
3834 runs-on : ${{ matrix.os }}
35+
36+ # 定义此任务的执行步骤
37+ # 以下所有步骤都将在矩阵中的每个操作系统上执行
3938 steps :
40- - uses : actions/checkout@v4
39+ # 步骤 1: 检出代码
40+ - name : Checkout repository
41+ uses : actions/checkout@v4
42+
43+ # 步骤 2: 安装 Rust 工具链
44+ # dtolnay/rust-toolchain 能很好地处理跨平台安装
4145 - name : Install Rust toolchain
4246 uses : dtolnay/rust-toolchain@stable
43- - uses : swatinem/rust-cache@v2
47+ with :
48+ components : clippy, rustfmt
49+
50+ # 步骤 3: 缓存 Cargo 依赖项
51+ # swatinem/rust-cache 自动处理跨平台缓存,非常方便
52+ - name : Cache Cargo dependencies
53+ uses : swatinem/rust-cache@v2
54+
55+ # 步骤 4: 在当前平台运行代码格式化检查 (fmt)
56+ - name : Check formatting (cargo fmt)
57+ run : cargo fmt --all -- --check
58+
59+ # 步骤 5: 在当前平台运行 Clippy 代码质量检查
60+ # -D warnings 会将所有警告视为错误
61+ - name : Run Clippy
62+ run : cargo clippy --all-targets --all-features
63+
64+ # 步骤 6: 在当前平台运行所有测试
4465 - name : Run tests
4566 run : cargo test --verbose --all-features
0 commit comments