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
2 changes: 2 additions & 0 deletions changelog.d/+news-skip-closed-pull-request.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`validate-news` no longer fails when a label changes on a merged or closed pull request, where the merged head is
already on the base branch and no fragment differs from the merge base.
3 changes: 3 additions & 0 deletions docs/pr-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ Requirements and pitfalls:
the pull request has now. The job needs `pull-requests: read`. It adds no labels and writes nothing to GitHub.
- Opening a pull request with labels, as `gh pr create --label` does, fires `labeled` a moment after `opened`. A label
event within a minute of opening passes at once, since the run for `opened` reads the labels when it checks.
- A label event on a closed or merged pull request passes at once. After a merge the head is already on the base branch,
so the fragment check would find no fragment to count; a closed pull request is checked again by the `reopened` run,
so keep `reopened` in the trigger types.
- Do not cancel runs in progress with a `concurrency` group: the cancelled run shows as a failed check while the other
passes.

Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ def _expression(
return environment.get("PULL_NUMBER", "7")
if expression == "github.event.action":
return environment.get("EVENT_ACTION", "opened")
if expression == "github.event.pull_request.state":
return environment.get("PULL_STATE", "open")
if expression == "github.event.pull_request.created_at":
return environment.get("CREATED_AT", "2026-01-01T00:00:00Z")
if expression == "github.event.pull_request.updated_at":
Expand Down
33 changes: 33 additions & 0 deletions tests/validate_news/test_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,36 @@ def test_validate_news_skips_labels_set_while_opening(
**_current_labels(github_api, "false"),
)
assert (result.returncode, "add a changelog fragment" in result.stderr) == ((1, True) if checked else (0, False))


@pytest.mark.parametrize(
("event", "state", "checked"),
[
pytest.param("labeled", "closed", False, id="labeled-after-merge"),
pytest.param("unlabeled", "closed", False, id="unlabeled-after-close"),
pytest.param("labeled", "open", True, id="labeled-while-open"),
],
)
def test_validate_news_skips_labels_changed_on_a_closed_pull_request(
repository: Path,
tmp_path: Path,
action_scripts: Path,
event: str,
state: str,
checked: bool,
github_api: tuple[HTTPServer, dict[str, str]],
) -> None:
result = action(
repository,
tmp_path,
action_scripts,
"validate-news",
version="0.2.0",
BASE_REF="main",
BOT_AUTHOR="false",
EVENT_ACTION=event,
PULL_STATE=state,
UPDATED_AT="2026-01-02T00:00:00Z",
**_current_labels(github_api, "false"),
)
assert (result.returncode, "add a changelog fragment" in result.stderr) == ((1, True) if checked else (0, False))
19 changes: 13 additions & 6 deletions validate-news/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ inputs:
runs:
using: composite
steps:
- id: opening
name: 🧭 Skip labels set while opening
- id: label-change
name: 🧭 Skip label changes the news check does not need
if: github.event.action == 'labeled' || github.event.action == 'unlabeled'
shell: bash
env:
STATE: ${{ github.event.pull_request.state }}
CREATED: ${{ github.event.pull_request.created_at }}
UPDATED: ${{ github.event.pull_request.updated_at }}
run: |
set -euo pipefail
# A merged pull request's head is already on the base branch, so no fragment differs from the merge base.
if [[ "$STATE" != open ]]; then
echo "News check skipped: labels changed on a $STATE pull request"
echo 'skip=true' >>"$GITHUB_OUTPUT"
exit 0
fi
# `gh pr create --label` labels a pull request right after opening it, so `labeled` fires beside `opened`. The
# run for `opened` reads the current labels when it checks, which leaves this run nothing to add.
seconds=$(($(date -d "$UPDATED" +%s) - $(date -d "$CREATED" +%s)))
Expand All @@ -46,7 +53,7 @@ runs:
fi
- id: news-change
name: 🧭 Check whether news inputs changed
if: steps.opening.outputs.skip != 'true'
if: steps.label-change.outputs.skip != 'true'
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
Expand Down Expand Up @@ -106,7 +113,7 @@ runs:
echo "Changed fragments: $(python3 "$GITHUB_ACTION_PATH/../tools/plural.py" "$(<"$RUNNER_TEMP/news-fragment-count")" fragment) valid against origin/$BASE_REF"
- id: labels
name: 🏷️ Read the current labels
if: steps.opening.outputs.skip != 'true'
if: steps.label-change.outputs.skip != 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -119,7 +126,7 @@ runs:
echo "Current labels of #$PULL: skip news $([[ "$skip" == true ]] && echo present || echo absent)"
echo "skip=$skip" >>"$GITHUB_OUTPUT"
- name: 🔍 Require news for human changes
if: steps.opening.outputs.skip != 'true'
if: steps.label-change.outputs.skip != 'true'
shell: bash
env:
SKIP_NEWS: ${{ steps.labels.outputs.skip }}
Expand All @@ -139,7 +146,7 @@ runs:
fi
- id: lock-change
name: 🧭 Check whether release inputs changed
if: steps.opening.outputs.skip != 'true'
if: steps.label-change.outputs.skip != 'true'
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
Expand Down