Skip to content

Comments

ci: 依赖感知的测试目标选择,按变更范围动态运行 CI 测试#369

Open
yoinspiration wants to merge 4 commits intoarceos-hypervisor:masterfrom
yoinspiration:ci/dependency-aware-testing
Open

ci: 依赖感知的测试目标选择,按变更范围动态运行 CI 测试#369
yoinspiration wants to merge 4 commits intoarceos-hypervisor:masterfrom
yoinspiration:ci/dependency-aware-testing

Conversation

@yoinspiration
Copy link

概述

实现依赖感知的 CI 测试目标选择:根据代码变更和 workspace 依赖关系,只对受影响的目标运行测试,减少不必要的硬件占用和等待时间。

动机

  • 硬件资源:自托管 Runner 连接的开发板数量有限,全量测试会阻塞其他任务
  • 反馈速度:每次提交都跑全量测试耗时长
  • 依赖关系:底层模块(如 axruntime)变更会影响依赖它的上层模块,需要根据依赖正确选择测试目标

实现方式

三阶段流程

  1. 变更检测git diff 获取变更文件,过滤文档等非代码文件
  2. 依赖传播cargo metadata 构建 workspace 反向依赖图,BFS 找出受影响的 crate
  3. 目标映射:10 条规则将变更映射到测试目标(QEMU aarch64/x86_64、飞腾派、RK3568)

文件变更

文件 说明
xtask/src/affected.rs 新增核心分析引擎
xtask/src/main.rs 注册 cargo xtask affected 子命令
.github/workflows/test-qemu.yml 添加 detect job 动态构建矩阵
.github/workflows/test-board.yml 同上
doc/dependency-aware-testing.md 设计文档

CI 流程调整

push/PR → detect job (ubuntu-latest) → 分析影响范围 → 动态构建测试矩阵
                                              ↓
                           test job(仅运行受影响的目标,矩阵为空则跳过)

使用方式

# 本地:对比 main 分支查看需要运行的测试
cargo xtask affected --base origin/main

CI 会在 push/PR 时自动执行 detect 并选择测试目标,无需额外配置。

验证

已在本地覆盖以下典型场景:

  • 只改文档 → skip_all=true,跳过所有测试
  • 改 aarch64 HAL → 仅 QEMU aarch64 + 两块 ARM 板
  • 改飞腾派驱动 → 仅飞腾派板
  • 改 x86 平台 crate → 仅 QEMU x86_64
  • 改 axruntime → 全量测试

root and others added 4 commits February 18, 2026 18:59
Add `cargo xtask affected` command that analyzes git changes against
a base ref and determines which test targets (QEMU aarch64/x86_64,
board phytiumpi/rk3568) actually need to run.

The analysis works in three phases:
1. git diff detects changed files
2. cargo metadata builds the workspace reverse dependency graph,
   then BFS propagates changes to all affected crates
3. Path-based and crate-based rules map affected crates to concrete
   test targets

Update CI workflows (test-qemu.yml, test-board.yml) to run a
lightweight `detect` job on ubuntu-latest before dispatching actual
tests on self-hosted hardware runners, skipping targets unaffected
by the change.

Co-authored-by: Cursor <cursoragent@cursor.com>
cargo_metadata 0.23 returns PackageName instead of String for
package names. Convert with to_string() to match HashMap key types.

Co-authored-by: Cursor <cursoragent@cursor.com>
The previous logic treated axruntime/axconfig as "all tests needed"
whenever they appeared in the affected set. This caused false positives
for target-specific deps (e.g. axplat-x86-qemu-q35 is a cfg(x86_64)
dep of axruntime). Now only trigger all tests when these core modules
are directly modified.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@aarkegz aarkegz self-requested a review February 19, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants