From 4667d94c45fad926365a3b703404aea7a78223b2 Mon Sep 17 00:00:00 2001 From: sloray Date: Thu, 15 Oct 2026 22:10:57 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BF=AE=20Windows=20job=200=20=E7=A7=92?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=20=E2=80=94=E2=80=94=20=E5=AE=BF=E4=B8=BB=20?= =?UTF-8?q?runner=20=E4=B8=8A=E7=9A=84=20bash=20=E6=98=AF=20WSL=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=20Git=20Bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit run 3 里 Windows job 挂在第二步、耗时 0 秒: 装 Rust(stable) [failure] 14:01:42 → 14:01:42 装 pnpm / 装 Node / 前端依赖 / 打包 / 上传产物 [skipped] 日志里是一串被当 UTF-8 解码的 GBK: ?b?~? 0 ?Nx? B a s h / E _ A C C E S S D E N I E D ... https://github.com/microsoft/WSL/issues 就是 WSL 的 E_ACCESSDENIED:这台 runner 是宿主直跑,PATH 上的 `bash` 指向 C:\Windows\System32\bash.exe(WSL 启动器),而 WSL 在 runner 账户下起不来。于是 所有 shell: bash 的步骤、以及用 bash 写的 composite action(dtolnay/rust-toolchain 就是),都会在 0 秒内失败。 修法:Windows job 的 checkout 之后插一步(shell: pwsh),把 "C:\Program Files\Git\bin" 写进 GITHUB_PATH —— 它的语义是前置插入,会盖过 System32 那个 WSL 版 bash。本机(就是这台 runner)实测通过: bash -> C:\Program Files\Git\bin\bash.exe rustup toolchain install stable --profile minimal exit=0 rustup target add --toolchain stable x86_64-pc-windows-msvc exit=0 rustup run stable rustc --version / cargo --version exit=0 在仓库根目录跑也一样:根 rust-toolchain.toml 的 `esp` override 不影响这几条命令, 只有裸 rustc/cargo 才会撞上它,而 workflow 里没有这种步骤。 顺带:run 3 里 Linux 那条是好的(检查 2m42s、Linux 9m14s 全绿)。 --- .github/workflows/build-client.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/build-client.yml b/.github/workflows/build-client.yml index 7f0a06c..9816005 100644 --- a/.github/workflows/build-client.yml +++ b/.github/workflows/build-client.yml @@ -336,6 +336,28 @@ jobs: steps: - uses: actions/checkout@v4 + # 宿主模式的 Windows runner 上,PATH 里的 `bash` 是 C:\Windows\System32\bash.exe + # —— WSL 的启动器,而 WSL 在 runner 账户下起不来,报 E_ACCESSDENIED(日志里是 + # 一串 GBK 被当 UTF-8 解出来的乱码 + https://github.com/microsoft/WSL/issues)。 + # 于是任何 `shell: bash` 的步骤、以及用 bash 写的 composite action + # (dtolnay/rust-toolchain 就是),都会在 0 秒内失败。 + # Git for Windows 自带 bash,把它的 bin 前置到 PATH —— GITHUB_PATH 的语义就是 + # **前置**插入,所以它会盖过 System32 那个 —— 后面这些步骤才跑得起来。 + # 2026-10-15 第一次真跑 Windows job 时踩出来的(本地这样改完,dtolnay 要跑的 + # rustup toolchain install / target add / rustc / cargo 全部 exit 0)。 + - name: 让 bash 指向 Git for Windows(不是 WSL) + shell: pwsh + run: | + $gitBash = 'C:\Program Files\Git\bin' + if (-not $env:GITHUB_PATH) { + throw '这个 runner 没提供 GITHUB_PATH,没法给后续步骤改 PATH' + } + if (-not (Test-Path (Join-Path $gitBash 'bash.exe'))) { + throw "找不到 $gitBash\bash.exe:这台机器上没装 Git for Windows,bash 会落到 WSL 上" + } + Add-Content -Path $env:GITHUB_PATH -Value $gitBash -Encoding ascii + "后续步骤的 bash = $(Join-Path $gitBash 'bash.exe')" + - name: 装 Rust(stable) uses: dtolnay/rust-toolchain@stable with: