From e241fea8010c3c7953ef4e8d2907ed959d32c319 Mon Sep 17 00:00:00 2001 From: Wanderingss <1624155937@qq.com> Date: Fri, 2 Oct 2026 01:17:24 +0800 Subject: [PATCH] =?UTF-8?q?CI=EF=BC=9Arun=20=E8=84=9A=E6=9C=AC=E6=94=B9?= =?UTF-8?q?=E7=BA=AF=20ASCII=EF=BC=88PS5.1=20=E6=8C=89=20GBK=20=E8=A7=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=B4=E6=97=B6=20ps1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第二次 CI 运行(run#2)仍失败,但失败点前移: pwsh 问题已修(环境自检步骤确实由 Windows PowerShell 5.1 执行) 新错误:TerminatorExpectedAtEndOfString @ 含中文那一行 根因:runner 把每个 run: 块写入临时 .ps1(无 BOM)交 PS5.1 执行, PS5.1 按 GBK/CP936 解码 → UTF-8 中文字节与相邻引号错位 → 字符串缺少终止符(报错行号即含中文行,极易误判)。 与 AGENTS.md「字符串字面量必须纯 ASCII」同源。 处置:所有 run: 块内改为纯 ASCII(提示语改英文),中文仅保留在 YAML 的 name:/注释(Gitea 按 UTF-8 读、不喂 PowerShell,安全)。 workflow 头部补该坑说明。已用脚本核验 run: 块内零非 ASCII。 --- .gitea/workflows/ci.yml | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 7edfe571..c72f0037 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -20,9 +20,17 @@ # `pwsh` = PowerShell 7,**不是 Windows 自带**;本机 runner 只有 # Windows PowerShell 5.1(`C:\Windows\System32\WindowsPowerShell\v1.0\`), # 用 `shell: pwsh` 会直接报 `Cannot find: pwsh in PATH` → job 失败(跑不到任何业务逻辑)。 -# `shell: powershell` 在任意 Windows 上都存在,且本 workflow 的脚本 -# **刻意只用 PS 5.1 兼容语法**(无 `??`/`?:`/`&&`/`||`/`-Parallel`)。 -# ⚠️ 若将来要改回 `pwsh`,须先在所有 runner 上装 PowerShell 7。 +# `shell: powershell` 在任意 Windows 上都存在。 +# +# 🔴🔴 `run:` 脚本内容必须【纯 ASCII】(2026-10-02 第二次实测修正): +# runner 把每个 `run:` 块写入临时 `.ps1`(`...\act\workflow\N.ps1`)再交给 +# Windows PowerShell 5.1 执行,而该临时文件**无 BOM** → PS 5.1 按 **GBK/CP936** 解码。 +# 脚本里的 UTF-8 中文字节会与相邻引号错位 → 报 +# `TerminatorExpectedAtEndOfString` / `字符串缺少终止符: "` / `缺少右"}"` +# (报错行号正是含中文的那一行,极易误判为逻辑错误)。 +# **故本文件所有 `run:` 块内零非 ASCII**(中文仅出现在 YAML 的 name:/注释里—— +# 那些由 Gitea 按 UTF-8 读,不喂给 PowerShell,安全)。 +# ⚠️ 与 AGENTS.md「字符串字面量必须纯 ASCII」同源;改脚本时务必守住。 # # ⚠️ 前置(部署到 Gitea 时需确认): # - 该 Gitea 实例已启用 Actions:`[actions] ENABLED = true`(site admin 配置) @@ -81,19 +89,19 @@ jobs: } } if ($missing.Count -gt 0) { - Write-Host "::error::runner 缺少:$($missing -join ', ') —— 请安装后重跑" + Write-Host "::error::runner missing: $($missing -join ', ') -- install then re-run" exit 1 } python --version cppcheck --version - # pre-commit:优先用 `python -m pre_commit`(不依赖 PATH 里的 console script) + # pre-commit: use `python -m pre_commit` (does not rely on PATH console script) python -m pre_commit --version if ($LASTEXITCODE -ne 0) { - Write-Host "::error::runner 缺少 pre-commit(pip install pre-commit / uv tool install pre-commit)" + Write-Host "::error::runner missing pre-commit (pip install pre-commit)" exit 1 } - Write-Host "runner 环境自检通过" + Write-Host "runner environment check passed" - name: 安装 pre-commit 钩子到本仓库 shell: powershell @@ -103,14 +111,14 @@ jobs: id: skip shell: powershell run: | - # mem-numbers 的事实源是 Keil 构建产物 .map(已 gitignore)。 - # 无 .map => 本 runner 不可能跑 L0 的该钩子 => 跳过(不是"通过",是"不适用")。 + # mem-numbers fact source is the Keil build artifact .map (gitignored). + # No .map => this hook cannot run => skip (not "pass", but "not applicable"). $map = Get-ChildItem -Path 'MDK-ARM' -Recurse -Filter '*.map' -ErrorAction SilentlyContinue if ($map) { - Write-Host "找到 .map:$($map[0].FullName) —— mem-numbers 照常运行" + Write-Host "found .map: $($map[0].FullName) -- mem-numbers runs normally" "value=" | Out-File -FilePath $env:GITHUB_OUTPUT -Append } else { - Write-Host "::notice::未找到 .map(未做 Keil 构建)—— 跳过 mem-numbers 钩子" + Write-Host "::notice::no .map found (no Keil build) -- skipping mem-numbers hook" "value=mem-numbers" | Out-File -FilePath $env:GITHUB_OUTPUT -Append } @@ -122,7 +130,7 @@ jobs: if ($env:SKIP) { Write-Host "SKIP=$env:SKIP" } python -m pre_commit run --all-files --show-diff-on-failure if ($LASTEXITCODE -ne 0) { - Write-Host "::error::L0 静态门禁未通过(详见上方输出)" + Write-Host "::error::L0 static gates failed (see output above)" exit $LASTEXITCODE } @@ -139,7 +147,7 @@ jobs: id: msvc shell: powershell run: | - # 与 test/host/common/unit_test_harness.py 的 VS_ROOTS 保持一致 + # Keep in sync with VS_ROOTS in test/host/common/unit_test_harness.py $roots = @( 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools', 'C:\Program Files\Microsoft Visual Studio\2022\BuildTools', @@ -151,13 +159,13 @@ jobs: if (Test-Path $r) { $cl = Get-ChildItem -Path $r -Recurse -Filter 'cl.exe' -ErrorAction SilentlyContinue | Where-Object { $_.FullName -like '*Hostx64\x64*' } | Select-Object -First 1 - if ($cl) { $found = $true; Write-Host "找到 cl.exe: $($cl.FullName)"; break } + if ($cl) { $found = $true; Write-Host "found cl.exe: $($cl.FullName)"; break } } } if ($found) { "value=yes" | Out-File -FilePath $env:GITHUB_OUTPUT -Append } else { - Write-Host "::warning::runner 未安装 MSVC(VS C++ 工具链)—— 跳过 L0.5 单测。请安装 VS BuildTools 后重跑。" + Write-Host "::warning::runner has no MSVC (VS C++ toolchain) -- skipping L0.5. Install VS BuildTools and re-run." "value=no" | Out-File -FilePath $env:GITHUB_OUTPUT -Append } @@ -165,21 +173,21 @@ jobs: if: steps.msvc.outputs.value == 'yes' shell: powershell run: | - # 遍历 test/host/*/run_unit_test.py(各模块自带运行器,统一走 common harness) + # Iterate test/host/*/run_unit_test.py (each module ships its own runner via common harness) $runners = Get-ChildItem -Path 'test/host' -Recurse -Filter 'run_unit_test.py' | Sort-Object FullName if (-not $runners) { - Write-Host "::warning::未找到 test/host/**/run_unit_test.py —— 跳过" + Write-Host "::warning::no test/host/**/run_unit_test.py found -- skipping" exit 0 } $fail = 0 foreach ($r in $runners) { Write-Host "================================" - Write-Host "运行:$($r.FullName)" + Write-Host "run: $($r.FullName)" Write-Host "================================" python $r.FullName if ($LASTEXITCODE -ne 0) { - Write-Host "::error::单测失败:$($r.FullName)(退出码 $LASTEXITCODE)" + Write-Host "::error::unit test failed: $($r.FullName) (exit $LASTEXITCODE)" $fail = 1 } } @@ -189,6 +197,6 @@ jobs: if: steps.msvc.outputs.value == 'no' shell: powershell run: | - Write-Host "L0.5 未执行:runner 缺 MSVC。" - Write-Host "本地等价命令:& '.venv\Scripts\python.exe' scripts/ci_local.py" + Write-Host "L0.5 skipped: runner has no MSVC." + Write-Host "Local equivalent: & '.venv\Scripts\python.exe' scripts/ci_local.py" exit 0