Skip to content

Commit f29ff9e

Browse files
committed
update workflows
1 parent 7912ad7 commit f29ff9e

File tree

1 file changed

+84
-63
lines changed

1 file changed

+84
-63
lines changed

.github/workflows/rust.yml

Lines changed: 84 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,96 @@ env:
1111
CARGO_TERM_COLOR: always
1212

1313
jobs:
14-
check-and-test:
15-
name: Check & Test
14+
# 任务一:专门在 Docker 容器中检查 Linux
15+
check-linux:
16+
name: Check on Linux
17+
runs-on: ubuntu-latest
18+
# 使用官方 Rust Docker 容器,保证环境绝对干净
19+
container:
20+
image: rust:stable # 你也可以用 rust:1.79.0 等具体版本
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
# 容器中已包含 Rust,无需安装。直接进行检查。
27+
28+
- name: Cache Cargo dependencies
29+
uses: actions/cache@v3
30+
with:
31+
path: |
32+
/usr/local/cargo/registry/index/
33+
/usr/local/cargo/registry/cache/
34+
/usr/local/cargo/git/db/
35+
target/
36+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
37+
38+
- name: Check formatting
39+
run: cargo fmt --all -- --check
40+
41+
- name: Run Clippy
42+
run: cargo clippy --all-targets --all-features -- -D warnings
43+
44+
- name: Run tests
45+
run: cargo test --verbose --all-features
46+
47+
- name: Build release
48+
run: cargo build --release --all-features
49+
50+
- name: Check packaging
51+
run: cargo package --all-features
52+
53+
# 任务二:检查 Windows 和 macOS
54+
check-windows-macos:
55+
name: Check on ${{ matrix.os }}
1656
runs-on: ${{ matrix.os }}
1757
strategy:
1858
matrix:
19-
os: [ubuntu-latest, windows-latest, macos-latest]
59+
os: [windows-latest, macos-latest]
2060

2161
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v3
24-
25-
# 安装最新的 stable Rust 工具链,并强制进行干净安装
26-
- name: Install latest Rust toolchain
27-
uses: actions-rust-lang/setup-rust-toolchain@v1
28-
with:
29-
toolchain: stable # <-- 使用 "stable" 关键字来获取最新稳定版
30-
components: clippy, fmt
31-
override: true # <-- 保留此项,以避免 runner 环境问题
32-
33-
# 为 Cargo 设置缓存,极大提升后续运行速度
34-
- name: Cache Cargo dependencies
35-
uses: actions/cache@v3
36-
with:
37-
path: |
38-
~/.cargo/bin/
39-
~/.cargo/registry/index/
40-
~/.cargo/registry/cache/
41-
~/.cargo/git/db/
42-
target/
43-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
44-
restore-keys: |
45-
${{ runner.os }}-cargo-
46-
47-
# 1. 检查代码格式
48-
- name: Check formatting
49-
run: cargo fmt --all -- --check
50-
51-
# 2. 运行 Clippy 代码质量检查
52-
- name: Run Clippy
53-
run: cargo clippy --all-targets --all-features -- -D warnings
54-
55-
# 3. 运行测试
56-
- name: Run tests
57-
run: cargo test --verbose --all-features
58-
59-
# 4. 确保 Release 版本可以成功构建
60-
- name: Build release
61-
run: cargo build --release --all-features
62-
63-
# 5. 检查是否可以打包
64-
- name: Check packaging
65-
run: cargo package --all-features
66-
67-
# (publish 任务可以保持不变,但建议也使用 'stable' 工具链)
62+
- name: Checkout repository
63+
uses: actions/checkout@v3
64+
65+
- name: Install Rust toolchain
66+
uses: actions-rust-lang/setup-rust-toolchain@v1
67+
with:
68+
toolchain: stable
69+
override: true # 在这些平台上,override 应该能正常工作
70+
components: clippy, fmt
71+
72+
- name: Cache Cargo dependencies
73+
uses: actions/cache@v3
74+
with:
75+
path: |
76+
~/.cargo/bin/
77+
~/.cargo/registry/index/
78+
~/.cargo/registry/cache/
79+
~/.cargo/git/db/
80+
target/
81+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
82+
restore-keys: |
83+
${{ runner.os }}-cargo-
84+
85+
- name: Check formatting
86+
run: cargo fmt --all -- --check
87+
88+
- name: Run Clippy
89+
run: cargo clippy --all-targets --all-features -- -D warnings
90+
91+
- name: Run tests
92+
run: cargo test --verbose --all-features
93+
94+
- name: Build release
95+
run: cargo build --release --all-features
96+
97+
- name: Check packaging
98+
run: cargo package --all-features
99+
100+
# (可选) 如果你需要在发布前确保所有检查都通过
68101
# publish:
69102
# name: Publish to Crates.io
70103
# runs-on: ubuntu-latest
71-
# needs: [check-and-test]
104+
# needs: [check-linux, check-windows-macos] # 依赖于上面两个任务
72105
# if: startsWith(github.ref, 'refs/tags/')
73-
74-
# steps:
75-
# - name: Checkout repository
76-
# uses: actions/checkout@v3
77-
# - name: Install latest Rust toolchain
78-
# uses: actions-rust-lang/setup-rust-toolchain@v1
79-
# with:
80-
# toolchain: stable
81-
# override: true
82-
# - name: Publish to Crates.io
83-
# run: cargo publish
84-
# env:
85-
# CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
106+
# # ... publish steps ...

0 commit comments

Comments
 (0)