fix(release): PE 版本读回在 Windows runner 上崩在 print 编码上(判据内部一条未降)

v0.2.4 Release run 43031591576 的 windows-x64 / windows-arm64 都红在「PE 版本资源读回」,
而 cargo build 是绿的、注解 API 上只有一句 Process completed with exit code 1.

根因:check_pe_version.py 把中文打在 stdout/stderr,本机 cp936 能编,Windows runner 是 en-US
镜像(代码页 1252),print() 直接 UnicodeEncodeError —— 判据全过也红,而且崩在 print 上,
日志里只剩 traceback。同仓 5 个 packaging 脚本已有 reconfigure(errors=backslashreplace) 守卫,
Windows 槽位跑的脚本里只有这一个漏了。

- check_pe_version.py: safe_streams()(管道钉 UTF-8、终端只放宽 errors)、
  每产物摘要行 flush(stderr 的判据不再跑到摘要前面)、模块 docstring 补判据清单;
  --self-test 增加「版本资源齐全的合成 PE 必须绿」正控 + 真子进程 cp1252/cp437 回归(红/绿两路)
- release-build.yml: 读回步骤先 ls -l 落产物大小,输出 tee 后逐行转 ::error:: 注解
  (下次红能看到原因,不再只有退出码)
- 判据未降:仍然是读产物字节、仍然 exit 1,未改任何断言

实测:RUSTFLAGS='-C target-feature=+crt-static' 的 release 产物本机读回 exit 0;
同产物同命令在 PYTHONIOENCODING=cp1252 下,修前 exit 1 + traceback、修后 exit 0。
This commit is contained in:
AskaEth committed 2026-11-12 09:25:30 +08:00
1 parent 03b644fa0c
commit 47386ef2ff
2 files changed
+158 -18

No files matched your search

+22 -1
View File
@@ -226,10 +226,31 @@ jobs:
set -euo pipefail
PY=$(command -v python3 || command -v python)
if [ -z "$PY" ]; then echo "::error::找不到 python,PE 版本资源门禁无法运行(门禁不降级)"; exit 1; fi
# 先把「产物到底是哪个文件、多大」落成日志:这一步红了,第一件要排除的就是「读的不是那个文件」。
# `|| echo` 是刻意的:让「文件不存在」的判据由检查器自己报(它的措辞比 ls 更适合当注解)。
ls -l "$BUILD_DIR/unlucky-launcher-iced.exe" "$BUILD_DIR/ull.exe" \
|| echo "::warning::ls 没列出产物(文件可能不存在),判据交给下面的检查器"
# 版本号与 Cargo.toml **同源**:`[workspace.package] version = "x.y.z"`。
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
echo "expect-version=$version"
"$PY" packaging/check_pe_version.py "$BUILD_DIR/unlucky-launcher-iced.exe" "$BUILD_DIR/ull.exe" --expect-version "$version"
# 判据本身不降级(仍然只看产物字节、仍然 exit 1),但**失败原因必须自己浮出来**:v0.2.4 的
# run 43031591576 两个 Windows 槽位红在这里,注解 API 上只剩一句 `Process completed with exit
# code 1.`(检查器把原因打在 stderr,而 step 没转成注解),只能靠猜。故整段输出 tee 到文件,
# failure 时逐行转 `::error::` 注解。
log="$RUNNER_TEMP/pe-version.log"
status=0
"$PY" packaging/check_pe_version.py \
"$BUILD_DIR/unlucky-launcher-iced.exe" "$BUILD_DIR/ull.exe" \
--expect-version "$version" 2>&1 | tee "$log" || status=$?
if [ "$status" -ne 0 ]; then
# 上限 30 行:正常失败是「每个产物几条判据」,异常失败(traceback)也不会被截掉开头。
line_no=0
while IFS= read -r line; do
line_no=$((line_no + 1))
if [ "$line_no" -le 30 ]; then echo "::error::PE 版本资源读回:$line"; fi
done < "$log"
exit "$status"
fi
- name: Windows 单文件自检(导入表不得出现 VC++ 可再发行 DLL)
if: runner.os == 'Windows'