fix(ci): 제품 merge 게이트가 실패하면 같은 run의 release 단계를 멈춘다
문제 제품 overlay(config/ci/product-gates.json)의 mergeGates는 product_merge_gate job으로 렌더링되는데, 다른 job이 이 job을 기다리지 않는다. release_gate는 merge_gate만 기다린다. 그래서 제품 검사(예: 짝 백엔드 계약 검사)가 실패해도 같은 run의 release·immutable_build·promotion·deployment는 그대로 돈다. 브랜치 필수 검사는 PR merge만 막는다. job 그래프는 계약이 고정해서(ci-gates.ts의 expectedJobGraph) 제품이 연결을 더할 방법도 없다. 고른 방법 - overlay에 게이트가 있으면 release_gate의 needs에 product_merge_gate를 더해 렌더링한다(`needs: [merge_gate, product_merge_gate]`). release_gate는 release 단계의 첫 job이고 뒤의 job은 모두 그것을 거쳐 기다린다. 템플릿 게이트가 release를 막는 방식과 같다. - 연결은 렌더링에서만 더한다. gates.json과 계약 그래프 검사는 그대로라 템플릿 job 그래프와 check:ci의 엄격함은 바뀌지 않는다. 게이트가 없으면 workflow 바이트가 같다(.gitea/workflows/quality-gates.yml 변경 없음). - workflowGateExecutionFailures(check:ci가 부름)가 제품 게이트가 있는데 release_gate가 product_merge_gate를 기다리지 않는 workflow를 거절한다. "실행된다"와 "막는다"를 따로 본다. - 문서(ci-quality-gates.md, README)에 release 단계가 제품 job을 기다린다고 적었다. - 버린 대안: (a) 문서에만 "막지 않는다"고 적기. 제품이 막을 방법이 계속 없다. (c) 게이트마다 blocksRelease 칸. 선택권은 주지만 칸이 늘고, 불안정한 제품 검사가 생기기 전에는 필요가 없다. 계약 그래프 검사에 overlay 예외를 넣는 것: 템플릿 계약이 제품 overlay를 알아야 한다. 위험·한계 - 불안정한 제품 게이트는 이제 release도 멈춘다. 그때는 (c)로 간다. - Gitea가 needs와 기본 success() 조건을 GitHub Actions처럼 처리한다고 본다. 실제 runner에서는 확인하지 못했다(Actions 꺼짐). - 제품 게이트를 이미 쓰는 다운스트림은 generate:ci-workflow를 다시 돌려야 check:ci를 통과한다(생성 YAML의 release_gate needs 한 줄이 바뀐다). 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/product-ci-overlay.test.ts tests/unit/ci-workflow-generation.test.ts, corepack pnpm check:ci. - RED 기대: "holds the release stage until the product merge gates pass", "runs product merge gates in a job of their own, apart from the template gates". Refs: 1105/13-02
This commit is contained in:
@@ -65,6 +65,18 @@ const defaultFileSystem: CiWorkflowFileSystem = Object.freeze({
|
||||
rm: async (target) => rm(target, { force: true }),
|
||||
});
|
||||
|
||||
const PRODUCT_GATE_JOB = "product_merge_gate";
|
||||
/**
|
||||
* 1105/13-02. The job that waits for the product gates. A failing product
|
||||
* gate stopped nothing but a PR merge: the same run went on to release, build,
|
||||
* promote and deploy, and the fixed job graph left a product no way to link
|
||||
* them. release_gate is the first release-stage job, and every later one
|
||||
* depends on it as it depends on merge_gate. The link is rendered from the
|
||||
* overlay, so the template contract's job graph (and its check) stays the
|
||||
* template's, and without product gates the workflow bytes do not change.
|
||||
*/
|
||||
const PRODUCT_GATES_HOLD = "release_gate";
|
||||
|
||||
export function renderCiWorkflow(
|
||||
contract: CiGateContract,
|
||||
productGates: readonly ProductGate[] = [],
|
||||
@@ -76,6 +88,8 @@ export function renderCiWorkflow(
|
||||
if (step.kind === "upload") transfers.set(step.transferId, { name: step.name });
|
||||
}
|
||||
}
|
||||
// 1105/13-02. With product gates, the release stage waits for them too.
|
||||
const productNeeds = productGates.length > 0 ? [PRODUCT_GATE_JOB] : [];
|
||||
const lines = [
|
||||
"# GENERATED FILE — edit config/ci/gates.json and run `corepack pnpm generate:ci-workflow`.",
|
||||
"name: frontend-quality-gates",
|
||||
@@ -113,7 +127,7 @@ export function renderCiWorkflow(
|
||||
];
|
||||
for (const [jobIndex, job] of contract.jobs.entries()) {
|
||||
if (jobIndex > 0) lines.push("");
|
||||
lines.push(...renderJob(job, index, transfers));
|
||||
lines.push(...renderJob(job, index, transfers, job.id === PRODUCT_GATES_HOLD ? productNeeds : []));
|
||||
}
|
||||
if (productGates.length > 0) lines.push("", ...renderProductGateJob(productGates));
|
||||
return `${lines.join("\n").replace(/\n+$/u, "")}\n`;
|
||||
@@ -123,12 +137,13 @@ export function renderCiWorkflow(
|
||||
* 1103/12-07. The product's merge gates (config/ci/product-gates.json) run in
|
||||
* a job after every template job, on the same merge condition. A product gate
|
||||
* is one package script; it has no log artifact or evidence of the template
|
||||
* gate contract and is not part of its readiness formula, so the product makes
|
||||
* this job a required check where it wants it to block a merge.
|
||||
* gate contract and is not part of its readiness formula. The release stage
|
||||
* waits for this job (1105/13-02); the product makes it a required check where
|
||||
* it wants it to block a merge.
|
||||
*/
|
||||
function renderProductGateJob(productGates: readonly ProductGate[]): string[] {
|
||||
return [
|
||||
" product_merge_gate:",
|
||||
` ${PRODUCT_GATE_JOB}:`,
|
||||
` name: ${yamlScalar("${{ matrix.gate }} / ${{ matrix.name }}")}`,
|
||||
` if: ${renderCondition("merge")}`,
|
||||
" runs-on: ubuntu-latest",
|
||||
@@ -161,10 +176,12 @@ function renderJob(
|
||||
job: CiWorkflowJob,
|
||||
index: ReturnType<typeof indexCiGateContract>,
|
||||
transfers: ReadonlyMap<string, Readonly<{ name: string }>>,
|
||||
productNeeds: readonly string[],
|
||||
): string[] {
|
||||
const lines = [` ${yamlKey(job.id)}:`, ` name: ${yamlScalar(job.displayName)}`];
|
||||
if (job.needs.length === 1) lines.push(` needs: ${yamlKey(job.needs[0]!)}`);
|
||||
if (job.needs.length > 1) lines.push(` needs: [${job.needs.map(yamlKey).join(", ")}]`);
|
||||
const needs = [...job.needs, ...productNeeds];
|
||||
if (needs.length === 1) lines.push(` needs: ${yamlKey(needs[0]!)}`);
|
||||
if (needs.length > 1) lines.push(` needs: [${needs.map(yamlKey).join(", ")}]`);
|
||||
const condition = renderCondition(job.condition);
|
||||
if (condition) lines.push(` if: ${condition}`);
|
||||
lines.push(
|
||||
@@ -480,7 +497,7 @@ export function workflowGateExecutionFailures(
|
||||
): string[] {
|
||||
const executed = new Set<string>();
|
||||
const jobs = workflow.split(/^(?= {2}[a-z_]+:$)/mu);
|
||||
const productJob = jobs.find((job) => job.startsWith(" product_merge_gate:\n")) ?? "";
|
||||
const productJob = jobs.find((job) => job.startsWith(` ${PRODUCT_GATE_JOB}:\n`)) ?? "";
|
||||
const productRuns = /^ {8}run: corepack pnpm \$\{\{ matrix\.script \}\}$/mu.test(productJob);
|
||||
const productFailures = productGates
|
||||
.filter(
|
||||
@@ -490,7 +507,17 @@ export function workflowGateExecutionFailures(
|
||||
` - { gate: ${gate.id}, name: ${gate.name}, script: ${yamlScalar(gate.script)} }\n`,
|
||||
),
|
||||
)
|
||||
.map(({ id }) => `product gate is not executed by the product_merge_gate job: ${id}`);
|
||||
.map(({ id }) => `product gate is not executed by the ${PRODUCT_GATE_JOB} job: ${id}`);
|
||||
// 1105/13-02. Run is not enough: a failing product gate must also hold the
|
||||
// release stage.
|
||||
const holdingJob = jobs.find((job) => job.startsWith(` ${PRODUCT_GATES_HOLD}:\n`)) ?? "";
|
||||
const heldBy = /^ {4}needs: (?:\[([^\]\n]*)\]|(\S+))$/mu.exec(holdingJob);
|
||||
if (
|
||||
productGates.length > 0 &&
|
||||
!(heldBy?.[1] ?? heldBy?.[2] ?? "").split(", ").includes(PRODUCT_GATE_JOB)
|
||||
) {
|
||||
productFailures.push(`product gates do not hold the release stage: ${PRODUCT_GATES_HOLD} does not need ${PRODUCT_GATE_JOB}`);
|
||||
}
|
||||
for (const job of jobs) {
|
||||
for (const match of job.matchAll(/^ +run: corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
|
||||
executed.add(match[1]!);
|
||||
|
||||
Reference in New Issue
Block a user