Skip to content

Conversation

@wangl-cc
Copy link
Member

@wangl-cc wangl-cc commented Jan 4, 2026

Closes #428.

Summary by Sourcery

为通过 Winget 分发的 Windows CLI 工件添加构建和发布的 CI 支持。

新功能:

  • 在发布工作流中新增一个 Winget 专用的构建任务,用于生成适合 Winget 分发的 Windows CLI 压缩包。
  • 引入可复用的 GitHub Actions 工作流,使用 Komac 将 CLI 发布为 Winget 软件包。

改进:

  • 扩展 xtask 构建工具,在创建压缩包时可选地重命名已构建的二进制文件。
  • 调整打包逻辑,以处理 Winget 专用的 Windows 目标,并在更新清单时排除 Winget 工件。

CI:

  • 更新主发布工作流,将新的 Winget 构建任务及随后的 Winget 发布步骤纳入其中。

Co-authored-by: JasonHuang79 63983700+JasonHuang79@users.noreply.github.com

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些高层次的反馈:

  • xtask/src/build.rs 中,opts.rename.unwrap_or(exe) 无法通过编译,因为 renameOption<String>exe&str;可以改为类似 opts.rename.unwrap_or_else(|| exe.to_string()) 的写法。
  • create_archive 中,if target.contains("-windows-msvc") 这个分支也会匹配 winget 目标(例如 -windows-msvc-winget),因此 winget 专用的 bin_name 永远不会被使用;应当先检查 -windows-msvc-winget 这种更具体的情况,再处理通用的 Windows 情况。
面向 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- In `xtask/src/build.rs`, `opts.rename.unwrap_or(exe)` will not compile because `rename` is an `Option<String>` and `exe` is a `&str`; use something like `opts.rename.unwrap_or_else(|| exe.to_string())` instead.
- In `create_archive`, the `if target.contains("-windows-msvc")` branch will also match winget targets (e.g. `-windows-msvc-winget`), so the winget-specific `bin_name` is never used; check for the `-windows-msvc-winget` case before the generic Windows case.

## Individual Comments

### Comment 1
<location> `xtask/src/release/package.rs:159-161` </location>
<code_context>
     // Use tar.gz for Unix-like systems (Linux, macOS) and zip for Windows
     let (format, bin_name) = if target.contains("-windows-msvc") {
         (ArchiveFormat::Zip, "maa.exe")
+    } else if target.contains("-windows-msvc-winget") {
+        (ArchiveFormat::Zip, "maa-cli.exe")
     } else if target.contains("-linux-") || target.contains("-apple-darwin") {
</code_context>

<issue_to_address>
**issue (bug_risk):** The `-windows-msvc-winget` branch is unreachable due to the broader `-windows-msvc` match above.

Because `target.contains("-windows-msvc")` matches `...-windows-msvc-winget`, the `else if target.contains("-windows-msvc-winget")` branch is never taken, so winget builds still get `maa.exe` instead of `maa-cli.exe`.

Swap the order so the more specific pattern is checked first:

```rust
let (format, bin_name) = if target.contains("-windows-msvc-winget") {
    (ArchiveFormat::Zip, "maa-cli.exe")
} else if target.contains("-windows-msvc") {
    (ArchiveFormat::Zip, "maa.exe")
} else if target.contains("-linux-") || target.contains("-apple-darwin") {
    // ...
}
```
</issue_to_address>

Sourcery 对开源项目免费 —— 如果你喜欢我们的评审,请考虑帮我们分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • In xtask/src/build.rs, opts.rename.unwrap_or(exe) will not compile because rename is an Option<String> and exe is a &str; use something like opts.rename.unwrap_or_else(|| exe.to_string()) instead.
  • In create_archive, the if target.contains("-windows-msvc") branch will also match winget targets (e.g. -windows-msvc-winget), so the winget-specific bin_name is never used; check for the -windows-msvc-winget case before the generic Windows case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `xtask/src/build.rs`, `opts.rename.unwrap_or(exe)` will not compile because `rename` is an `Option<String>` and `exe` is a `&str`; use something like `opts.rename.unwrap_or_else(|| exe.to_string())` instead.
- In `create_archive`, the `if target.contains("-windows-msvc")` branch will also match winget targets (e.g. `-windows-msvc-winget`), so the winget-specific `bin_name` is never used; check for the `-windows-msvc-winget` case before the generic Windows case.

## Individual Comments

### Comment 1
<location> `xtask/src/release/package.rs:159-161` </location>
<code_context>
     // Use tar.gz for Unix-like systems (Linux, macOS) and zip for Windows
     let (format, bin_name) = if target.contains("-windows-msvc") {
         (ArchiveFormat::Zip, "maa.exe")
+    } else if target.contains("-windows-msvc-winget") {
+        (ArchiveFormat::Zip, "maa-cli.exe")
     } else if target.contains("-linux-") || target.contains("-apple-darwin") {
</code_context>

<issue_to_address>
**issue (bug_risk):** The `-windows-msvc-winget` branch is unreachable due to the broader `-windows-msvc` match above.

Because `target.contains("-windows-msvc")` matches `...-windows-msvc-winget`, the `else if target.contains("-windows-msvc-winget")` branch is never taken, so winget builds still get `maa.exe` instead of `maa-cli.exe`.

Swap the order so the more specific pattern is checked first:

```rust
let (format, bin_name) = if target.contains("-windows-msvc-winget") {
    (ArchiveFormat::Zip, "maa-cli.exe")
} else if target.contains("-windows-msvc") {
    (ArchiveFormat::Zip, "maa.exe")
} else if target.contains("-linux-") || target.contains("-apple-darwin") {
    // ...
}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.34%. Comparing base (32267cc) to head (4998c40).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #470   +/-   ##
=======================================
  Coverage   69.34%   69.34%           
=======================================
  Files          56       56           
  Lines        5598     5598           
  Branches     5598     5598           
=======================================
  Hits         3882     3882           
  Misses       1425     1425           
  Partials      291      291           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wangl-cc wangl-cc merged commit c87d15e into main Jan 4, 2026
11 checks passed
@wangl-cc wangl-cc deleted the release/winget branch January 4, 2026 13:07
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