From 5e3d20fee665fc010ae1ebd1a6dc313848848aee Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:05:27 +0800 Subject: [PATCH 1/3] CI saves caches only on main, releases save none, Windows release builds each architecture on its own runner - ci.yml: `rust-cache` saves only on pushes to main. A PR can read its own caches, its base branch's and the default branch's, never another PR's, so a cache saved on a PR served only a later push to that same PR while taking as much of the 10 GB quota as main's and pushing main's out. - release.yml: no cache is saved. A tag run's cache is filed under that tag and no later tag can read it; v0.64.0 and v0.64.1 left about 1.5 GB each. - release.yml: the Windows job becomes a matrix, x64 on windows-latest and arm64 natively on windows-11-arm, in parallel. It built both in a row and took about twice as long as any other platform, holding up the release; the arm64 binary is now also run, not only checked by its PE header. - ci.yml: the Windows start-up check uses a debug build: it proves the binary starts and answers only after the handshake, which does not depend on the optimisation level, and the release build added about four minutes to the slowest job. The macOS and Linux smoke runs keep the release build, since their memory and latency targets only hold for it (a debug build sits at about 55 MB against the 30 MB target). Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 20 ++++- .github/workflows/release.yml | 162 ++++++++++++++++++---------------- 2 files changed, 104 insertions(+), 78 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe1888e1..deb95947 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,13 @@ jobs: components: rustfmt, clippy # 插件沙箱里的 QuickJS 编成这个目标(crates/tw-plugin/build.rs) targets: wasm32-unknown-unknown + # **只在 main 上存。**一个 PR 读得到的缓存只有三处:它自己的、目标分支的、 + # 默认分支的,读不到别的 PR 存的。PR 上存的那份只有同一个 PR 再推一次才 + # 用得上,却和 main 的一样大,挤占仓库 10 GB 的缓存额度、把 main 的挤掉。 + # main 每次推送都存一份,之后每个 PR 从它起步,只重编自己改到的部分 - uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} # 编插件沙箱要一个能出 wasm 的 clang:这里是 Homebrew 的 llvm,由 build.rs # 自己找到(顺便测了「装了 brew 的 llvm 就能编」这条路) @@ -155,6 +161,8 @@ jobs: if: steps.changed.outputs.layer1 == 'true' with: workspaces: enterprise -> target + # 见 check 那一段 + save-if: ${{ github.ref == 'refs/heads/main' }} - name: cargo check (enterprise) if: steps.changed.outputs.layer1 == 'true' @@ -185,6 +193,8 @@ jobs: with: # 理由见下面 windows 那一段 cache-on-failure: true + # 见 check 那一段 + save-if: ${{ github.ref == 'refs/heads/main' }} # 镜像预装的 clang-15,显式指定(见脚本) - name: Toolchain for the plugin sandbox @@ -226,6 +236,8 @@ jobs: # cargo 自己按指纹判断哪些要重编,所以缓存下一个失败构建的 # target 目录是安全的,它只是省掉那些与失败无关的部分。 cache-on-failure: true + # 见 check 那一段。PR 上不存,所以上面那条只对 main 起作用 + save-if: ${{ github.ref == 'refs/heads/main' }} # 镜像预装的 LLVM(C:\Program Files\LLVM),由 build.rs 自己找到 - name: Toolchain for the plugin sandbox @@ -242,8 +254,12 @@ jobs: shell: bash run: bash scripts/wasm-toolchain.sh record target + # **debug 版就够了。**这一步证明的是它起得来、握手是唯一的门,和优化级别 + # 无关;release 版每次 PR 都要多编四分钟,这个任务本来就是最慢的那个。 + # 内存、延迟这些资源目标要 release 版才量得准,那在 macOS 和 Linux 的 + # smoke 里量;发出去的 release 版由 release.yml 在发版时自己跑一遍 - name: Build - run: cargo build --release -p twcore + run: cargo build -p twcore # macOS 那边的 smoke 脚本在这里跑不了(`stat -f`、一堆 BSD 的写法), # 移植它是另一件事。但**至少要证明这个二进制真的起得来、控制面真的应答** @@ -260,7 +276,7 @@ jobs: New-Item -ItemType Directory -Force -Path $home_ | Out-Null $env:THINKWATCH_HOME = $home_ $cfg = Join-Path $home_ "config.yaml" - $bin = "target\release\twcore.exe" + $bin = "target\debug\twcore.exe" $proc = Start-Process -FilePath $bin ` -ArgumentList "serve","--config",$cfg,"--port","18999" ` -PassThru -NoNewWindow ` diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de984c03..c959219f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,9 +22,9 @@ on: # 运行的产物(Artifacts)里,`publish` 照样把它们逐个核对,只是不写 Release。 # # 理由是这条流水线唯一一个「发现了也没法在本次补救」的性质:tag 一旦 - # 推上去,流水线错了就得把它撤回来。而这里新增的那条 Windows 支线要靠 - # 交叉编译到 arm64,那件事成不成只有真跑一次才知道 —— 用一个 tag 去 - # 问这个问题太贵了。 + # 推上去,流水线错了就得把它撤回来。改了这条流水线(换 runner、加平台), + # 成不成只有真跑一次才知道 —— 用一个 tag 去问这个问题太贵了。 + # `gh workflow run release.yml --ref <分支>` 跑的是那个分支上的这份文件。 workflow_dispatch: permissions: @@ -46,7 +46,12 @@ jobs: with: # wasm32:插件沙箱里的 QuickJS(crates/tw-plugin/build.rs) targets: aarch64-apple-darwin, wasm32-unknown-unknown + # **只读不存。**tag 上的运行读得到的缓存只有两处:这个 tag 自己的、默认分支 + # (main)的。存下来的缓存挂在这个 tag 名下,下一个 tag 读不到,等于白占仓库 + # 10 GB 的缓存额度 —— 还会把 main 上 CI 天天在用的缓存挤掉 - uses: Swatinem/rust-cache@v2 + with: + save-if: false # 编插件沙箱要一个能出 wasm 的 clang:Homebrew 的 llvm - name: Toolchain for the plugin sandbox @@ -103,131 +108,134 @@ jobs: if-no-files-found: error twcore-windows: - name: twcore (Windows x64 + arm64) - # **两个架构都发**(x64 和 arm64)。x64 原生编,arm64 在同一台 x64 - # runner 上交叉编 —— MSVC 的 ARM64 工具链在这个镜像里,而起一台 - # arm64 runner 只为编一个二进制不划算。 - # - # 交叉编译成不成,靠上面那个排练模式先问清楚,而不是拿一个 tag 去问。 - runs-on: windows-latest + name: twcore (${{ matrix.target }}) + # **两个架构各在自己架构的 runner 上原生编**,和 Linux 一样。以前 arm64 在 x64 + # 的 runner 上接着 x64 交叉编,两遍串行,这个 job 一个人就比别的平台多花一倍 + # 时间、拖住整个发版;拆开之后两个并行跑。原生编还能把 arm64 的产物真跑一遍, + # 交叉编的只能读 PE 头看它是不是 arm64。 + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-pc-windows-msvc + runner: windows-latest + machine: "0x8664" + host: x64 + - target: aarch64-pc-windows-msvc + runner: windows-11-arm + machine: "0xAA64" + host: arm64 + runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: - targets: x86_64-pc-windows-msvc, aarch64-pc-windows-msvc, wasm32-unknown-unknown + targets: ${{ matrix.target }}, wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + # 见 twcore 那一段 + save-if: false # 镜像预装的 LLVM(C:\Program Files\LLVM);没有就装官方发行版 - name: Toolchain for the plugin sandbox shell: bash run: bash scripts/wasm-toolchain.sh - # arm64 的沙箱机器码在 x64 上交叉编:build.rs 里的 Cranelift 直接编给目标平台 - name: Build - run: | - cargo build --release -p twcore -p tw-plugin --target x86_64-pc-windows-msvc - cargo build --release -p twcore -p tw-plugin --target aarch64-pc-windows-msvc + run: cargo build --release -p twcore -p tw-plugin --target ${{ matrix.target }} - name: Which compiler built the plugin sandbox shell: bash - run: | - for t in x86_64-pc-windows-msvc aarch64-pc-windows-msvc; do - bash scripts/wasm-toolchain.sh record "target/$t/release" "guest-build/$t.txt" - done + run: bash scripts/wasm-toolchain.sh record "target/${{ matrix.target }}/release" "guest-build/${{ matrix.target }}.txt" - uses: actions/upload-artifact@v4 with: - name: guest-build-windows + name: guest-build-${{ matrix.target }} path: guest-build/ if-no-files-found: error # **产物自检。**一个编得过但起不来的二进制,从文件列表上看不出任何 # 问题 —— 而它会一路发到用户手里。 # - # arm64 那个在这台机器上跑不起来(x64 runner),所以只能查它到底是不是 - # arm64 —— 读 PE 头里的 machine 字段,等价于 macOS 那边的 `file | grep - # arm64`。**这一条不是走过场**:交叉编译配错目标的表现正是产出一个 - # 名字叫 arm64 的 x64 二进制。 - - name: They are what they claim to be, and the x64 one runs + # PE 头里的 machine 字段,等价于 macOS 那边的 `file | grep arm64`:目标配错 + # 的表现正是产出一个名字叫 arm64 的 x64 二进制,而 arm64 的 Windows 能模拟 + # 跑 x64 —— 光是跑得起来证明不了它是哪个架构 + - name: It is what it claims to be, it runs, and it is the version on the tag shell: pwsh + env: + TARGET: ${{ matrix.target }} + MACHINE: ${{ matrix.machine }} run: | $ErrorActionPreference = "Stop" - function Get-PeMachine([string]$path) { - $fs = [System.IO.File]::OpenRead($path) - try { - $br = New-Object System.IO.BinaryReader($fs) - $fs.Position = 0x3C - $fs.Position = $br.ReadInt32() - if ($br.ReadUInt32() -ne 0x00004550) { throw "$path is not a PE file" } - return $br.ReadUInt16() - } finally { $fs.Dispose() } - } - $want = @{ - "target\x86_64-pc-windows-msvc\release\twcore.exe" = 0x8664 - "target\aarch64-pc-windows-msvc\release\twcore.exe" = 0xAA64 - } - foreach ($p in $want.Keys) { - $got = Get-PeMachine $p - if ($got -ne $want[$p]) { - throw ("{0} is machine 0x{1:X4}, expected 0x{2:X4}" -f $p, $got, $want[$p]) - } - Write-Host ("{0}: 0x{1:X4}" -f $p, $got) + $exe = "target\$env:TARGET\release\twcore.exe" + $fs = [System.IO.File]::OpenRead($exe) + try { + $br = New-Object System.IO.BinaryReader($fs) + $fs.Position = 0x3C + $fs.Position = $br.ReadInt32() + if ($br.ReadUInt32() -ne 0x00004550) { throw "$exe is not a PE file" } + $got = $br.ReadUInt16() + } finally { $fs.Dispose() } + if ($got -ne [Convert]::ToUInt16($env:MACHINE, 16)) { + throw ("{0} is machine 0x{1:X4}, expected {2}" -f $exe, $got, $env:MACHINE) } + Write-Host ("{0}: 0x{1:X4}" -f $exe, $got) - $exe = "target\x86_64-pc-windows-msvc\release\twcore.exe" - $got = (& $exe --version).Split(" ")[1] + $ver = (& $exe --version).Split(" ")[1] if ($env:GITHUB_REF_TYPE -eq "tag") { - $wantVer = $env:GITHUB_REF_NAME.TrimStart("v") - if ($got -ne $wantVer) { - throw "the tag says $wantVer but the binary reports $got -- Cargo.toml did not keep up" + $want = $env:GITHUB_REF_NAME.TrimStart("v") + if ($ver -ne $want) { + throw "the tag says $want but the binary reports $ver -- Cargo.toml did not keep up" } } else { - Write-Host "rehearsal: the binary reports $got" + Write-Host "rehearsal: the binary reports $ver" } & $exe --help | Out-Null # **不要用户另装 VC 运行库。**VC 运行库由 `.cargo/config.toml` 静态链接进来; - # 这里查两个 exe 的导入表,里面不许有 Windows 不自带的那几个 DLL。这台 - # runner 上装着运行库,exe 照样跑得起来 —— 上一步看不出这件事,只有导入表看得出。 - # 用的是链接它的那套 MSVC 里的 dumpbin,arm64 的 exe 一样读得了 + # 这里查 exe 的导入表,里面不许有 Windows 不自带的那几个 DLL。runner 上装着 + # 运行库,exe 照样跑得起来 —— 上一步看不出这件事,只有导入表看得出。 + # 用的是这台 runner 自己架构的那套 MSVC 里的 dumpbin - name: No Visual C++ runtime to install shell: pwsh + env: + TARGET: ${{ matrix.target }} + HOST: ${{ matrix.host }} run: | $ErrorActionPreference = "Stop" $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" - $dumpbin = & $vswhere -latest -products * -find "VC\Tools\MSVC\**\bin\Hostx64\x64\dumpbin.exe" | + $dumpbin = & $vswhere -latest -products * -find "VC\Tools\MSVC\**\bin\Host$env:HOST\$env:HOST\dumpbin.exe" | Select-Object -First 1 if (-not $dumpbin) { throw "dumpbin.exe not found" } - foreach ($t in @("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc")) { - $exe = "target\$t\release\twcore.exe" - $deps = & $dumpbin /nologo /dependents $exe | - ForEach-Object { $_.Trim() } | - Where-Object { $_ -match '\.dll$' } - if ($LASTEXITCODE -ne 0 -or -not $deps) { throw "could not read the imports of $exe" } - Write-Host "${exe}: $($deps -join ', ')" - $redist = @($deps | Where-Object { $_ -match '^(vcruntime|msvcp|concrt|vccorlib|vcomp)\d' }) - if ($redist.Count -gt 0) { - throw "$exe needs the Visual C++ runtime ($($redist -join ', ')) -- the static CRT in .cargo/config.toml did not apply" - } + $exe = "target\$env:TARGET\release\twcore.exe" + $deps = & $dumpbin /nologo /dependents $exe | + ForEach-Object { $_.Trim() } | + Where-Object { $_ -match '\.dll$' } + if ($LASTEXITCODE -ne 0 -or -not $deps) { throw "could not read the imports of $exe" } + Write-Host "${exe}: $($deps -join ', ')" + $redist = @($deps | Where-Object { $_ -match '^(vcruntime|msvcp|concrt|vccorlib|vcomp)\d' }) + if ($redist.Count -gt 0) { + throw "$exe needs the Visual C++ runtime ($($redist -join ', ')) -- the static CRT in .cargo/config.toml did not apply" } - name: Package shell: pwsh + env: + TARGET: ${{ matrix.target }} run: | $ErrorActionPreference = "Stop" New-Item -ItemType Directory -Force -Path dist | Out-Null - foreach ($t in @("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc")) { - $out = "dist\twcore-$t.exe" - Copy-Item "target\$t\release\twcore.exe" $out - # **和 macOS 那边同一种校验文件**:` <文件名>`,两列, - # 两个空格 —— 下载的人用同一条 shasum -c 就能核。 - $h = (Get-FileHash $out -Algorithm SHA256).Hash.ToLower() - "$h twcore-$t.exe" | Set-Content -NoNewline -Encoding ascii "$out.sha256" - Get-Content "$out.sha256" - } + $out = "dist\twcore-$env:TARGET.exe" + Copy-Item "target\$env:TARGET\release\twcore.exe" $out + # **和 macOS 那边同一种校验文件**:` <文件名>`,两列, + # 两个空格 —— 下载的人用同一条 shasum -c 就能核。 + $h = (Get-FileHash $out -Algorithm SHA256).Hash.ToLower() + "$h twcore-$env:TARGET.exe" | Set-Content -NoNewline -Encoding ascii "$out.sha256" + Get-Content "$out.sha256" - uses: actions/upload-artifact@v4 with: - name: twcore-windows + name: twcore-${{ matrix.target }} path: dist/ if-no-files-found: error @@ -265,6 +273,8 @@ jobs: - uses: Swatinem/rust-cache@v2 with: key: ${{ matrix.target }} + # 见 twcore 那一段 + save-if: false # 两种 runner 都预装 clang-15,两个架构用同一个版本(见脚本) - name: Toolchain for the plugin sandbox From aeaa6ff8ea6fc03619d67754cfd4e254708a8c53 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:14:42 +0800 Subject: [PATCH 2/3] Smoke runs on a debug build everywhere, with a 150 MB memory ceiling instead of a 30 MB target The macOS and Linux smoke runs built the release binary only so the memory figure would sit under 30 MB, which cost three to four minutes per platform on every PR. The memory check now only catches runaway growth (a leak, a request history read into memory): a debug build after a round of requests sits at about 55 MB, the ceiling is 150 MB. The warning tier that existed only for that figure goes too. The released binary is still run by release.yml. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 12 ++++-------- scripts/smoke.sh | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index deb95947..4ef238ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,12 +74,9 @@ jobs: cargo run -p tw-api --features ts --example export_ts -- "$RUNNER_TEMP/tw-api-ts" npx --yes -p typescript@5 tsc --noEmit --strict --target es2022 "$RUNNER_TEMP/tw-api-ts/tw-api.ts" - - name: Build - run: cargo build --release -p twcore - # **接缝上的失败模式单元测试看不见**:文件权限、socket、某个端点 # 在真二进制上根本没注册。这个项目的前四个真 bug 都是这么被逮到的。 - # 脚本自己会 build,这一步只是跑它。 + # 脚本自己会 build(debug 版,见脚本),这一步只是跑它。 - name: Smoke (real binary, real socket, real data plane) run: ./scripts/smoke.sh @@ -254,10 +251,9 @@ jobs: shell: bash run: bash scripts/wasm-toolchain.sh record target - # **debug 版就够了。**这一步证明的是它起得来、握手是唯一的门,和优化级别 - # 无关;release 版每次 PR 都要多编四分钟,这个任务本来就是最慢的那个。 - # 内存、延迟这些资源目标要 release 版才量得准,那在 macOS 和 Linux 的 - # smoke 里量;发出去的 release 版由 release.yml 在发版时自己跑一遍 + # **debug 版就够了**,和 macOS、Linux 的 smoke 一样:这一步证明的是它起得来、 + # 握手是唯一的门,和优化级别无关;release 版每次 PR 都要多编四分钟。发出去的 + # release 版由 release.yml 在发版时自己跑一遍 - name: Build run: cargo build -p twcore diff --git a/scripts/smoke.sh b/scripts/smoke.sh index 18f79fe5..825b9599 100755 --- a/scripts/smoke.sh +++ b/scripts/smoke.sh @@ -26,15 +26,8 @@ PORT=18999 UPPORT=18998 PASS=0; FAIL=0 -WARN=0 ok() { PASS=$((PASS+1)); printf ' ✓ %s\n' "$1"; } bad() { FAIL=$((FAIL+1)); printf ' ✗ %s\n' "$1"; [ $# -gt 1 ] && printf ' %s\n' "$2"; } -# **超出目标但不算回归**的那一档。 -# -# 只有 ✓ 和 ✗ 两档时,一个「35MB,而目标是 30MB」只能二选一:打勾等于 -# 给一个没达标的数字盖章,打叉等于让 CI 为一个没变坏的事实一直红着。 -# 两个都会让人停止看这一行。 -warn() { WARN=$((WARN+1)); printf ' ⚠ %s\n' "$1"; [ $# -gt 1 ] && printf ' %s\n' "$2"; } step() { printf '\n== %s\n' "$1"; } # 权限位、修改时间 + 大小。**GNU 先问**:BSD 的 `stat -f` 在 GNU 上是「查文件 # 系统」,同一串参数照样返回 0、吐出一行不相干的东西,而不是失败退到下一种。 @@ -177,11 +170,14 @@ disown "$UP_PID" 2>/dev/null || true sleep 1 # ---------------------------------------------------------------- 构建 +# **debug 版。**这里查的是接缝(权限、socket、端点、真实的数据面),和优化级别 +# 无关;release 版要多编三四分钟,CI 上每个 PR、每个平台都要付一次。发出去的 +# release 版由 release.yml 在发版时自己跑一遍 step "构建" -if cargo build --release -p twcore --manifest-path "$ROOT/Cargo.toml" 2>&1 | grep -q '^error'; then +if cargo build -p twcore --manifest-path "$ROOT/Cargo.toml" 2>&1 | grep -q '^error'; then bad "构建失败"; exit 1 fi -BIN="${CARGO_TARGET_DIR:-$ROOT/target}/release/twcore" +BIN="${CARGO_TARGET_DIR:-$ROOT/target}/debug/twcore" ok "twcore 构建好了" # ---------------------------------------------------------------- init @@ -627,15 +623,13 @@ step "资源目标" RSS_KB=$(ps -o rss= -p "$CORE_PID" | tr -d ' ') RSS_MB=$((RSS_KB / 1024)) -# 目标 < 30 MB。**留一点余量但不留太多**:卡死在 30 会让一次无关的 -# 依赖升级把 CI 弄红,而放到 100 就等于没有这个检查 -if [ "$RSS_MB" -lt 30 ]; then - ok "内存 ${RSS_MB} MB(目标 < 30)" -elif [ "$RSS_MB" -lt 45 ]; then - # **不给超标的数字打勾。**那等于盖章说它达标了 - warn "内存 ${RSS_MB} MB,超出 30 MB 目标" "跑过一轮请求之后量的,不是纯冷启动;40 以内不算回归" +# **只拦失控,不抠字节。**量的是 debug 版、跑过一轮请求之后的数(2026-10 约 +# 55 MB),release 版更小。上限给到 150 MB:依赖升级、多缓存一点不该把 CI 弄红, +# 而泄漏、把整个请求历史读进内存这类问题会远远超过它 +if [ "$RSS_MB" -lt 150 ]; then + ok "内存 ${RSS_MB} MB(上限 150)" else - bad "内存 ${RSS_MB} MB,比目标高出一截" + bad "内存 ${RSS_MB} MB,超过 150 MB 上限" fi # 空闲时不写盘(最后一条)。**没有请求就不该有任何写入** —— @@ -721,5 +715,5 @@ fi # ---------------------------------------------------------------- 收尾 step "结果" -printf '通过 %d,失败 %d,超标但没回归 %d\n' "$PASS" "$FAIL" "$WARN" +printf '通过 %d,失败 %d\n' "$PASS" "$FAIL" [ "$FAIL" -eq 0 ] || exit 1 From f7e6a73c1b4ec8634e48173038a3e98b71b9cccb Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:22:13 +0800 Subject: [PATCH 3/3] CI: the platform-independent checks get their own Linux job, macOS gets a job like Linux and Windows `check` ran on macOS and held format, the sandbox guest's clippy, the TypeScript export and the macOS clippy, tests and smoke in one job, so the platform-independent steps took a macOS runner and lengthened the slowest job. `check` now runs those steps on ubuntu-22.04, with the release page text check moved in from `linux`; the new `macos` job runs clippy, tests and smoke like the other two platforms. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 75 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ef238ee..5190ffde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,23 @@ env: RUSTFLAGS: "-D warnings" jobs: + # **和平台无关的几关**:格式、沙箱胶水的 clippy、前端类型导出、发布页正文。放在 + # Linux 上一次跑完,不占 macOS 的机器,也不拖慢 macOS 那一档。 check: - runs-on: macos-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + + # 发布页的正文只在推 tag 时才写(release.yml 的 publish)。脚本和 + # `release-notes/` 下的说明在改它们的那个 PR 上就核对:链接对不对得上 + # 发出去的文件、说明里有没有混进中文。只要 Python,放在编译之前 + - name: Release page text + run: python3 scripts/release_notes_test.py + - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - # 插件沙箱里的 QuickJS 编成这个目标(crates/tw-plugin/build.rs) + # 沙箱胶水编成这个目标(crates/tw-plugin/guest) targets: wasm32-unknown-unknown # **只在 main 上存。**一个 PR 读得到的缓存只有三处:它自己的、目标分支的、 # 默认分支的,读不到别的 PR 存的。PR 上存的那份只有同一个 PR 再推一次才 @@ -33,38 +42,24 @@ jobs: with: save-if: ${{ github.ref == 'refs/heads/main' }} - # 编插件沙箱要一个能出 wasm 的 clang:这里是 Homebrew 的 llvm,由 build.rs - # 自己找到(顺便测了「装了 brew 的 llvm 就能编」这条路) - - name: Toolchain for the plugin sandbox - run: bash scripts/wasm-toolchain.sh - - name: Format run: | cargo fmt --all -- --check # 沙箱里的那个小工程不在工作区里,上面一行管不到它 cargo fmt --manifest-path crates/tw-plugin/guest/Cargo.toml -- --check - - name: clippy - run: cargo clippy --workspace --all-targets -- -D warnings + # 镜像预装的 clang-15,脚本把它写进 TW_WASM_CLANG / TW_WASM_AR + - name: Toolchain for the plugin sandbox + run: bash scripts/wasm-toolchain.sh # 沙箱里的胶水(编成 wasm32 的 no_std 小工程)。build.rs 编它时不带 -D warnings # —— 那是给外层工作区的 —— 所以它的告警只在这一步当错误 - name: clippy (plugin sandbox guest) run: | - LLVM="$(brew --prefix llvm)/bin" - CC_wasm32_unknown_unknown="$LLVM/clang" AR_wasm32_unknown_unknown="$LLVM/llvm-ar" \ + CC_wasm32_unknown_unknown="$TW_WASM_CLANG" AR_wasm32_unknown_unknown="$TW_WASM_AR" \ cargo clippy --manifest-path crates/tw-plugin/guest/Cargo.toml --target wasm32-unknown-unknown --target-dir target/tw-plugin-guest -- -D warnings - # 默认不跑打真实网络的那些(它们标了 #[ignore])—— CI 上的网络 - # 抖动会变成一条和代码无关的红,而那种红看几次就没人看了。 - - name: Test - run: cargo test --workspace - - # 编进这一版的沙箱是哪个 clang 编的、wasm 的哈希 - - name: Which compiler built the plugin sandbox - run: bash scripts/wasm-toolchain.sh record target - - # 桌面端从 tw-api 导出前端类型(`ts` feature)。**默认关**,上面几步一行都 + # 桌面端从 tw-api 导出前端类型(`ts` feature)。**默认关**,别的任务一行都 # 不编它 —— 而它坏掉的表现是桌面端接下一个 tag 时才发现导不出来。导出来 # 的文件再过一遍 tsc:ts-rs 生成的东西本身也可能不是合法的 TypeScript - name: TypeScript bindings (tw-api, ts) @@ -74,6 +69,38 @@ jobs: cargo run -p tw-api --features ts --example export_ts -- "$RUNNER_TEMP/tw-api-ts" npx --yes -p typescript@5 tsc --noEmit --strict --target es2022 "$RUNNER_TEMP/tw-api-ts/tw-api.ts" + # **桌面版的主平台。**和 Linux、Windows 两档一样:clippy、测试、真二进制。 + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + # 插件沙箱里的 QuickJS 编成这个目标(crates/tw-plugin/build.rs) + targets: wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v2 + with: + # 见 check 那一段 + save-if: ${{ github.ref == 'refs/heads/main' }} + + # 编插件沙箱要一个能出 wasm 的 clang:这里是 Homebrew 的 llvm,由 build.rs + # 自己找到(顺便测了「装了 brew 的 llvm 就能编」这条路) + - name: Toolchain for the plugin sandbox + run: bash scripts/wasm-toolchain.sh + + - name: clippy + run: cargo clippy --workspace --all-targets -- -D warnings + + # 默认不跑打真实网络的那些(它们标了 #[ignore])—— CI 上的网络 + # 抖动会变成一条和代码无关的红,而那种红看几次就没人看了。 + - name: Test + run: cargo test --workspace + + # 编进这一版的沙箱是哪个 clang 编的、wasm 的哈希 + - name: Which compiler built the plugin sandbox + run: bash scripts/wasm-toolchain.sh record target + # **接缝上的失败模式单元测试看不见**:文件权限、socket、某个端点 # 在真二进制上根本没注册。这个项目的前四个真 bug 都是这么被逮到的。 # 脚本自己会 build(debug 版,见脚本),这一步只是跑它。 @@ -176,12 +203,6 @@ jobs: steps: - uses: actions/checkout@v4 - # 发布页的正文只在推 tag 时才写(release.yml 的 publish)。脚本和 - # `release-notes/` 下的说明在改它们的那个 PR 上就核对:链接对不对得上 - # 发出去的文件、说明里有没有混进中文。只要 Python,放在编译之前 - - name: Release page text - run: python3 scripts/release_notes_test.py - - uses: dtolnay/rust-toolchain@stable with: components: clippy