ci: 增加部署后发布验收脚本
This commit is contained in:
1 parent
85f37d2eae
commit
9c15a822e9
4 files changed
+125
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import test from "node:test";
|
||||
import { spawn } from "node:child_process";
|
||||
import { once } from "node:events";
|
||||
import { createServer } from "node:http";
|
||||
|
||||
function runScript(environment) {
|
||||
const child = spawn(process.execPath, ["scripts/deploy/verify-release.mjs"], {
|
||||
env: { ...process.env, ...environment },
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
return once(child, "close").then(([code]) => code);
|
||||
}
|
||||
|
||||
test("release verifier requires deployment variables", async () => {
|
||||
assertEqualExit(await runScript({}), 1);
|
||||
});
|
||||
|
||||
test("release verifier rejects an unpublished brand", async () => {
|
||||
const server = createServer((request, response) => {
|
||||
if (request.url === "/health") {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ status: "ok", service: "fixture" }));
|
||||
return;
|
||||
}
|
||||
if (request.url === "/admin/session/login") {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ token: "fixture-token", mustChangePassword: false }));
|
||||
return;
|
||||
}
|
||||
if (request.url === "/admin/releases/readiness") {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ checks: [{ key: "brand", passed: true }] }));
|
||||
return;
|
||||
}
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ publication: { status: "unpublished" } }));
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const { port } = server.address();
|
||||
const exitCode = await runScript({
|
||||
API_BASE_URL: `http://127.0.0.1:${port}`,
|
||||
BRAND_SLUG: "fixture",
|
||||
ADMIN_USERNAME: "admin",
|
||||
ADMIN_PASSWORD: "fixture-password",
|
||||
});
|
||||
server.close();
|
||||
assertEqualExit(exitCode, 1);
|
||||
});
|
||||
|
||||
function assertEqualExit(actual, expected) {
|
||||
if (actual !== expected) throw new Error(`expected exit ${expected}, received ${actual}`);
|
||||
}
|
||||
Reference in new issue
Block a user