Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions tests/test_tests_workflow_contract.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""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"
Comment thread
seonghobae marked this conversation as resolved.


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
Loading