feat: load branch follower reuse config from source repos
This commit is contained in:
@@ -15,6 +15,7 @@ import { existsSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { repoRoot, rootPath } from "./config";
|
||||
import { runCommand, type CommandResult } from "./command";
|
||||
import { runtimeReuseService, summarizeRuntimeReuseConfig, type RuntimeReuseConfig } from "./cicd-reuse-config";
|
||||
import { startJob } from "./jobs";
|
||||
import { webProbeSentinelConfigPlan, withWebProbeSentinelConfigRendered } from "./hwlab-node-web-sentinel-config";
|
||||
import { readWebProbeSentinelConfigRefTarget } from "./hwlab-node-web-sentinel-config-ref";
|
||||
@@ -547,6 +548,7 @@ export function loadSentinelCicdState(
|
||||
timeoutSeconds: number,
|
||||
sourceResolveMode: SourceResolveMode,
|
||||
sourceOverride: SentinelSourceOverride | null = null,
|
||||
reuseConfig: RuntimeReuseConfig | null = null,
|
||||
): SentinelCicdState {
|
||||
const sentinel = resolveWebProbeSentinel(spec, sentinelId);
|
||||
const configPlan = webProbeSentinelConfigPlan(spec, "status", sentinel.id);
|
||||
@@ -562,11 +564,12 @@ export function loadSentinelCicdState(
|
||||
const nodeId = stringField(controlPlaneTarget, "node");
|
||||
const controlPlaneNode = recordTarget(valueAtPath(controlPlaneConfig, `nodes.${nodeId}`), `${configRefFile(controlPlaneRef)}#nodes.${nodeId}`);
|
||||
validateSentinelSourceAuthority(cicd);
|
||||
const effectiveCicd = applySentinelRuntimeReuseConfig(cicd, reuseConfig);
|
||||
const sourceHead = sourceOverride === null
|
||||
? resolveSourceHead(spec, cicd, controlPlaneTarget, controlPlaneNode, timeoutSeconds, sourceResolveMode)
|
||||
: sourceHeadFromOverride(cicd, sourceOverride);
|
||||
const image = sentinelImagePlan(spec, cicd, sourceHead);
|
||||
const manifests = renderSentinelManifests(spec, sentinel.id, runtime, cicd, scenarios, publicExposure, secrets, image, sourceHead);
|
||||
? resolveSourceHead(spec, effectiveCicd, controlPlaneTarget, controlPlaneNode, timeoutSeconds, sourceResolveMode)
|
||||
: sourceHeadFromOverride(effectiveCicd, sourceOverride);
|
||||
const image = sentinelImagePlan(spec, effectiveCicd, sourceHead);
|
||||
const manifests = renderSentinelManifests(spec, sentinel.id, runtime, effectiveCicd, scenarios, publicExposure, secrets, image, sourceHead);
|
||||
const manifestYaml = `${manifests.map((item) => Bun.YAML.stringify(item).trim()).join("\n---\n")}\n`;
|
||||
return {
|
||||
spec,
|
||||
@@ -574,7 +577,7 @@ export function loadSentinelCicdState(
|
||||
configRefs: sentinel.configRefs,
|
||||
configReady: configPlan.ok,
|
||||
runtime,
|
||||
cicd,
|
||||
cicd: effectiveCicd,
|
||||
scenarios,
|
||||
publicExposure,
|
||||
secrets,
|
||||
@@ -588,6 +591,27 @@ export function loadSentinelCicdState(
|
||||
};
|
||||
}
|
||||
|
||||
function applySentinelRuntimeReuseConfig(cicd: Record<string, unknown>, reuseConfig: RuntimeReuseConfig | null): Record<string, unknown> {
|
||||
const service = runtimeReuseService(reuseConfig, ["web-probe-sentinel", "monitor-web"]);
|
||||
const envReuse = service?.envReuse;
|
||||
if (envReuse === undefined || envReuse === null) return cicd;
|
||||
if (envReuse.enabled === false) return cicd;
|
||||
const monitorWeb = record(cicd.monitorWeb);
|
||||
const existingEnvReuse = record(monitorWeb.envReuse);
|
||||
return {
|
||||
...cicd,
|
||||
monitorWeb: {
|
||||
...monitorWeb,
|
||||
envReuse: {
|
||||
...existingEnvReuse,
|
||||
...(envReuse.mode === null ? {} : { mode: envReuse.mode }),
|
||||
...(envReuse.nodeDepsPath === null ? {} : { nodeDepsPath: envReuse.nodeDepsPath }),
|
||||
source: summarizeRuntimeReuseConfig(reuseConfig),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function sourceHeadFromOverride(cicd: Record<string, unknown>, override: SentinelSourceOverride): SourceHead {
|
||||
if (!/^[0-9a-f]{40}$/iu.test(override.commit)) throw new Error(`sentinel source override commit must be a full sha, got ${override.commit}`);
|
||||
const stageRef = override.stageRef ?? sentinelSourceSnapshotRef(cicd, override.commit);
|
||||
|
||||
Reference in New Issue
Block a user