Support generating major releases using issue comments (#7548)

This commit is contained in:
Bruno Oliveira 2020-07-28 08:40:14 -03:00 committed by GitHub
parent c2c0b7a542
commit 38029828d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 13 deletions

View File

@ -17,6 +17,10 @@ The comment must be in the form::
Where ``BRANCH`` is ``master`` or one of the maintenance branches. Where ``BRANCH`` is ``master`` or one of the maintenance branches.
For major releases the comment must be in the form::
@pytestbot please prepare major release from master
After that, the workflow should publish a PR and notify that it has done so as a comment After that, the workflow should publish a PR and notify that it has done so as a comment
in the original issue. in the original issue.

View File

@ -2,7 +2,7 @@
This script is part of the pytest release process which is triggered by comments This script is part of the pytest release process which is triggered by comments
in issues. in issues.
This script is started by the `prepare_release.yml` workflow, which is triggered by two comment This script is started by the `release-on-comment.yml` workflow, which is triggered by two comment
related events: related events:
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issue-comment-event-issue_comment * https://help.github.com/en/actions/reference/events-that-trigger-workflows#issue-comment-event-issue_comment
@ -10,12 +10,13 @@ related events:
This script receives the payload and a secrets on the command line. This script receives the payload and a secrets on the command line.
The payload must contain a comment with a phrase matching this regular expression: The payload must contain a comment with a phrase matching this pseudo-regular expression:
@pytestbot please prepare release from <branch name> @pytestbot please prepare (major )? release from <branch name>
Then the appropriate version will be obtained based on the given branch name: Then the appropriate version will be obtained based on the given branch name:
* a major release from master if "major" appears in the phrase in that position
* a feature or bug fix release from master (based if there are features in the current changelog * a feature or bug fix release from master (based if there are features in the current changelog
folder) folder)
* a bug fix from a maintenance branch * a bug fix from a maintenance branch
@ -76,15 +77,15 @@ def get_comment_data(payload: Dict) -> str:
def validate_and_get_issue_comment_payload( def validate_and_get_issue_comment_payload(
issue_payload_path: Optional[Path], issue_payload_path: Optional[Path],
) -> Tuple[str, str]: ) -> Tuple[str, str, bool]:
payload = json.loads(issue_payload_path.read_text(encoding="UTF-8")) payload = json.loads(issue_payload_path.read_text(encoding="UTF-8"))
body = get_comment_data(payload)["body"] body = get_comment_data(payload)["body"]
m = re.match(r"@pytestbot please prepare release from ([\w\-_\.]+)", body) m = re.match(r"@pytestbot please prepare (major )?release from ([\w\-_\.]+)", body)
if m: if m:
base_branch = m.group(1) is_major, base_branch = m.group(1) is not None, m.group(2)
else: else:
base_branch = None is_major, base_branch = False, None
return payload, base_branch return payload, base_branch, is_major
def print_and_exit(msg) -> None: def print_and_exit(msg) -> None:
@ -94,7 +95,9 @@ def print_and_exit(msg) -> None:
def trigger_release(payload_path: Path, token: str) -> None: def trigger_release(payload_path: Path, token: str) -> None:
error_contents = "" # to be used to store error output in case any command fails error_contents = "" # to be used to store error output in case any command fails
payload, base_branch = validate_and_get_issue_comment_payload(payload_path) payload, base_branch, is_major = validate_and_get_issue_comment_payload(
payload_path
)
if base_branch is None: if base_branch is None:
url = get_comment_data(payload)["html_url"] url = get_comment_data(payload)["html_url"]
print_and_exit( print_and_exit(
@ -109,10 +112,9 @@ def trigger_release(payload_path: Path, token: str) -> None:
issue = repo.issue(issue_number) issue = repo.issue(issue_number)
check_call(["git", "checkout", f"origin/{base_branch}"]) check_call(["git", "checkout", f"origin/{base_branch}"])
print("DEBUG:", check_output(["git", "rev-parse", "HEAD"]))
try: try:
version = find_next_version(base_branch) version = find_next_version(base_branch, is_major)
except InvalidFeatureRelease as e: except InvalidFeatureRelease as e:
issue.create_comment(str(e)) issue.create_comment(str(e))
print_and_exit(f"{Fore.RED}{e}") print_and_exit(f"{Fore.RED}{e}")
@ -215,7 +217,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
print_and_exit(f"{Fore.RED}{error_contents}") print_and_exit(f"{Fore.RED}{error_contents}")
def find_next_version(base_branch: str) -> str: def find_next_version(base_branch: str, is_major: bool) -> str:
output = check_output(["git", "tag"], encoding="UTF-8") output = check_output(["git", "tag"], encoding="UTF-8")
valid_versions = [] valid_versions = []
for v in output.splitlines(): for v in output.splitlines():
@ -242,7 +244,9 @@ def find_next_version(base_branch: str) -> str:
msg += "\n".join(f"* `{x.name}`" for x in sorted(features + breaking)) msg += "\n".join(f"* `{x.name}`" for x in sorted(features + breaking))
raise InvalidFeatureRelease(msg) raise InvalidFeatureRelease(msg)
if is_feature_release: if is_major:
return f"{last_version[0]+1}.0.0"
elif is_feature_release:
return f"{last_version[0]}.{last_version[1] + 1}.0" return f"{last_version[0]}.{last_version[1] + 1}.0"
else: else:
return f"{last_version[0]}.{last_version[1]}.{last_version[2] + 1}" return f"{last_version[0]}.{last_version[1]}.{last_version[2] + 1}"