Merge pull request #574 from pikasTech/fix/v02-prune-removed-gitops-20260529

fix: clean stale v0.2 GitOps render output
This commit is contained in:
Lyon
2026-05-29 18:40:33 +08:00
committed by GitHub
2 changed files with 22 additions and 3 deletions
+12 -2
View File
@@ -2,7 +2,7 @@
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import path from "node:path";
import { promisify } from "node:util";
import { fileURLToPath } from "node:url";
@@ -3314,6 +3314,13 @@ async function writeFiles(files) {
}
}
async function cleanStaleGeneratedOutput(args) {
if (args.lane !== "v02") return;
for (const relativePath of ["runtime-v02", "tekton-v02"]) {
await rm(generatedPath(path.join(args.outDir, relativePath)), { recursive: true, force: true });
}
}
async function checkFiles(files) {
const mismatches = [];
for (const [filePath, expected] of files) {
@@ -3342,7 +3349,10 @@ async function main() {
process.exitCode = mismatches.length === 0 ? 0 : 1;
return;
}
if (args.write) await writeFiles(files);
if (args.write) {
await cleanStaleGeneratedOutput(args);
await writeFiles(files);
}
console.log(JSON.stringify({ ok: true, sourceCommit: source.full, sourceShort: source.short, outDir: args.outDir, files: [...files.keys()] }, null, 2));
}
+10 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import test from "node:test";
@@ -18,6 +18,13 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
assert.equal(head.status, 0, head.stderr || head.stdout);
const sourceRevision = head.stdout.trim();
const staleRuntimeFile = path.join(outDir, "runtime-v02", "stale-gateway-simu.yaml");
const staleTektonFile = path.join(outDir, "tekton-v02", "stale-router.yaml");
await mkdir(path.dirname(staleRuntimeFile), { recursive: true });
await mkdir(path.dirname(staleTektonFile), { recursive: true });
await writeFile(staleRuntimeFile, "kind: Service\nmetadata:\n name: hwlab-gateway-simu\n");
await writeFile(staleTektonFile, "hwlab-router\n");
const render = spawnSync(process.execPath, [
"scripts/g14-gitops-render.mjs",
"--lane", "v02",
@@ -29,6 +36,8 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
"--source-revision", "HEAD"
], { cwd: process.cwd(), encoding: "utf8" });
assert.equal(render.status, 0, render.stderr || render.stdout);
await assert.rejects(() => readFile(staleRuntimeFile, "utf8"), { code: "ENOENT" });
await assert.rejects(() => readFile(staleTektonFile, "utf8"), { code: "ENOENT" });
const pipeline = await readFile(path.join(outDir, "tekton-v02", "pipeline.yaml"), "utf8");
const pipelineJson = JSON.parse(pipeline);