Repository navigation
69 lines (56 loc) · 2.42 KB
/
Copy pathci.yml
File metadata and controls
69 lines (56 loc) · 2.42 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
name: CI
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always
jobs:
ci:
name: test / fmt / clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo build artifacts
uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --check
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings
- name: Run tests
run: cargo test
# Cargo.toml 声明 rust-version = "1.86",CONTRIBUTING.md 把它写成对贡献者的契约,而上面的
# job 只装最新 stable —— 声明因此没有任何执行者:clippy 的修复建议会推着代码越过这条线
# (例如 unsigned_is_multiple_of 是 1.87 才稳定的 API),在 stable 上仍然是全绿。
# 本 job 只装「被声明的那一版」,让该契约第一次变成一道会红的门禁。
msrv:
name: msrv (the version Cargo.toml declares)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install the declared MSRV toolchain
uses: dtolnay/rust-toolchain@1.86
# 声明一旦抬高,这里必须同步:否则本 job 测着旧版本、而 Cargo.toml 已经声明新高,
# 等于又退回「声明没有执行者」。这一步把两者钉在一起。
- name: Assert the installed toolchain is the declared rust-version
run: |
declared=$(grep -m1 '^rust-version' Cargo.toml | cut -d'"' -f2)
installed=$(rustc --version | cut -d' ' -f2)
echo "Cargo.toml rust-version = ${declared}; installed rustc = ${installed}"
case "$installed" in
"$declared"|"$declared".*) ;;
*)
echo "::error::Cargo.toml declares rust-version \"${declared}\" but this job installs rustc ${installed} — bump the toolchain in .github/workflows/ci.yml"
exit 1
;;
esac
- name: Cache cargo build artifacts
uses: Swatinem/rust-cache@v2
# --locked:钉住仓库里那份 Cargo.lock —— 否则 lockfile 与 Cargo.toml 一旦不一致,
# runner 会就地重新解析、构建照样通过,而提交进仓库的那份 lockfile 仍是坏的。
- name: Build with the declared MSRV
run: cargo build --locked