apsis-rs/.github/workflows/ci.yml

102 lines
5.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: CI
on:
push:
pull_request:
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Format
run: cargo fmt --all --check
- name: Check
# --all-features matters: the facade crate enables nothing by default,
# so without it almost all of its code, and every example, is skipped.
# `--all-features` 很重要:门面 crate 默认不启用任何特性,没有它
# 几乎其全部代码以及每个示例都会被跳过。
run: cargo check --workspace --all-targets --all-features
- name: Clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: Test
run: cargo test --workspace --all-features
- name: Integration checks
# The cross-layer checks are examples rather than tests, because they
# are also meant to be read and run by hand. `cargo test` does not run
# them, so without this step a change that breaks one layer's
# assumptions about another would pass CI silently.
# 跨层检查是示例而非测试,因为它们也意在供人阅读并手动运行。
# `cargo test` 不会运行它们,故没有这一步,破坏某层对另一层假设的
# 改动会无声地通过 CI。
run: |
cargo run -p apsis-rs --features network --example integrate_network
cargo run -p apsis-rs --features ops --example integrate_ops
cargo run -p apsis-rs --features sim --example integrate_sim
- name: Build the benchmarks
# The benchmarks are not run in CI, because their timings are only
# meaningful on a quiet machine, but they must still compile so that
# they do not rot.
# 基准在 CI 中不运行,因为其计时只在安静的机器上有意义,但它们
# 仍必须能编译,以免腐坏。
run: |
cargo build -p apsis-rs --features full --example bench
cargo build -p apsis-rs --features full --example bench_scale
cargo build -p apsis-rs --features full --example bench_parallel
- name: Documentation
# Catches a doc link that no longer resolves, which is how a doc
# comment drifts away from the code it describes.
# 捕获不再解析的文档链接,文档注释正是这样与其所述代码渐行渐远。
#
# RUSTDOCFLAGS takes precedence over the rustdocflags in
# .cargo/config.toml, so the MathJax header is named here as well.
# RUSTDOCFLAGS 优先于 .cargo/config.toml 中的 rustdocflags,故此处
# 也指名 MathJax 头部。
env:
RUSTDOCFLAGS: -D warnings --html-in-header docs/mathjax.html
run: bash scripts/build-docs.sh --workspace --all-features --no-deps
- name: Documentation with default features
# A downstream reader runs `cargo doc` on the default feature set,
# where the facade re-exports nothing, so a link to a re-exported
# crate does not resolve. The all-features build above would not
# catch that, so it is checked here.
# 下游读者会在默认特性集上运行 `cargo doc`,那里门面不重导出任何
# 东西,故指向被重导出 crate 的链接无法解析。上面的全特性构建捕获
# 不到这一点,故在此检查。
env:
RUSTDOCFLAGS: -D warnings --html-in-header docs/mathjax.html
run: bash scripts/build-docs.sh --workspace --no-deps
- name: Check the layer rule
# README.md states that a crate may only depend on layers to its
# left. Nothing else in the build enforces that, so a reverse
# dependency would otherwise pass CI silently.
# README.md 规定一个 crate 只能依赖其左侧的层。构建中没有别的
# 东西强制这一点,故反向依赖否则会无声地通过 CI。
run: bash scripts/check-layers.sh
- name: Verify dependency freedom
run: |
# Every package in the graph must be a workspace crate. `--prefix
# none` prints bare `name version` lines, one per package, which the
# box drawing prefix of the default format would otherwise hide.
# 依赖图中的每个包都必须是工作区 crate。`--prefix none` 打印
# 裸的 `name version` 行,每包一行;否则默认格式的制表前缀会把
# 它隐藏。
external=$(cargo tree --workspace --all-features \
--edges normal,build,dev --prefix none 2>/dev/null \
| sed -E 's/ \(\*\)$//; s/ \([^)]*\)$//' \
| awk 'NF {print $1}' \
| sort -u \
| grep -v '^apsis' || true)
if [ -n "$external" ]; then
echo "unexpected external dependency detected:" >&2
echo "$external" >&2
exit 1
fi
echo "dependency check passed: workspace crates only"