Add HWLAB v0.3 lane expansion config

This commit is contained in:
Codex Agent
2026-06-08 14:08:18 +08:00
parent 34ee947285
commit 6c5166d816
12 changed files with 852 additions and 149 deletions
+3 -1
View File
@@ -40,7 +40,9 @@ export const DEFAULT_DOCS_ONLY_PATHS = Object.freeze([
export const DEFAULT_GITOPS_ONLY_PATHS = Object.freeze([
"deploy/gitops/",
"deploy/frp/",
"scripts/g14-gitops-render.mjs"
"scripts/g14-gitops-render.mjs",
"scripts/src/g14-gitops-lane.ts",
"tsconfig.gitops.json"
]);
export async function createG14CiPlan(options = {}) {
+120
View File
@@ -0,0 +1,120 @@
type RuntimeLaneDefaults = {
defaultBranch?: string;
defaultGitopsBranch?: string;
defaultCatalogPath?: string;
defaultRuntimeEndpoint?: string;
defaultWebEndpoint?: string;
defaultV02RuntimeEndpoint?: string;
defaultSourceRepo?: string;
};
export type GitOpsRenderArgs = {
lane: string;
sourceBranch: string;
gitopsBranch: string;
catalogPath: string;
imageTagMode: string;
runtimeEndpoint: string;
webEndpoint: string;
sourceRepo: string;
[key: string]: unknown;
};
export type RuntimeLaneConfig = {
sourceBranch?: string;
gitopsBranch?: string;
artifactCatalog?: string;
imageTagMode?: string;
endpoint?: string;
publicEndpoints?: {
frontend?: string;
api?: string;
[key: string]: string | undefined;
};
sourceRepo?: string;
};
export type DeployConfig = {
lanes?: Record<string, RuntimeLaneConfig | undefined>;
};
const defaultPublicHost = "74.48.78.17";
export function isRuntimeLane(lane: unknown): lane is string {
return /^v[0-9]{2,}$/u.test(String(lane ?? ""));
}
export function runtimeLaneMinor(lane: string): number {
invariant(isRuntimeLane(lane), `runtime lane must look like v02/v03, got ${lane}`);
return Number.parseInt(lane.slice(1), 10);
}
export function versionNameForRuntimeLane(lane: string): string {
return `v0.${runtimeLaneMinor(lane)}`;
}
export function namespaceNameForRuntimeLane(lane: string): string {
invariant(isRuntimeLane(lane), `runtime lane must look like v02/v03, got ${lane}`);
return `hwlab-${lane}`;
}
export function runtimePathForRuntimeLane(lane: string): string {
invariant(isRuntimeLane(lane), `runtime lane must look like v02/v03, got ${lane}`);
return `runtime-${lane}`;
}
export function defaultPortForRuntimeLane(lane: string): number {
return 19466 + runtimeLaneMinor(lane) * 100;
}
export function publicHostLabel(host = defaultPublicHost): string {
return host.replaceAll(".", "-");
}
export function defaultEndpointForRuntimeLane(lane: string, options: { host?: string; v02Endpoint?: string } = {}): string {
if (lane === "v02" && options.v02Endpoint) return options.v02Endpoint;
return `https://hwlab-${lane}.${publicHostLabel(options.host ?? defaultPublicHost)}.nip.io`;
}
export function runtimeLaneConfig(deploy: DeployConfig, lane: string): RuntimeLaneConfig {
invariant(isRuntimeLane(lane), `runtime lane must look like v02/v03, got ${lane}`);
const config = deploy.lanes?.[lane];
invariant(isObject(config), `deploy.lanes.${lane} is required`);
return config;
}
export function applyRuntimeLaneDeployConfig(args: GitOpsRenderArgs, deploy: DeployConfig, defaults: RuntimeLaneDefaults = {}): GitOpsRenderArgs {
if (!isRuntimeLane(args.lane)) return args;
const result: GitOpsRenderArgs = { ...args };
const laneConfig = runtimeLaneConfig(deploy, args.lane);
const versionName = versionNameForRuntimeLane(args.lane);
const defaultEndpointOptions = defaults.defaultV02RuntimeEndpoint ? { v02Endpoint: defaults.defaultV02RuntimeEndpoint } : {};
const defaultEndpoint = defaultEndpointForRuntimeLane(args.lane, defaultEndpointOptions);
const configuredEndpoint = laneConfig.endpoint ?? defaultEndpoint;
const configuredWebEndpoint = laneConfig.publicEndpoints?.frontend ?? configuredEndpoint;
const configuredRuntimeEndpoint = laneConfig.publicEndpoints?.api ?? configuredEndpoint;
const defaultBranch = defaults.defaultBranch ?? "G14";
const defaultGitopsBranch = defaults.defaultGitopsBranch ?? "G14-gitops";
const defaultCatalogPath = defaults.defaultCatalogPath ?? "deploy/artifact-catalog.dev.json";
const defaultRuntimeEndpoint = defaults.defaultRuntimeEndpoint ?? "http://74.48.78.17:17667";
const defaultWebEndpoint = defaults.defaultWebEndpoint ?? "http://74.48.78.17:17666";
const defaultSourceRepo = defaults.defaultSourceRepo ?? "git@github.com:pikasTech/HWLAB.git";
const defaultCatalog = `deploy/artifact-catalog.${args.lane}.json`;
if (result.sourceBranch === defaultBranch || result.sourceBranch === versionName) result.sourceBranch = laneConfig.sourceBranch ?? versionName;
if (result.gitopsBranch === defaultGitopsBranch || result.gitopsBranch === `${versionName}-gitops`) result.gitopsBranch = laneConfig.gitopsBranch ?? `${versionName}-gitops`;
if (result.catalogPath === defaultCatalogPath || result.catalogPath === defaultCatalog) result.catalogPath = laneConfig.artifactCatalog ?? defaultCatalog;
if (result.imageTagMode === "full") result.imageTagMode = laneConfig.imageTagMode ?? result.imageTagMode;
if (result.runtimeEndpoint === defaultRuntimeEndpoint || result.runtimeEndpoint === defaultEndpoint) result.runtimeEndpoint = configuredRuntimeEndpoint;
if (result.webEndpoint === defaultWebEndpoint || result.webEndpoint === defaultEndpoint) result.webEndpoint = configuredWebEndpoint;
if (result.sourceRepo === defaultSourceRepo && laneConfig.sourceRepo) result.sourceRepo = laneConfig.sourceRepo;
return result;
}
function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function invariant(condition: unknown, message: string): asserts condition {
if (!condition) throw new Error(message);
}