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);