From 2f5eb2b4a551b5a6ddac4963b5a1821548ee6686 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 12 Nov 2026 22:02:56 +0900 Subject: [PATCH] =?UTF-8?q?ci(workflow):=20=EA=B0=99=EC=9D=80=20PR=C2=B7?= =?UTF-8?q?=EB=B8=8C=EB=9E=9C=EC=B9=98=EC=9D=98=20=EC=83=88=20push?= =?UTF-8?q?=EA=B0=80=20=EC=95=9E=20run=EC=9D=84=20=EC=B7=A8=EC=86=8C?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: runner가 하나(capacity 1)인데 PR에 push할 때마다 run이 하나씩 쌓인다. 낡은 head의 run이 runner를 25분씩 잡아 새 head와 백엔드 run이 뒤로 밀린다. 고른 방법: workflow에 concurrency를 둔다. group은 `frontend-quality-gates---`다. PR run의 ref는 `refs/pull/<번호>/head`라 PR마다 group 하나, branch push는 branch마다 하나, release tag는 tag마다 하나다. cancel-in-progress는 수동 실행만 거짓이다. Gitea 1.27.0은 group과 cancel-in-progress를 서버에서 식으로 계산하고(`services/actions/concurrency.go`, `inputs` 포함), 같은 group의 앞 run을 대기 중이면 언제나, 실행 중이면 cancel-in-progress가 참일 때 취소한다. - 수동 실행에 stage를 group에 넣고 취소를 끈 이유: 다음 수동 실행이 검증과 승격 사이의 release run을 끊지 않게 한다. - 버린 대안: 백엔드처럼 event·ref만으로 group을 짓기. 프론트는 수동 실행 하나가 stage 여섯을 받아, 다른 stage의 수동 실행끼리 취소된다. 위험·한계: 실제 취소는 runner에서 push 두 번으로 확인해야 한다(다음 커밋들의 PR run으로 남긴다). 이 커밋 전에 만들어진 대기 run은 group이 없어 취소되지 않는다. 검증(desktop): generate:ci-workflow, ci-workflow-generation 시험 파일 전부 통과(스냅샷 갱신 포함), check:ci-workflow rc=0, check:types rc=0, eslint rc=0. 로그 /tmp/claude-gates/w2fe2-gen1/, w2fe2-cov1/. --- .gitea/workflows/quality-gates.yml | 4 ++++ docs/operations/ci-quality-gates.md | 4 ++++ scripts/generate-ci-workflow.ts | 17 +++++++++++++++++ .../ci-workflow-generation.test.ts.snap | 4 ++++ tests/unit/ci-workflow-generation.test.ts | 9 +++++++++ 5 files changed, 38 insertions(+) diff --git a/.gitea/workflows/quality-gates.yml b/.gitea/workflows/quality-gates.yml index 0f4e9a3a..c57bdd78 100644 --- a/.gitea/workflows/quality-gates.yml +++ b/.gitea/workflows/quality-gates.yml @@ -24,6 +24,10 @@ on: permissions: contents: read +concurrency: + group: frontend-quality-gates-${{ gitea.event_name }}-${{ gitea.ref }}-${{ inputs.stage }} + cancel-in-progress: ${{ gitea.event_name != 'workflow_dispatch' }} + env: CI: "true" VITE_BUILD_ID: "gitea-${{ gitea.run_id }}-${{ gitea.run_attempt }}" diff --git a/docs/operations/ci-quality-gates.md b/docs/operations/ci-quality-gates.md index 9a69a4a0..fe35acac 100644 --- a/docs/operations/ci-quality-gates.md +++ b/docs/operations/ci-quality-gates.md @@ -11,6 +11,10 @@ 있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다. 검사기 자신의 음성 fixture와 gating 검사는 branch에 push한 뒤 main 단계(`main_gate`, FE-GATE-029)에서 돈다. release와 production 게이트는 matrix check로 남는다. 실패를 무시하는(soft-fail) 연결은 없다. +같은 PR이나 같은 브랜치에 새 push가 오면 workflow `concurrency`가 앞 run을 취소한다. Gitea는 +앞 run의 대기 중인 job은 언제나, 돌고 있는 job은 `cancel-in-progress`가 참일 때 취소한다. +수동 실행(`workflow_dispatch`)은 ref와 stage마다 group이 따로이고 돌고 있는 run을 취소하지 +않는다. 검증과 승격 사이의 release run이 다음 수동 실행에 끊기지 않게 하려는 것이다. ## 기준선 갱신과 새 프로젝트 시작 시 초기화할 기준선 diff --git a/scripts/generate-ci-workflow.ts b/scripts/generate-ci-workflow.ts index 4ef8e811..f34e0bc1 100644 --- a/scripts/generate-ci-workflow.ts +++ b/scripts/generate-ci-workflow.ts @@ -77,6 +77,21 @@ const PRODUCT_GATE_JOB = "product_merge_gate"; */ const PRODUCT_GATES_HOLD = "release_gate"; +/** + * A newer run in the same group cancels the older one. Gitea 1.27 cancels the + * older run's waiting and blocked jobs always and its running jobs only when + * cancel-in-progress is true. A pull request run has the ref + * `refs/pull//head`, so one group per pull request; a branch push is + * one group per branch; a release tag has its own ref. A manual run is one + * group per ref and stage and does not cancel a running run: a later release + * dispatch must not stop an earlier one between verification and promotion. + */ +const CONCURRENCY_LINES = Object.freeze([ + "concurrency:", + " group: frontend-quality-gates-${{ gitea.event_name }}-${{ gitea.ref }}-${{ inputs.stage }}", + " cancel-in-progress: ${{ gitea.event_name != 'workflow_dispatch' }}", +]); + export function renderCiWorkflow( contract: CiGateContract, productGates: readonly ProductGate[] = [], @@ -117,6 +132,8 @@ export function renderCiWorkflow( "permissions:", " contents: read", "", + ...CONCURRENCY_LINES, + "", "env:", ' CI: "true"', ' VITE_BUILD_ID: "gitea-${{ gitea.run_id }}-${{ gitea.run_attempt }}"', diff --git a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap index a06b7e03..6d85b431 100644 --- a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap +++ b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap @@ -27,6 +27,10 @@ on: permissions: contents: read +concurrency: + group: frontend-quality-gates-\${{ gitea.event_name }}-\${{ gitea.ref }}-\${{ inputs.stage }} + cancel-in-progress: \${{ gitea.event_name != 'workflow_dispatch' }} + env: CI: "true" VITE_BUILD_ID: "gitea-\${{ gitea.run_id }}-\${{ gitea.run_attempt }}" diff --git a/tests/unit/ci-workflow-generation.test.ts b/tests/unit/ci-workflow-generation.test.ts index 7610645f..5758dc98 100644 --- a/tests/unit/ci-workflow-generation.test.ts +++ b/tests/unit/ci-workflow-generation.test.ts @@ -1586,6 +1586,15 @@ describe("CI workflow generation", () => { ); expect(first).not.toContain("process_dist_sha256"); expect(first).toContain("persist-credentials: false"); + // A newer push to the same pull request or branch cancels the older run; + // a manual run never cancels a running one. + expect(first).toContain( + [ + "concurrency:", + " group: frontend-quality-gates-${{ gitea.event_name }}-${{ gitea.ref }}-${{ inputs.stage }}", + " cancel-in-progress: ${{ gitea.event_name != 'workflow_dispatch' }}", + ].join("\n"), + ); expect( first.match(/corepack pnpm install --frozen-lockfile --ignore-scripts/gu), ).toHaveLength(12);