From 9fbd2e4ec6fee8158cd2f70fcd194a7b9e38287b Mon Sep 17 00:00:00 2001 From: rendianmeng Date: Thu, 23 Jul 2026 18:12:42 +0800 Subject: [PATCH] build: multi channel install test --- .github/workflows/publish.yml | 4 +++ docs/agents/binary-distribution.md | 6 ++++ tools/release/lib/binary-build.mjs | 4 ++- tools/release/lib/binary-compile.mjs | 50 +++++++++++++++++++--------- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 23a33a3..0346059 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -57,6 +57,8 @@ jobs: - run: pnpm install --frozen-lockfile + # Binary compile uses `bun build --compile` CLI (not Bun.build API). + # Keep this pin in sync with any local smoke tests of binary-compile.mjs. - uses: oven-sh/setup-bun@v2 with: bun-version: "1.2.19" @@ -97,6 +99,8 @@ jobs: - run: pnpm install --frozen-lockfile + # Binary compile uses `bun build --compile` CLI (not Bun.build API). + # Keep this pin in sync with any local smoke tests of binary-compile.mjs. - uses: oven-sh/setup-bun@v2 with: bun-version: "1.2.19" diff --git a/docs/agents/binary-distribution.md b/docs/agents/binary-distribution.md index 066f7e9..c521def 100644 --- a/docs/agents/binary-distribution.md +++ b/docs/agents/binary-distribution.md @@ -61,3 +61,9 @@ vp check | FC 未跑完用户就 curl | OSS 404 / 半包 | | 矩阵变更未通知脚本方 | 装错 arch / 永久失败 | | webhook 配错当发版失败 | 不应;webhook 失败只 warn | +| 用 `Bun.build({ compile })` 代替 CLI | Bun ≤1.2.19 可能 exit 0 但不写 outfile → `sha256` ENOENT | + +## 编译实现注意 + +- `binary-compile.mjs` 必须走 **`bun build --compile --outfile …`**,不要用 `Bun.build({ compile })`(CI 钉 `1.2.19` 时 API 会假成功)。 +- 编译后校验 outfile 存在再算 SHA256。 diff --git a/tools/release/lib/binary-build.mjs b/tools/release/lib/binary-build.mjs index 737c797..d076aca 100644 --- a/tools/release/lib/binary-build.mjs +++ b/tools/release/lib/binary-build.mjs @@ -150,8 +150,10 @@ function compileOne({ bunTarget, os, arch, exe }, version, outdir, entry) { ); if (result.status !== 0) { process.stderr.write(result.stderr || result.stdout || ""); - throw new Error(`Bun.build compile failed for ${bunTarget}`); + throw new Error(`Bun compile failed for ${bunTarget}`); } + if (result.stdout) process.stdout.write(result.stdout); + if (result.stderr) process.stderr.write(result.stderr); return { fileName, outfile, os, arch, sha256: sha256File(outfile) }; } diff --git a/tools/release/lib/binary-compile.mjs b/tools/release/lib/binary-compile.mjs index 250c70a..8cd288c 100644 --- a/tools/release/lib/binary-compile.mjs +++ b/tools/release/lib/binary-compile.mjs @@ -1,9 +1,16 @@ /** - * Single-target `Bun.build({ compile })` helper. Must be run with Bun: + * Single-target Bun compile helper. Must be run with Bun on PATH: * bun tools/release/lib/binary-compile.mjs --entry --outfile --target * + * Uses `bun build --compile` (CLI), not `Bun.build({ compile })`. + * Bun ≤1.2.19's Build API can report success without writing `compile.outfile` + * (API support landed properly around 1.2.21). CLI works on the pinned CI version. + * * Called by binary-build.mjs (Node orchestration stays on Node). */ +import { existsSync } from "node:fs"; +import { spawnSync } from "node:child_process"; + function parseArgs(argv) { let entry = null; let outfile = null; @@ -30,22 +37,33 @@ function parseArgs(argv) { const { entry, outfile, target } = parseArgs(process.argv.slice(2)); -const result = await Bun.build({ - entrypoints: [entry], - // Bundler defaults to "browser"; CLI needs Node/Bun builtins. - target: "bun", - define: { - "process.env.BAILIAN_COMPILED": JSON.stringify("1"), - }, - compile: { - target, +const result = spawnSync( + "bun", + [ + "build", + entry, + "--compile", + "--outfile", outfile, - }, -}); + "--target", + target, + "--define", + 'process.env.BAILIAN_COMPILED="1"', + ], + { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }, +); -if (!result.success) { - for (const log of result.logs) { - console.error(log); - } +if (result.stdout) process.stdout.write(result.stdout); +if (result.stderr) process.stderr.write(result.stderr); + +if (result.status !== 0) { + process.exit(result.status ?? 1); +} + +if (!existsSync(outfile)) { + console.error( + `bun build --compile exited 0 but outfile missing: ${outfile}\n` + + `(Bun Build API compile.outfile is unreliable on some versions; this helper uses the CLI.)`, + ); process.exit(1); }