Skip to content

Commit 9fbd2e4

Browse files
committed
build: multi channel install test
1 parent 4bd84e9 commit 9fbd2e4

4 files changed

Lines changed: 47 additions & 17 deletions

File tree

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ jobs:
5757
5858
- run: pnpm install --frozen-lockfile
5959

60+
# Binary compile uses `bun build --compile` CLI (not Bun.build API).
61+
# Keep this pin in sync with any local smoke tests of binary-compile.mjs.
6062
- uses: oven-sh/setup-bun@v2
6163
with:
6264
bun-version: "1.2.19"
@@ -97,6 +99,8 @@ jobs:
9799
98100
- run: pnpm install --frozen-lockfile
99101

102+
# Binary compile uses `bun build --compile` CLI (not Bun.build API).
103+
# Keep this pin in sync with any local smoke tests of binary-compile.mjs.
100104
- uses: oven-sh/setup-bun@v2
101105
with:
102106
bun-version: "1.2.19"

docs/agents/binary-distribution.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ vp check
6161
| FC 未跑完用户就 curl | OSS 404 / 半包 |
6262
| 矩阵变更未通知脚本方 | 装错 arch / 永久失败 |
6363
| webhook 配错当发版失败 | 不应;webhook 失败只 warn |
64+
|`Bun.build({ compile })` 代替 CLI | Bun ≤1.2.19 可能 exit 0 但不写 outfile → `sha256` ENOENT |
65+
66+
## 编译实现注意
67+
68+
- `binary-compile.mjs` 必须走 **`bun build --compile --outfile …`**,不要用 `Bun.build({ compile })`(CI 钉 `1.2.19` 时 API 会假成功)。
69+
- 编译后校验 outfile 存在再算 SHA256。

tools/release/lib/binary-build.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ function compileOne({ bunTarget, os, arch, exe }, version, outdir, entry) {
150150
);
151151
if (result.status !== 0) {
152152
process.stderr.write(result.stderr || result.stdout || "");
153-
throw new Error(`Bun.build compile failed for ${bunTarget}`);
153+
throw new Error(`Bun compile failed for ${bunTarget}`);
154154
}
155+
if (result.stdout) process.stdout.write(result.stdout);
156+
if (result.stderr) process.stderr.write(result.stderr);
155157
return { fileName, outfile, os, arch, sha256: sha256File(outfile) };
156158
}
157159

tools/release/lib/binary-compile.mjs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
/**
2-
* Single-target `Bun.build({ compile })` helper. Must be run with Bun:
2+
* Single-target Bun compile helper. Must be run with Bun on PATH:
33
* bun tools/release/lib/binary-compile.mjs --entry <path> --outfile <path> --target <bun-target>
44
*
5+
* Uses `bun build --compile` (CLI), not `Bun.build({ compile })`.
6+
* Bun ≤1.2.19's Build API can report success without writing `compile.outfile`
7+
* (API support landed properly around 1.2.21). CLI works on the pinned CI version.
8+
*
59
* Called by binary-build.mjs (Node orchestration stays on Node).
610
*/
11+
import { existsSync } from "node:fs";
12+
import { spawnSync } from "node:child_process";
13+
714
function parseArgs(argv) {
815
let entry = null;
916
let outfile = null;
@@ -30,22 +37,33 @@ function parseArgs(argv) {
3037

3138
const { entry, outfile, target } = parseArgs(process.argv.slice(2));
3239

33-
const result = await Bun.build({
34-
entrypoints: [entry],
35-
// Bundler defaults to "browser"; CLI needs Node/Bun builtins.
36-
target: "bun",
37-
define: {
38-
"process.env.BAILIAN_COMPILED": JSON.stringify("1"),
39-
},
40-
compile: {
41-
target,
40+
const result = spawnSync(
41+
"bun",
42+
[
43+
"build",
44+
entry,
45+
"--compile",
46+
"--outfile",
4247
outfile,
43-
},
44-
});
48+
"--target",
49+
target,
50+
"--define",
51+
'process.env.BAILIAN_COMPILED="1"',
52+
],
53+
{ encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] },
54+
);
4555

46-
if (!result.success) {
47-
for (const log of result.logs) {
48-
console.error(log);
49-
}
56+
if (result.stdout) process.stdout.write(result.stdout);
57+
if (result.stderr) process.stderr.write(result.stderr);
58+
59+
if (result.status !== 0) {
60+
process.exit(result.status ?? 1);
61+
}
62+
63+
if (!existsSync(outfile)) {
64+
console.error(
65+
`bun build --compile exited 0 but outfile missing: ${outfile}\n` +
66+
`(Bun Build API compile.outfile is unreliable on some versions; this helper uses the CLI.)`,
67+
);
5068
process.exit(1);
5169
}

0 commit comments

Comments
 (0)