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
31 changes: 31 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,37 @@ The `<PR_REF>` can be:
or `https://github.com/bazel-contrib/rules_python/pull/124/files`)
* Only URLs for the configured repository are accepted.

### Processing News Files and PR Changes for Backports

To process and merge news files into an existing release in `CHANGELOG.md`
(e.g. after backporting a PR) and update any `VERSION_NEXT_*` markers added by
the PR:

```shell
bazel run //tools/private/release -- \
process-news <VERSION> <TARGET> [<TARGET> ...]
```

The `<TARGET>` can be:
* A news file path (e.g., `news/3997.added.md`).
* A PR number (e.g., `3997` or `#3997`).
* A PR URL (e.g., `https://github.com/bazel-contrib/rules_python/pull/3997`).

When a PR reference is passed, `process-news` resolves the files touched by the
PR, merges its news file(s) into `CHANGELOG.md`, deletes the processed news
file(s), and updates any `VERSION_NEXT_FEATURE` / `VERSION_NEXT_PATCH`
placeholders in the PR's files to `<VERSION>`.

Examples:

```shell
# Process a single news file
bazel run //tools/private/release -- process-news 2.3.0 news/3997.added.md

# Process all news files and update version markers for a PR
bazel run //tools/private/release -- process-news 2.3.0 3997
```

### Failure Behavior
If a backport fails to process (e.g., due to cherry-pick conflicts):
* The failed backport checklist item will remain unchecked with
Expand Down
29 changes: 29 additions & 0 deletions tests/tools/private/release/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ py_library(
pytest_test(
name = "add_backports_test",
srcs = ["add_backports_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -42,6 +43,7 @@ pytest_test(
pytest_test(
name = "changelog_news_test",
srcs = ["changelog_news_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -53,6 +55,7 @@ pytest_test(
pytest_test(
name = "complete_prepare_test",
srcs = ["complete_prepare_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -64,6 +67,7 @@ pytest_test(
pytest_test(
name = "complete_sync_changelog_test",
srcs = ["complete_sync_changelog_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -75,6 +79,7 @@ pytest_test(
pytest_test(
name = "create_release_branch_test",
srcs = ["create_release_branch_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -86,6 +91,7 @@ pytest_test(
pytest_test(
name = "git_test",
srcs = ["git_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -97,6 +103,7 @@ pytest_test(
pytest_test(
name = "on_pr_merged_test",
srcs = ["on_pr_merged_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -108,6 +115,7 @@ pytest_test(
pytest_test(
name = "promote_test",
srcs = ["promote_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -119,6 +127,7 @@ pytest_test(
pytest_test(
name = "release_issue_test",
srcs = ["release_issue_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -130,6 +139,7 @@ pytest_test(
pytest_test(
name = "release_test",
srcs = ["release_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -141,6 +151,7 @@ pytest_test(
pytest_test(
name = "backport_create_releases_test",
srcs = ["backport_create_releases_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -152,6 +163,7 @@ pytest_test(
pytest_test(
name = "prepare_test",
srcs = ["prepare_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -163,6 +175,7 @@ pytest_test(
pytest_test(
name = "gh_test",
srcs = ["gh_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -174,6 +187,7 @@ pytest_test(
pytest_test(
name = "backport_prepare_test",
srcs = ["backport_prepare_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -185,6 +199,7 @@ pytest_test(
pytest_test(
name = "process_backports_test",
srcs = ["process_backports_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -196,6 +211,19 @@ pytest_test(
pytest_test(
name = "create_rc_test",
srcs = ["create_rc_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
":release_test_helper",
"//tools/private/release:release_lib",
],
)

pytest_test(
name = "process_news_test",
srcs = ["process_news_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand All @@ -207,6 +235,7 @@ pytest_test(
pytest_test(
name = "utils_test",
srcs = ["utils_test.py"],
python_version = "3.14",
target_compatible_with = NOT_WINDOWS,
deps = [
":conftest",
Expand Down
40 changes: 35 additions & 5 deletions tests/tools/private/release/gh_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import subprocess

import pytest

from tools.private.release import shell
from tools.private.release.gh import CreatePrError, GitHub
from tools.private.release.gh import (
CreatePrError,
GetPrError,
GitHub,
InvalidPrRefError,
)
from tools.private.release.git import Git

pytest_plugins = ["tests.tools.private.release.release_test_helper"]
Expand Down Expand Up @@ -51,14 +58,16 @@ def test_resolve_pr_number_url_other_repo(mocker, gh):
mock_run_cmd = mocker.patch("tools.private.release.gh.run_cmd")
# URL for a different repo should fail immediately without calling gh
url = "https://github.com/other-owner/other-repo/pull/126"
with pytest.raises(ValueError, match="URL is not for the configured repository"):
with pytest.raises(
InvalidPrRefError, match="URL is not for the configured repository"
):
gh.resolve_pr_number(url)
mock_run_cmd.assert_not_called()


def test_resolve_pr_number_invalid(mocker, gh):
mock_run_cmd = mocker.patch("tools.private.release.gh.run_cmd")
with pytest.raises(ValueError, match="Could not resolve PR reference"):
with pytest.raises(InvalidPrRefError, match="Could not resolve PR reference"):
gh.resolve_pr_number("invalid-ref")
mock_run_cmd.assert_not_called()

Expand Down Expand Up @@ -96,6 +105,29 @@ def mock_run(*args, **kwargs):
assert captured_body["content"] == "new body content"


def test_get_pr_files(gh, auto_patch_cmd_helpers):
auto_patch_cmd_helpers.run_gh.return_value = (
'{"files": [{"path": "news/123.added.md"}, {"path": "python/foo.py"}]}'
)
files = gh.get_pr_files(123)
assert files == ["news/123.added.md", "python/foo.py"]
auto_patch_cmd_helpers.run_gh.assert_called_with(
"pr",
"view",
"123",
"--json=files",
"--repo=my-owner/my-repo",
check=True,
capture_output=True,
)


def test_get_pr_files_not_found(gh, auto_patch_cmd_helpers):
auto_patch_cmd_helpers.run_gh.side_effect = subprocess.CalledProcessError(1, ["gh"])
with pytest.raises(GetPrError, match="Failed to get PR #123 on my-owner/my-repo"):
gh.get_pr_files(123)


def test_create_pr_success(gh, auto_patch_cmd_helpers):
auto_patch_cmd_helpers.run_gh.return_value = (
"https://github.com/my-owner/my-repo/pull/123"
Expand All @@ -121,8 +153,6 @@ def test_create_pr_success(gh, auto_patch_cmd_helpers):


def test_create_pr_failure_raises_create_pr_error(gh, auto_patch_cmd_helpers):
import subprocess

err = subprocess.CalledProcessError(
1,
["gh", "pr", "create"],
Expand Down
Loading