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:
@@ -333,7 +333,7 @@ bubblewrap may create unprivileged user and network namespaces, which Ubuntu
|
||||
23.10 and later refuse by default — its first step says so, and
|
||||
`docs/operations/ci-quality-gates.md` lists the fixes). Product checks listed in
|
||||
`config/ci/product-gates.json` (`PRODUCT-GATE-NNN`) run in the workflow's own
|
||||
`product_merge_gate` job:
|
||||
`product_merge_gate` job, which the release stage waits for:
|
||||
|
||||
```bash
|
||||
for gate in 001 002 003 004 005 006 007 008 009 010 011 012 013 020; do
|
||||
|
||||
@@ -421,9 +421,14 @@ the paired backend: `{ "id": "PRODUCT-GATE-001", "name": "backend-contract",
|
||||
`FE-GATE-NNN` ids, their commands, artifacts and readiness formula stay the
|
||||
template's. Each runs as `corepack pnpm <script>` in the `product_merge_gate`
|
||||
job, on the same condition as `merge_gate`, without browsers and without the
|
||||
gate log and evidence artifacts of `ci:gate`. Make that job a required check
|
||||
of the branch where it has to block a merge. `check:ci` refuses a script that
|
||||
`package.json` does not define and counts these scripts as gated.
|
||||
gate log and evidence artifacts of `ci:gate`. `release_gate` waits for that job
|
||||
as it waits for `merge_gate`, so a failing product gate also stops the release
|
||||
build, promotion and deployment of the same run (1105/13-02); with no product
|
||||
gates the workflow is the template's own. A required check of the branch is
|
||||
what blocks a pull request merge, so make the job one where it has to. `check:ci`
|
||||
refuses a script that `package.json` does not define, and a workflow whose
|
||||
`release_gate` does not wait for the product job, and counts these scripts as
|
||||
gated.
|
||||
|
||||
The slot as stored in `config/ci/gates.json` still follows the same contract
|
||||
rules. The contract allows the steps `checkout`, `setup-node`,
|
||||
|
||||
@@ -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]!);
|
||||
|
||||
@@ -54,6 +54,8 @@ const DEPLOYMENT = {
|
||||
const DEPLOY_SCRIPTS = { "deploy:desktop": "node scripts/deploy-desktop.ts" };
|
||||
const GATE = { id: "PRODUCT-GATE-001", name: "backend-contract", script: "check:backend-contract" };
|
||||
const GATE_SCRIPTS = { "check:backend-contract": "node scripts/check-backend-contract.ts" };
|
||||
const RELEASE_HELD_BY_TEMPLATE = " needs: merge_gate\n";
|
||||
const RELEASE_HELD_BY_PRODUCT = " needs: [merge_gate, product_merge_gate]\n";
|
||||
|
||||
describe("product CI overlay (1103/12-07)", () => {
|
||||
it("ships empty, so the template's own workflow is unchanged", async () => {
|
||||
@@ -143,14 +145,49 @@ describe("product CI overlay (1103/12-07)", () => {
|
||||
expect(job).toContain(" run: corepack pnpm ${{ matrix.script }}");
|
||||
expect(job).toContain(` if: ${"${{ gitea.event_name != 'workflow_dispatch' || inputs.stage != 'documentation' }}"}`);
|
||||
expect(workflowGateExecutionFailures(contract, workflow, mergeGates)).toEqual([]);
|
||||
// The template part of the workflow is the same bytes with or without the overlay.
|
||||
expect(workflow.startsWith(renderCiWorkflow(contract).trimEnd())).toBe(true);
|
||||
// The template part of the workflow is the same bytes with or without the
|
||||
// overlay, except that the release stage waits for the product job (1105/13-02).
|
||||
expect(
|
||||
workflow.replace(RELEASE_HELD_BY_PRODUCT, RELEASE_HELD_BY_TEMPLATE).startsWith(renderCiWorkflow(contract).trimEnd()),
|
||||
).toBe(true);
|
||||
|
||||
expect(workflowGateExecutionFailures(contract, renderCiWorkflow(contract), mergeGates)).toEqual([
|
||||
"product gate is not executed by the product_merge_gate job: PRODUCT-GATE-001",
|
||||
"product gates do not hold the release stage: release_gate does not need product_merge_gate",
|
||||
]);
|
||||
});
|
||||
|
||||
// 1105/13-02. A failing product gate stopped only a PR merge (as a required
|
||||
// check): the same run went on to release, promote and deploy, and the fixed
|
||||
// job graph left the product no way to link them.
|
||||
it("holds the release stage until the product merge gates pass", async () => {
|
||||
const root = await productRoot(
|
||||
{ schemaVersion: 1, deployment: DEPLOYMENT, mergeGates: [GATE] },
|
||||
{ ...DEPLOY_SCRIPTS, ...GATE_SCRIPTS },
|
||||
);
|
||||
const contract = await loadCiGateContract(root);
|
||||
const { mergeGates } = await loadProductCiOverlay(root);
|
||||
const releaseJob = (workflow: string) =>
|
||||
workflow.slice(workflow.indexOf(" release_gate:\n"), workflow.indexOf(" immutable_build:\n"));
|
||||
|
||||
const workflow = renderCiWorkflow(contract, mergeGates);
|
||||
expect(releaseJob(workflow)).toContain(RELEASE_HELD_BY_PRODUCT);
|
||||
// immutable_build, and through it every later release-stage job
|
||||
// (deployment included), needs release_gate.
|
||||
expect(contract.jobs.find(({ id }) => id === "immutable_build")?.needs).toEqual(["release_gate"]);
|
||||
// Without product gates the template's own graph is rendered.
|
||||
expect(releaseJob(renderCiWorkflow(contract))).toContain(RELEASE_HELD_BY_TEMPLATE);
|
||||
|
||||
// check:ci refuses a workflow that runs the product gates without the link.
|
||||
expect(
|
||||
workflowGateExecutionFailures(
|
||||
contract,
|
||||
workflow.replace(RELEASE_HELD_BY_PRODUCT, RELEASE_HELD_BY_TEMPLATE),
|
||||
mergeGates,
|
||||
),
|
||||
).toEqual(["product gates do not hold the release stage: release_gate does not need product_merge_gate"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a template gate id", { mergeGates: [{ ...GATE, id: "FE-GATE-030" }] }, /PRODUCT-GATE-NNN/u],
|
||||
["a duplicate gate id", { mergeGates: [GATE, { ...GATE, name: "other" }] }, /duplicate product gate/u],
|
||||
|
||||
Reference in New Issue
Block a user