fix: YAML-first 治理 CI/CD target (#919)

* docs: specify cicd yaml target governance

* fix: resolve cicd targets from yaml

---------

Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
Lyon
2026-06-26 01:14:38 +08:00
committed by GitHub
parent 3777577df4
commit edfddd2445
35 changed files with 1079 additions and 181 deletions
+55 -25
View File
@@ -1,4 +1,5 @@
// SPEC: PJ2026-01060307 控制面模块化 draft-2026-06-25-p0. options module for scripts/src/artifact-registry.ts.
// SPEC: PJ2026-01060308 cicd-yaml-targets draft-2026-06-25-cicd-yaml-targets.
// Moved mechanically from scripts/src/artifact-registry.ts:881-978 for #903.
@@ -24,7 +25,8 @@ import { d601K3sGuardShellLines } from "../d601-k3s-guard";
import { composeRuntimeEnvValue } from "../runtime-env";
import type { ArtifactDeployEnvironment, ArtifactRegistryOptions } from "./types";
import { defaultOptions } from "./types";
import { artifactRegistryOptionsFromTarget } from "./types";
import { resolveArtifactRegistryTarget } from "../ops/targets";
export function isHelpArg(value: string | undefined): boolean {
return value === undefined || value === "help" || value === "--help" || value === "-h";
@@ -60,65 +62,93 @@ export function environmentValue(value: string, option: string): ArtifactDeployE
}
export function parseArtifactRegistryOptions(args: string[]): ArtifactRegistryOptions {
const options = { ...defaultOptions };
let targetSelection: string | null = null;
let environment: ArtifactDeployEnvironment | null = null;
let host: string | null = null;
let port: number | null = null;
let image: string | null = null;
let baseDir: string | null = null;
let storageDir: string | null = null;
let timeoutMs: number | null = null;
let dryRun = false;
let runNow = false;
let commit: string | null = null;
let targetImage: string | null = null;
let serviceId: string | null = null;
let sourceRepo: string | null = null;
let sourceRepoExplicit = false;
let deployRef: string | null = null;
let deployJsonService: ArtifactRegistryOptions["deployJsonService"] = null;
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
if (arg === "--dry-run") {
options.dryRun = true;
dryRun = true;
} else if (arg === "--run-now") {
options.runNow = true;
runNow = true;
} else if (arg === "--env" || arg === "--environment") {
const environment = requireValue(args, index, arg);
if (environment !== "dev" && environment !== "prod") throw new Error(`${arg} must be dev or prod`);
options.environment = environment;
environment = environmentValue(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--provider-id") {
options.providerId = requireValue(args, index, arg);
} else if (arg === "--target" || arg === "--provider-id") {
targetSelection = requireValue(args, index, arg);
index += 1;
} else if (arg === "--host") {
options.host = requireValue(args, index, arg);
host = requireValue(args, index, arg);
index += 1;
} else if (arg === "--port") {
options.port = positiveInt(requireValue(args, index, arg), arg);
port = positiveInt(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--image") {
options.image = requireValue(args, index, arg);
image = requireValue(args, index, arg);
index += 1;
} else if (arg === "--base-dir") {
options.baseDir = absolutePath(requireValue(args, index, arg), arg);
baseDir = absolutePath(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--storage-dir") {
options.storageDir = absolutePath(requireValue(args, index, arg), arg);
storageDir = absolutePath(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--timeout-ms") {
options.timeoutMs = positiveInt(requireValue(args, index, arg), arg);
timeoutMs = positiveInt(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--commit") {
options.commit = commitValue(requireValue(args, index, arg), arg);
commit = commitValue(requireValue(args, index, arg), arg);
index += 1;
} else if (arg === "--target-image") {
options.targetImage = requireValue(args, index, arg);
targetImage = requireValue(args, index, arg);
index += 1;
} else if (arg === "--service" || arg === "--service-id") {
options.serviceId = requireValue(args, index, arg);
serviceId = requireValue(args, index, arg);
index += 1;
} else if (arg === "--source-repo") {
options.sourceRepo = requireValue(args, index, arg);
options.sourceRepoExplicit = true;
sourceRepo = requireValue(args, index, arg);
sourceRepoExplicit = true;
index += 1;
} else if (arg === "--deploy-ref") {
options.deployRef = requireValue(args, index, arg);
deployRef = requireValue(args, index, arg);
index += 1;
} else if (arg === "--deploy-json-service") {
options.deployJsonService = parseDeployJsonServiceContractBase64(requireValue(args, index, arg));
index += 1;
} else if (arg === "--env" || arg === "--environment") {
options.environment = environmentValue(requireValue(args, index, arg), arg);
deployJsonService = parseDeployJsonServiceContractBase64(requireValue(args, index, arg));
index += 1;
} else {
throw new Error(`unknown artifact-registry option: ${arg}`);
}
}
const options = artifactRegistryOptionsFromTarget(resolveArtifactRegistryTarget(targetSelection));
options.environment = environment;
options.host = host ?? options.host;
options.port = port ?? options.port;
options.image = image ?? options.image;
options.baseDir = baseDir ?? options.baseDir;
options.storageDir = storageDir ?? options.storageDir;
options.timeoutMs = timeoutMs ?? options.timeoutMs;
options.dryRun = dryRun;
options.runNow = runNow;
options.commit = commit;
options.targetImage = targetImage;
options.serviceId = serviceId;
options.sourceRepo = sourceRepo ?? options.sourceRepo;
options.sourceRepoExplicit = sourceRepoExplicit;
options.deployRef = deployRef;
options.deployJsonService = deployJsonService;
if (options.host !== "127.0.0.1") throw new Error("--host is first-stage restricted to 127.0.0.1");
if (options.port !== 5000) throw new Error("--port is first-stage restricted to 5000");
return options;