fix(cicd): 使用 public-edge 专用 archive runner
This commit is contained in:
@@ -4,6 +4,8 @@ import { spawnSync } from "node:child_process";
|
||||
import { readFileSync, realpathSync } from "node:fs";
|
||||
import { dirname, isAbsolute, join, resolve } from "node:path";
|
||||
|
||||
import { buildPublicEdgeArchiveReconcile } from "../../src/platform-infra-public-edge.ts";
|
||||
|
||||
const options = parseOptions(process.argv.slice(2));
|
||||
const sourceRoot = realpathSync(options.sourceRoot);
|
||||
const archiveRoot = dirname(sourceRoot);
|
||||
@@ -15,26 +17,18 @@ if (!ancestors.includes(options.sourceCommit) || ancestors.some((value) => !/^[0
|
||||
const configPath = resolve(sourceRoot, options.config);
|
||||
if (!configPath.startsWith(`${sourceRoot}/`)) fail("--config 必须位于 source archive 内");
|
||||
|
||||
const result = spawnSync("bun", [
|
||||
"scripts/cli.ts",
|
||||
"platform-infra",
|
||||
"public-edge",
|
||||
"reconcile",
|
||||
"--config",
|
||||
const reconcile = buildPublicEdgeArchiveReconcile({
|
||||
configPath,
|
||||
"--target",
|
||||
options.target,
|
||||
"--authority",
|
||||
options.authority,
|
||||
"--source-commit",
|
||||
options.sourceCommit,
|
||||
"--ancestry-file",
|
||||
ancestryFile,
|
||||
"--confirm",
|
||||
], {
|
||||
targetId: options.target,
|
||||
authorityId: options.authority,
|
||||
sourceCommit: options.sourceCommit,
|
||||
ancestry: ancestors,
|
||||
});
|
||||
const result = spawnSync("sh", [], {
|
||||
cwd: sourceRoot,
|
||||
env: { ...process.env, UNIDESK_PUBLIC_EDGE_RECONCILE: "1", UNIDESK_TRANS_REPO_ROOT: sourceRoot },
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, UNIDESK_TRANS_REPO_ROOT: sourceRoot },
|
||||
input: reconcile.script,
|
||||
stdio: ["pipe", "inherit", "inherit"],
|
||||
timeout: 120_000,
|
||||
});
|
||||
process.exit(result.status ?? 1);
|
||||
|
||||
@@ -38,6 +38,14 @@ interface PublicEdgeDelivery {
|
||||
pipelineId: string;
|
||||
}
|
||||
|
||||
export interface PublicEdgeArchiveReconcileInput {
|
||||
configPath: string;
|
||||
targetId: string;
|
||||
authorityId: string;
|
||||
sourceCommit: string;
|
||||
ancestry: string[];
|
||||
}
|
||||
|
||||
export interface SiteReference {
|
||||
id: string;
|
||||
configRef: string;
|
||||
@@ -498,6 +506,51 @@ async function reconcile(
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPublicEdgeArchiveReconcile(input: PublicEdgeArchiveReconcileInput): {
|
||||
script: string;
|
||||
authorityId: string;
|
||||
sourceCommit: string;
|
||||
targetId: string;
|
||||
siteCount: number;
|
||||
} {
|
||||
const root = readConfig(input.configPath);
|
||||
const delivery = readDelivery(root);
|
||||
if (input.authorityId !== delivery.authorityId) {
|
||||
throw inputError("reconcile authority 与 owning YAML 不一致", "reconcile-authority-mismatch", "--authority");
|
||||
}
|
||||
if (!/^[0-9a-f]{40}$/u.test(input.sourceCommit)) {
|
||||
throw inputError("source commit 必须是 40 位 commit", "invalid-source-commit", "--source-commit");
|
||||
}
|
||||
if (
|
||||
input.ancestry.length === 0
|
||||
|| input.ancestry.some((value) => !/^[0-9a-f]{40}$/u.test(value))
|
||||
|| !input.ancestry.includes(input.sourceCommit)
|
||||
) {
|
||||
throw inputError("archive ancestry proof 无效", "reconcile-ancestry-invalid", "--ancestry-file");
|
||||
}
|
||||
const target = readTarget(root, input.targetId);
|
||||
const resolution = resolveSites(target);
|
||||
if (resolution.unresolved.length > 0) {
|
||||
throw inputError(
|
||||
`存在缺失或不兼容的产品 owning YAML 引用:${resolution.unresolved.map((item) => item.id).join(",")}`,
|
||||
"public-edge-config-unresolved",
|
||||
"--config",
|
||||
);
|
||||
}
|
||||
const artifacts = renderPublicEdgeArtifacts(target, resolution.sites);
|
||||
return {
|
||||
script: applyScript(target, resolution.sites, artifacts, {
|
||||
authorityId: delivery.authorityId,
|
||||
sourceCommit: input.sourceCommit,
|
||||
ancestry: input.ancestry,
|
||||
}),
|
||||
authorityId: delivery.authorityId,
|
||||
sourceCommit: input.sourceCommit,
|
||||
targetId: target.id,
|
||||
siteCount: resolution.sites.length,
|
||||
};
|
||||
}
|
||||
|
||||
async function status(
|
||||
config: UniDeskConfig,
|
||||
configPath: string,
|
||||
|
||||
Reference in New Issue
Block a user