From 5a00515d3e3355d26d267cc28e3a7ecbf3489148 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 13 Jul 2026 22:46:16 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20HWLAB=20PaC=20rende?= =?UTF-8?q?rer=20=E5=86=85=E8=81=94=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/src/hwlab-node/render.ts | 4 +- ...-pipelines-as-code-source-artifact.test.ts | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/scripts/src/hwlab-node/render.ts b/scripts/src/hwlab-node/render.ts index 7acc7a39..22450fef 100644 --- a/scripts/src/hwlab-node/render.ts +++ b/scripts/src/hwlab-node/render.ts @@ -2568,8 +2568,8 @@ export function nodeRuntimePipelinePostprocessScript(): string[] { " return next;", " });", " result = result.replace(/(node scripts\\/run-bun\\.mjs scripts\\/gitops-render\\.mjs[^\\n]*--use-deploy-images[^\\n]*)/g, (match) => {", - " if (match.includes('--check')) return runtimeGitopsVerifyScript();", - " return `${match}\\n${[runtimePathOverlayScript(), runtimeGitopsPostprocessScript()].filter(Boolean).join('\\n')}`;", + " if (match.includes('--check')) return match;", + " return `${match}\\n${runtimePathOverlayScript()}`;", " });", " result = result.replace(/node scripts\\/run-bun\\.mjs scripts\\/gitops-render\\.mjs([^\\n]*?)--out \"\\$render_check_dir\"/g, (match) => match.includes('--gitops-root ') ? match : `${match} --gitops-root ${JSON.stringify(overlay.gitopsRoot)} --node ${shellSingle(overlay.nodeId)} --git-read-url ${shellSingle(overlay.gitReadUrl)} --git-write-url ${shellSingle(overlay.gitWriteUrl)} --runtime-endpoint ${shellSingle(overlay.publicApiUrl)} --web-endpoint ${shellSingle(overlay.publicWebUrl)}`);", " validatePrepareSourceDependencyScript(result);", diff --git a/scripts/src/platform-infra-pipelines-as-code-source-artifact.test.ts b/scripts/src/platform-infra-pipelines-as-code-source-artifact.test.ts index d8e40551..6301578d 100644 --- a/scripts/src/platform-infra-pipelines-as-code-source-artifact.test.ts +++ b/scripts/src/platform-infra-pipelines-as-code-source-artifact.test.ts @@ -7,7 +7,7 @@ import { resolve } from "node:path"; import { rootPath } from "./config"; import { applyNodeRuntimeDeployYamlOverlay, nodeRuntimeDeployYamlOverlayShellScript } from "./hwlab-node/deploy-overlay"; import { hwlabRuntimePipelineProvenance } from "./hwlab-node/pipeline-provenance"; -import { nodeRuntimePipelineProvenancePostprocessScript } from "./hwlab-node/render"; +import { nodeRuntimePipelinePostprocessScript, nodeRuntimePipelineProvenancePostprocessScript } from "./hwlab-node/render"; import { nodeRuntimeRenderOverlay } from "./hwlab-node/web-probe"; import { hwlabRuntimeLaneSpecForNode, parseHwlabRuntimePipelineProvenance } from "./hwlab-node-lanes"; import { pipelineProvenanceAnnotationKeys, pipelineProvenanceAnnotations } from "./pipeline-provenance"; @@ -245,9 +245,33 @@ describe("HWLAB YAML-owned Pipeline provenance", () => { const budget = spec.pipelineProvenance?.maxInlineScriptBytes; expect(budget).toBeNumber(); const overlay = nodeRuntimeRenderOverlay(spec); - const pipelinePath = resolve(temporary, "pipeline.yaml"); - const configMapPath = resolve(temporary, "runtime-gitops-scripts.yaml"); - const scriptsDir = rootPath("scripts", "native", "hwlab"); + const pipelineDir = resolve(temporary, spec.tektonDir); + const pipelinePath = resolve(pipelineDir, "pipeline.yaml"); + const configMapPath = resolve(pipelineDir, "runtime-gitops-scripts.yaml"); + const gitMirrorDir = resolve(temporary, "devops-infra"); + mkdirSync(pipelineDir, { recursive: true }); + mkdirSync(gitMirrorDir, { recursive: true }); + writeFileSync(resolve(gitMirrorDir, "git-mirror.yaml"), Bun.YAML.stringify({ + apiVersion: "v1", + kind: "List", + items: [ + { + apiVersion: "v1", + kind: "ConfigMap", + metadata: { name: overlay.gitMirror.syncConfigMapName }, + data: { + "sync.sh": "#!/bin/sh\nset -eu\nrepo_url='ssh://git@github.com/pikasTech/HWLAB.git'\n", + "flush.sh": "#!/bin/sh\nset -eu\nremote='ssh://git@github.com/pikasTech/HWLAB.git'\n", + }, + }, + { + apiVersion: "apps/v1", + kind: "Deployment", + metadata: { name: overlay.gitMirror.serviceReadName }, + spec: { template: { spec: { containers: [{ name: "git-mirror", env: [] }] } } }, + }, + ], + })); writeFileSync(pipelinePath, Bun.YAML.stringify({ apiVersion: "tekton.dev/v1", kind: "Pipeline", @@ -260,23 +284,26 @@ describe("HWLAB YAML-owned Pipeline provenance", () => { }] }, }] }, })); - const result = spawnSync("node", [ - rootPath("scripts", "native", "hwlab", "runtime-gitops-pipeline-guard.mjs"), - "--pipeline", pipelinePath, - "--scripts-configmap", configMapPath, - "--namespace", "hwlab-ci", - "--scripts-dir", scriptsDir, - ], { + const overlayBase64 = Buffer.from(JSON.stringify(overlay), "utf8").toString("base64"); + const result = spawnSync("sh", [], { cwd: rootPath(), - env: { ...process.env, UNIDESK_RUNTIME_GITOPS_OVERLAY_B64: Buffer.from(JSON.stringify(overlay), "utf8").toString("base64") }, + input: [ + "set -eu", + `render_dir=${JSON.stringify(temporary)}`, + `overlay_b64=${JSON.stringify(overlayBase64)}`, + ...nodeRuntimePipelinePostprocessScript(), + ].join("\n"), encoding: "utf8", timeout: 30_000, }); - expect(result.status).toBe(0); + expect(result.status, result.stderr).toBe(0); const pipeline = Bun.YAML.parse(readFileSync(pipelinePath, "utf8")) as Record; const scripts = pipeline.spec.tasks.flatMap((task: Record) => task.taskSpec.steps.map((step: Record) => String(step.script ?? ""))); expect(Math.max(...scripts.map((script: string) => Buffer.byteLength(script)))).toBeLessThanOrEqual(budget as number); expect(scripts.join("\n")).toContain("UNIDESK_RUNTIME_GITOPS_OVERLAY_FILE=/etc/unidesk-cicd-runtime-gitops/runtime-gitops-overlay.json"); + expect(scripts.join("\n")).not.toContain("NODE_UNIDESK_RUNTIME_GITOPS_POSTPROCESS"); + expect(scripts.join("\n")).not.toContain("NODE_UNIDESK_RUNTIME_GITOPS_VERIFY"); + expect(scripts.join("\n")).not.toContain("UNIDESK_RUNTIME_GITOPS_OVERLAY_B64="); expect(scripts.join("\n")).not.toContain(Buffer.from(JSON.stringify(overlay.observability), "utf8").toString("base64")); const configMap = Bun.YAML.parse(readFileSync(configMapPath, "utf8")) as Record; expect(JSON.parse(configMap.data["runtime-gitops-overlay.json"])).toEqual({ runtimePath: overlay.runtimePath, observability: overlay.observability });