Skip to content

Commit 3802982

Browse files
authored
Support generating major releases using issue comments (#7548)
1 parent c2c0b7a commit 3802982

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

RELEASING.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The comment must be in the form::
1717

1818
Where ``BRANCH`` is ``master`` or one of the maintenance branches.
1919

20+
For major releases the comment must be in the form::
21+
22+
@pytestbot please prepare major release from master
23+
2024
After that, the workflow should publish a PR and notify that it has done so as a comment
2125
in the original issue.
2226

scripts/release-on-comment.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
This script is part of the pytest release process which is triggered by comments
33
in issues.
44
5-
This script is started by the `prepare_release.yml` workflow, which is triggered by two comment
5+
This script is started by the `release-on-comment.yml` workflow, which is triggered by two comment
66
related events:
77
88
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issue-comment-event-issue_comment
99
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issues-event-issues
1010
1111
This script receives the payload and a secrets on the command line.
1212
13-
The payload must contain a comment with a phrase matching this regular expression:
13+
The payload must contain a comment with a phrase matching this pseudo-regular expression:
1414
15-
@pytestbot please prepare release from <branch name>
15+
@pytestbot please prepare (major )? release from <branch name>
1616
1717
Then the appropriate version will be obtained based on the given branch name:
1818
19+
* a major release from master if "major" appears in the phrase in that position
1920
* a feature or bug fix release from master (based if there are features in the current changelog
2021
folder)
2122
* a bug fix from a maintenance branch
@@ -76,15 +77,15 @@ def get_comment_data(payload: Dict) -> str:
7677

7778
def validate_and_get_issue_comment_payload(
7879
issue_payload_path: Optional[Path],
79-
) -> Tuple[str, str]:
80+
) -> Tuple[str, str, bool]:
8081
payload = json.loads(issue_payload_path.read_text(encoding="UTF-8"))
8182
body = get_comment_data(payload)["body"]
82-
m = re.match(r"@pytestbot please prepare release from ([\w\-_\.]+)", body)
83+
m = re.match(r"@pytestbot please prepare (major )?release from ([\w\-_\.]+)", body)
8384
if m:
84-
base_branch = m.group(1)
85+
is_major, base_branch = m.group(1) is not None, m.group(2)
8586
else:
86-
base_branch = None
87-
return payload, base_branch
87+
is_major, base_branch = False, None
88+
return payload, base_branch, is_major
8889

8990

9091
def print_and_exit(msg) -> None:
@@ -94,7 +95,9 @@ def print_and_exit(msg) -> None:
9495

9596
def trigger_release(payload_path: Path, token: str) -> None:
9697
error_contents = "" # to be used to store error output in case any command fails
97-
payload, base_branch = validate_and_get_issue_comment_payload(payload_path)
98+
payload, base_branch, is_major = validate_and_get_issue_comment_payload(
99+
payload_path
100+
)
98101
if base_branch is None:
99102
url = get_comment_data(payload)["html_url"]
100103
print_and_exit(
@@ -109,10 +112,9 @@ def trigger_release(payload_path: Path, token: str) -> None:
109112
issue = repo.issue(issue_number)
110113

111114
check_call(["git", "checkout", f"origin/{base_branch}"])
112-
print("DEBUG:", check_output(["git", "rev-parse", "HEAD"]))
113115

114116
try:
115-
version = find_next_version(base_branch)
117+
version = find_next_version(base_branch, is_major)
116118
except InvalidFeatureRelease as e:
117119
issue.create_comment(str(e))
118120
print_and_exit(f"{Fore.RED}{e}")
@@ -215,7 +217,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
215217
print_and_exit(f"{Fore.RED}{error_contents}")
216218

217219

218-
def find_next_version(base_branch: str) -> str:
220+
def find_next_version(base_branch: str, is_major: bool) -> str:
219221
output = check_output(["git", "tag"], encoding="UTF-8")
220222
valid_versions = []
221223
for v in output.splitlines():
@@ -242,7 +244,9 @@ def find_next_version(base_branch: str) -> str:
242244
msg += "\n".join(f"* `{x.name}`" for x in sorted(features + breaking))
243245
raise InvalidFeatureRelease(msg)
244246

245-
if is_feature_release:
247+
if is_major:
248+
return f"{last_version[0]+1}.0.0"
249+
elif is_feature_release:
246250
return f"{last_version[0]}.{last_version[1] + 1}.0"
247251
else:
248252
return f"{last_version[0]}.{last_version[1]}.{last_version[2] + 1}"

0 commit comments

Comments
 (0)