Skip to content

feat(ci) - ci pre check#300

Merged
zevwings merged 3 commits into
masterfrom
chore/ci-pre-check
Feb 27, 2026
Merged

feat(ci) - ci pre check#300
zevwings merged 3 commits into
masterfrom
chore/ci-pre-check

Conversation

@zevwings
Copy link
Copy Markdown
Owner

PR Ready

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change which does not change functionality)
  • Hotfix (urgent fix for production issues)
  • Chore (maintenance tasks and non-functional changes)

Summary

在 CI 流水线中提前生成并公开预发布版本信息,使后续步骤能够依据是否需要递增版本进行判断。

Key Changes

  • 新增 pre-release-checks 作业并输出 version、tag、needs_increment
  • 修改 generate.py 支持手动指定的 Cargo 版本覆盖自动计算结果
  • 改进 cargo update 调用并加入错误处理
  • 新增针对新逻辑的单元测试

Changes

Features

  • CI 作业新增预发布版本检查
  • 版本生成脚本支持手动指定的 Cargo 版本

Refactors

  • 重写 update_cargo_files 为直接 subprocess 调用

Configuration

  • ci.yml 中添加 pre-release-checks 作业配置
  • 更新 final status 作业的 needs 列表

Tests

  • 新增多项单元测试覆盖版本生成与 CI 输出

Impact Analysis

Affected Modules

Module Impact Severity
.github/workflows/ci.yml 新增作业并修改依赖顺序,可能导致 CI 时长略增 low
scripts/dev/py/version/generate.py 内部逻辑依赖 Cargo.toml 中的手动版本,若格式异常可能回退到自动计算 medium

Risk Assessment

Overall risk: medium

Risk factors:

  • 正则解析 Cargo.toml 可能在非标准格式下失效
  • CI 作业新增导致整体执行时间增加

Mitigation:

  • 为 _read_cargo_workspace_version 添加覆盖多种 Cargo.toml 布局的单元测试
  • 在 CI 中缓存 Python 依赖或使用预构建镜像以降低执行时长

Testing Suggestions

  • 运行所有新增的单元测试,确保版本覆盖逻辑正确
  • 在 CI 环境下验证 pre-release-checks 作业能够成功输出 version、tag、needs_increment
  • 手动修改 Cargo.toml 中的 workspace.package.version,观察 generate_master_version 的行为

Statistics

Metric Value
Total files 4
Additions +243
Deletions -3
Net change 240
Added files 2
Modified files 2
Deleted files 0
Renamed files 0

Review Info

  • Complexity: medium
  • Review priority: medium
  • Estimated review time: 15 minutes
  • Tags: ci, version, feature

The test suite for the completion service failed on Windows because the standard library's `dirs::home_dir()` ignores the `HOME` environment variable and prefers `USERPROFILE`, `HOMEDRIVE` and `HOMEPATH`. This commit introduces a small test‑only helper (`EnvGuard`) that sets up a consistent home directory environment across platforms and restores the original values after each test.

Key changes:
- Added `EnvGuard` struct with fields for `HOME`, `WORKFLOW_DISABLE_ICLOUD` and Windows‑specific variables.
- Implemented `EnvGuard::new` to set `HOME`, disable iCloud sync, and on Windows configure `USERPROFILE`, `HOMEDRIVE`, and `HOMEPATH` based on the temporary directory.
- Implemented `Drop` for `EnvGuard` to cleanly revert all environment modifications.
- Updated `test_check_status_when_no_scripts_exist` to use the guard and verify that the completion directory stays inside the temporary home.

This ensures reliable, platform‑agnostic test execution without affecting production code.
The path service previously relied on `dirs::home_dir()` which, on Windows, ignores the `HOME` environment variable and always falls back to `USERPROFILE`/`HOMEDRIVE`+`HOMEPATH`. This caused tests that temporarily set `HOME` to a temporary directory to fail because the service resolved to the actual user profile instead of the intended temporary location.

**What changed**
- Added an explicit check for the `HOME` environment variable before calling `dirs::home_dir()`.
- If `HOME` is set, its value is used as the base directory; otherwise the original fallback logic is retained.
- Introduced a new unit test `try_local_base_dir_respects_home_env` that verifies the service respects `HOME` on both Unix and Windows platforms.

**How it was implemented**
- Utilized `std::env::var("HOME")` to read the variable and construct a `PathBuf` when present.
- Kept the existing error handling for the case where neither `HOME` nor `dirs::home_dir()` can determine a path.
- Added platform‑specific environment variable handling in the test to mimic Windows behaviour.

This fix restores expected behaviour across all platforms and ensures test reliability.
@zevwings zevwings merged commit 8eae5ea into master Feb 27, 2026
14 checks passed
@zevwings zevwings deleted the chore/ci-pre-check branch February 27, 2026 05:53
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.

1 participant