From 4e11cfe42c7e32224641dab49e2ebf5ba5798067 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Thu, 27 Aug 2026 01:25:19 +0900 Subject: [PATCH 1/2] ci: cancel stale tests when PR closes --- .github/workflows/tests.yml | 5 ++++- tests/test_tests_workflow_contract.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f96edc07..648b5e090 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,10 @@ permissions: contents: read concurrency: - group: tests-${{ github.ref }} + # A merged pull request can report the base ref on ``closed``. Keying PR + # events by number lets that close run cancel an older queued synchronize + # run for the same PR instead of consuming runners after the PR is closed. + group: tests-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: diff --git a/tests/test_tests_workflow_contract.py b/tests/test_tests_workflow_contract.py index 2fd145b0e..bd1a89031 100644 --- a/tests/test_tests_workflow_contract.py +++ b/tests/test_tests_workflow_contract.py @@ -1,15 +1,16 @@ -"""Regression contracts for the repository test workflow.""" +"""Regression contracts for the repository-local test workflow.""" from pathlib import Path -def test_pr_close_cancels_obsolete_test_runs_without_starting_jobs() -> None: - """A close event must cancel the same-PR run while scheduling no test work.""" - workflow = ( - Path(__file__).resolve().parents[1] / ".github/workflows/tests.yml" - ).read_text(encoding="utf-8") +_WORKFLOW = Path(__file__).parents[1] / ".github" / "workflows" / "tests.yml" + + +def test_pull_request_concurrency_survives_closed_ref_change() -> None: + """Key synchronize and closed events by PR number so close cancels stale work.""" + + workflow = _WORKFLOW.read_text(encoding="utf-8") assert "types: [opened, synchronize, reopened, closed]" in workflow - assert "group: tests-${{ github.ref }}" in workflow + assert "group: tests-${{ github.event.pull_request.number || github.ref }}" in workflow assert "cancel-in-progress: true" in workflow - assert workflow.count("github.event.action != 'closed'") == 2 From dda0531d81e59b7558afa01e10ab5e8f3fc45139 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Thu, 27 Aug 2026 01:26:51 +0900 Subject: [PATCH 2/2] test(ci): retain closed-job skip contract --- tests/test_tests_workflow_contract.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_tests_workflow_contract.py b/tests/test_tests_workflow_contract.py index bd1a89031..e6b48461a 100644 --- a/tests/test_tests_workflow_contract.py +++ b/tests/test_tests_workflow_contract.py @@ -14,3 +14,4 @@ def test_pull_request_concurrency_survives_closed_ref_change() -> None: assert "types: [opened, synchronize, reopened, closed]" in workflow assert "group: tests-${{ github.event.pull_request.number || github.ref }}" in workflow assert "cancel-in-progress: true" in workflow + assert workflow.count("github.event.action != 'closed'") == 2