chore: 固化一键生产部署流程
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Browser regression (push) Has been cancelled

This commit is contained in:
que01 committed 2026-10-13 14:56:16 +08:00
1 parent c78deafee3
commit 47a24e0d53
6 files changed
+189 -40

No files matched your search

+29 -20
View File
@@ -21,21 +21,24 @@ const contentTypes = new Map([
]);
async function checkResource(url, expectedType, label) {
const response = await fetch(url);
const response = await fetch(url, { signal: AbortSignal.timeout(10000) });
const contentType = response.headers.get("content-type") ?? "";
assert.equal(response.status, 200, label + " returned " + response.status);
assert.ok(contentType.includes(expectedType), label + " has content type " + contentType);
await response.body?.cancel();
}
async function checkHtmlAssets(relativeEntry, localPath, publicPath) {
const html = await readFile(localPath, "utf8");
const checks = [];
for (const match of html.matchAll(/(?:src|href)=["']([^"']+)["']/g)) {
const asset = match[1];
if (!/\.(?:js|css)(?:[?#]|$)/.test(asset)) continue;
const url = new URL(asset, baseUrl + publicPath);
const expectedType = /\.css(?:[?#]|$)/.test(url.pathname) ? "text/css" : "javascript";
await checkResource(url, expectedType, relativeEntry + " -> " + asset);
checks.push(checkResource(url, expectedType, relativeEntry + " -> " + asset));
}
await Promise.all(checks);
}
async function listFiles(directory, prefix = "") {
@@ -49,7 +52,9 @@ async function listFiles(directory, prefix = "") {
return files;
}
const apiHealthResponse = await fetch(baseUrl + "/api/health");
const apiHealthResponse = await fetch(baseUrl + "/api/health", {
signal: AbortSignal.timeout(10000),
});
assert.equal(apiHealthResponse.status, 200, "public API health check failed");
assert.match(apiHealthResponse.headers.get("content-type") ?? "", /application\/json/);
assert.equal((await apiHealthResponse.json()).status, "ok");
@@ -67,23 +72,27 @@ for (const [entry, localFile, publicPath] of [
}
const assetRoot = path.join(root, "apps/admin/dist/assets");
for (const asset of await listFiles(assetRoot)) {
const extension = path.extname(asset).toLowerCase();
const expectedType = contentTypes.get(extension);
if (!expectedType) continue;
await checkResource(
baseUrl + "/assets/" + asset.split("/").map(encodeURIComponent).join("/"),
expectedType,
"static asset " + asset,
);
}
await Promise.all(
(await listFiles(assetRoot)).map(async (asset) => {
const extension = path.extname(asset).toLowerCase();
const expectedType = contentTypes.get(extension);
if (!expectedType) return;
await checkResource(
baseUrl + "/assets/" + asset.split("/").map(encodeURIComponent).join("/"),
expectedType,
"static asset " + asset,
);
}),
);
for (const entry of await readdir(path.join(root, "seed-media"))) {
await checkResource(
baseUrl + "/media/seed/" + encodeURIComponent(entry),
"image/jpeg",
"seed media " + entry,
);
}
await Promise.all(
(await readdir(path.join(root, "seed-media"))).map((entry) =>
checkResource(
baseUrl + "/media/seed/" + encodeURIComponent(entry),
"image/jpeg",
"seed media " + entry,
),
),
);
console.log("public release verified: admin, preview, assets, and seed media");