test: 增加发布包运行时预检

This commit is contained in:
que01 committed 2026-10-20 21:24:21 +08:00
1 parent 16fd827634
commit ea81c754ed
3 files changed
+63 -2

No files matched your search

@@ -1,7 +1,7 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"scope": "模板完成证据登记,保留命令、日志与产物哈希", "scope": "模板完成证据登记,保留命令、日志与产物哈希",
"generatedAt": "2026-10-20T09:58:15.011Z", "generatedAt": "2026-10-20T13:23:08.179Z",
"templates": { "templates": {
"acheng-campus-food": { "acheng-campus-food": {
"real-manifest-interaction": { "real-manifest-interaction": {
@@ -256,5 +256,5 @@
} }
} }
}, },
"sourceTreeHash": "a1dbfac7dbf6897814276ca0188c78808c587253307fa6f865761645bf054cdb" "sourceTreeHash": "d7e89045378d64c92977fbd664fac32902bc6fcdf003d9e79a7c9b6bf5b22c46"
} }
+4
View File
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process"; import { spawnSync } from "node:child_process";
import { createRequire } from "node:module"; import { createRequire } from "node:module";
import { checkPackage } from "./check-package.mjs"; import { checkPackage } from "./check-package.mjs";
import { verifyRuntimePreflight } from "./runtime-preflight.mjs";
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
const { findLeaks, loadConfig } = require("../../apps/taro/config/mask-taro.cjs"); const { findLeaks, loadConfig } = require("../../apps/taro/config/mask-taro.cjs");
@@ -173,6 +174,8 @@ async function buildTemplateCatalog() {
} }
async function main() { async function main() {
if (Number(process.versions.node.split(".")[0]) !== 24)
throw new Error("Node.js 24 is required to build the release");
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,100}$/.test(version)) if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,100}$/.test(version))
throw new Error("Invalid release version"); throw new Error("Invalid release version");
const adminDist = path.join(root, "apps/admin/dist"); const adminDist = path.join(root, "apps/admin/dist");
@@ -245,6 +248,7 @@ async function main() {
} }
await writeFile(path.join(output, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n"); await writeFile(path.join(output, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
await checkPackage(output); await checkPackage(output);
await verifyRuntimePreflight(output);
run("tar", ["-czf", archive, "-C", output, "."]); run("tar", ["-czf", archive, "-C", output, "."]);
const checksum = createHash("sha256") const checksum = createHash("sha256")
.update(await readFile(archive)) .update(await readFile(archive))
+57
View File
@@ -0,0 +1,57 @@
import { cp, mkdtemp, rm } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
/**
* 在临时目录中验证发布包的运行时依赖闭包。
* 冻结安装只能证明锁文件一致,不能证明打包时没有遗漏 workspace package。
*/
export async function verifyRuntimePreflight(releaseDirectory) {
const temporary = await mkdtemp(path.join(os.tmpdir(), "personal-brand-runtime-"));
const apiDirectory = path.join(temporary, "apps/api");
try {
await cp(releaseDirectory, temporary, { recursive: true });
run(
"pnpm",
[
"--filter",
"@personal-brand/api...",
"--filter",
"@personal-brand/taro...",
"--filter",
"@personal-brand/template-acheng-campus-food",
"--filter",
"@personal-brand/template-linjing-editorial",
"--filter",
"@personal-brand/template-atelier-solopreneur",
"install",
"--frozen-lockfile",
"--prefer-offline",
"--ignore-scripts",
],
temporary,
);
run("pnpm", ["--filter", "@personal-brand/api", "exec", "prisma", "generate"], temporary);
run(
process.execPath,
["--input-type=module", "-e", "await import('./dist/main.js')"],
apiDirectory,
{ NODE_ENV: "test" },
);
} finally {
await rm(temporary, { recursive: true, force: true });
}
}
function run(command, args, cwd, extraEnvironment = {}) {
const result = spawnSync(command, args, {
cwd,
stdio: "inherit",
env: { ...process.env, ...extraEnvironment },
});
if (result.status !== 0)
throw new Error(
`${command} failed during release runtime preflight with exit ${result.status}`,
);
}