feat: migrate jd01 hwlab ci to gitea pac
This commit is contained in:
@@ -61,6 +61,111 @@ export function nodeRuntimeExternalPostgresSecretRows(secrets: Record<string, un
|
||||
}
|
||||
|
||||
export function nodeRuntimeGitMirrorStatus(scoped: ReturnType<typeof parseNodeScopedDelegatedOptions>): Record<string, unknown> {
|
||||
if (scoped.spec.sourceAuthority?.mode === "giteaSnapshot") return nodeRuntimeGiteaSourceStatus(scoped);
|
||||
return nodeRuntimeLegacyGitMirrorStatus(scoped);
|
||||
}
|
||||
|
||||
function nodeRuntimeGiteaSourceStatus(scoped: ReturnType<typeof parseNodeScopedDelegatedOptions>): Record<string, unknown> {
|
||||
const repoKey = scoped.spec.sourceAuthority?.giteaMirrorRepoKey;
|
||||
if (typeof repoKey !== "string" || repoKey.length === 0) {
|
||||
return {
|
||||
ok: false,
|
||||
command: `hwlab nodes git-mirror status --node ${scoped.node} --lane ${scoped.lane}`,
|
||||
node: scoped.node,
|
||||
lane: scoped.lane,
|
||||
mode: "gitea-source+legacy-gitops-flush",
|
||||
mutation: false,
|
||||
degradedReason: "node-runtime-gitea-repo-key-missing",
|
||||
};
|
||||
}
|
||||
const legacy = nodeRuntimeLegacyGitMirrorStatus(scoped);
|
||||
const result = runCommand([
|
||||
"bun",
|
||||
"scripts/cli.ts",
|
||||
"platform-infra",
|
||||
"gitea",
|
||||
"mirror",
|
||||
"status",
|
||||
"--target",
|
||||
scoped.node,
|
||||
"--repo",
|
||||
repoKey,
|
||||
"--raw",
|
||||
], repoRoot, { timeoutMs: scoped.timeoutSeconds * 1000 });
|
||||
const parsedRoot = record(parseJsonObject(statusText(result)));
|
||||
const parsed = record(parsedRoot.data ?? parsedRoot);
|
||||
const repositories = Array.isArray(parsed.repositories)
|
||||
? parsed.repositories.filter((item): item is Record<string, unknown> => typeof item === "object" && item !== null && !Array.isArray(item))
|
||||
: [];
|
||||
const repo = repositories[0] ?? {};
|
||||
const branchCommit = typeof repo.branchCommit === "string" && /^[0-9a-f]{40}$/iu.test(repo.branchCommit) ? repo.branchCommit.toLowerCase() : null;
|
||||
const snapshotCommit = typeof repo.snapshotCommit === "string" && /^[0-9a-f]{40}$/iu.test(repo.snapshotCommit) ? repo.snapshotCommit.toLowerCase() : null;
|
||||
const snapshotRef = typeof repo.snapshotRef === "string" ? repo.snapshotRef : null;
|
||||
const sourceReady = branchCommit !== null && snapshotCommit === branchCommit;
|
||||
const legacySummary = compactNodeRuntimeGitMirrorStatus(legacy);
|
||||
const localGitops = typeof legacySummary.localGitops === "string" ? legacySummary.localGitops : null;
|
||||
const githubGitops = typeof legacySummary.githubGitops === "string" ? legacySummary.githubGitops : null;
|
||||
const pendingFlush = legacySummary.pendingFlush === true || (localGitops !== null && githubGitops !== null && localGitops !== githubGitops);
|
||||
const summary = {
|
||||
localSource: branchCommit,
|
||||
githubSource: branchCommit,
|
||||
sourceAuthority: "gitea-snapshot",
|
||||
sourceStageRef: snapshotRef,
|
||||
sourceSnapshot: snapshotCommit,
|
||||
localGitops,
|
||||
githubGitops,
|
||||
pendingFlush,
|
||||
flushNeeded: pendingFlush,
|
||||
githubInSync: sourceReady && localGitops !== null && githubGitops !== null && localGitops === githubGitops,
|
||||
refSources: {
|
||||
localSource: `gitea:${repoKey}:refs/heads/${scoped.spec.sourceBranch}`,
|
||||
githubSource: `gitea:${repoKey}:refs/heads/${scoped.spec.sourceBranch}`,
|
||||
sourceSnapshot: snapshotRef,
|
||||
localGitops: "legacy-git-mirror:refs/heads/" + scoped.spec.gitopsBranch,
|
||||
githubGitops: "legacy-git-mirror:refs/mirror-stage/heads/" + scoped.spec.gitopsBranch,
|
||||
githubFieldsAreMirrorStageCache: false,
|
||||
},
|
||||
};
|
||||
const ok = result.exitCode === 0 && (parsed.ok === true || parsedRoot.ok === true) && sourceReady;
|
||||
return {
|
||||
ok,
|
||||
command: `hwlab nodes git-mirror status --node ${scoped.node} --lane ${scoped.lane}`,
|
||||
node: scoped.node,
|
||||
lane: scoped.lane,
|
||||
mode: "gitea-source+legacy-gitops-flush",
|
||||
mutation: false,
|
||||
namespace: record(legacy).namespace ?? null,
|
||||
readUrl: scoped.spec.gitReadUrl,
|
||||
writeUrl: scoped.spec.gitWriteUrl,
|
||||
sourceBranch: scoped.spec.sourceBranch,
|
||||
gitopsBranch: scoped.spec.gitopsBranch,
|
||||
resources: record(legacy.resources),
|
||||
githubTransport: record(legacy.githubTransport),
|
||||
summary,
|
||||
gitea: {
|
||||
repoKey,
|
||||
repository: repo,
|
||||
status: parsed,
|
||||
result: compactRuntimeCommand(result),
|
||||
},
|
||||
legacyGitMirror: {
|
||||
role: "gitops-flush-only",
|
||||
ok: legacy.ok === true,
|
||||
summary: legacySummary,
|
||||
degradedReason: legacy.degradedReason ?? null,
|
||||
},
|
||||
refSources: summary.refSources,
|
||||
result: compactRuntimeCommand(result),
|
||||
degradedReason: ok ? undefined : "node-runtime-gitea-source-snapshot-not-ready",
|
||||
valuesPrinted: false,
|
||||
next: {
|
||||
sync: `bun scripts/cli.ts platform-infra gitea mirror sync --target ${scoped.node} --repo ${repoKey} --confirm`,
|
||||
flush: `bun scripts/cli.ts hwlab nodes git-mirror flush --node ${scoped.node} --lane ${scoped.lane} --confirm`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function nodeRuntimeLegacyGitMirrorStatus(scoped: ReturnType<typeof parseNodeScopedDelegatedOptions>): Record<string, unknown> {
|
||||
const spec = scoped.spec;
|
||||
const mirror = nodeRuntimeGitMirrorTarget(spec);
|
||||
const script = [
|
||||
@@ -703,6 +808,7 @@ export function nodeRuntimeOpportunisticGitMirrorSync(
|
||||
pipelineRun: string,
|
||||
options: NodeRuntimeGitMirrorRunOptions = {},
|
||||
): Record<string, unknown> | null {
|
||||
if (scoped.spec.sourceAuthority?.mode === "giteaSnapshot") return null;
|
||||
const stage = "git-mirror-parallel-sync";
|
||||
const syncScoped = nodeRuntimeScopedWithinDeadline(scoped, options.deadlineMs);
|
||||
if (syncScoped === null) return null;
|
||||
|
||||
Reference in New Issue
Block a user