Use tox to execute release script

The release-on-comment script is always executed on *master*, so we should
execute the `release.py` script using tox to ensure we create the
right environment.

Also fixed errors in the error handling code.
This commit is contained in:
Bruno Oliveira 2020-09-04 17:03:47 -03:00
parent 885d969484
commit 5371be4cf6
1 changed files with 28 additions and 39 deletions

View File

@ -2,8 +2,8 @@
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 `release-on-comment.yml` workflow, which is triggered by two comment This script is started by the `release-on-comment.yml` workflow, which always executes on
related events: `master` and is triggered by two comment 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
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issues-event-issues * https://help.github.com/en/actions/reference/events-that-trigger-workflows#issues-event-issues
@ -30,7 +30,7 @@ import argparse
import json import json
import os import os
import re import re
import sys import traceback
from pathlib import Path from pathlib import Path
from subprocess import CalledProcessError from subprocess import CalledProcessError
from subprocess import check_call from subprocess import check_call
@ -94,7 +94,6 @@ 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
payload, base_branch, is_major = validate_and_get_issue_comment_payload( payload, base_branch, is_major = validate_and_get_issue_comment_payload(
payload_path payload_path
) )
@ -119,6 +118,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
issue.create_comment(str(e)) issue.create_comment(str(e))
print_and_exit(f"{Fore.RED}{e}") print_and_exit(f"{Fore.RED}{e}")
error_contents = ""
try: try:
print(f"Version: {Fore.CYAN}{version}") print(f"Version: {Fore.CYAN}{version}")
@ -146,11 +146,12 @@ def trigger_release(payload_path: Path, token: str) -> None:
print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} created.") print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} created.")
# important to use tox here because we have changed branches, so dependencies
# might have changed as well
cmdline = ["tox", "-e", "release", "--", version, "--skip-check-links"]
print("Running", " ".join(cmdline))
run( run(
[sys.executable, "scripts/release.py", version, "--skip-check-links"], cmdline, text=True, check=True, capture_output=True,
text=True,
check=True,
capture_output=True,
) )
oauth_url = f"https://{token}:x-oauth-basic@github.com/{SLUG}.git" oauth_url = f"https://{token}:x-oauth-basic@github.com/{SLUG}.git"
@ -178,43 +179,31 @@ def trigger_release(payload_path: Path, token: str) -> None:
) )
print(f"Notified in original comment {Fore.CYAN}{comment.url}{Fore.RESET}.") print(f"Notified in original comment {Fore.CYAN}{comment.url}{Fore.RESET}.")
print(f"{Fore.GREEN}Success.")
except CalledProcessError as e: except CalledProcessError as e:
error_contents = e.output error_contents = f"CalledProcessError\noutput:\n{e.output}\nstderr:\n{e.stderr}"
except Exception as e: except Exception:
error_contents = str(e) error_contents = f"Exception:\n{traceback.format_exc()}"
link = f"https://github.com/{SLUG}/actions/runs/{os.environ['GITHUB_RUN_ID']}"
issue.create_comment(
dedent(
f"""
Sorry, the request to prepare release `{version}` from {base_branch} failed with:
```
{e}
```
See: {link}.
"""
)
)
print_and_exit(f"{Fore.RED}{e}")
if error_contents: if error_contents:
link = f"https://github.com/{SLUG}/actions/runs/{os.environ['GITHUB_RUN_ID']}" link = f"https://github.com/{SLUG}/actions/runs/{os.environ['GITHUB_RUN_ID']}"
issue.create_comment( msg = ERROR_COMMENT.format(
dedent( version=version, base_branch=base_branch, contents=error_contents, link=link
f""" )
Sorry, the request to prepare release `{version}` from {base_branch} failed with: issue.create_comment(msg)
print_and_exit(f"{Fore.RED}{error_contents}")
else:
print(f"{Fore.GREEN}Success.")
ERROR_COMMENT = """\
The request to prepare release `{version}` from {base_branch} failed with:
``` ```
{error_contents} {contents}
``` ```
See: {link}. See: {link}.
""" """
)
)
print_and_exit(f"{Fore.RED}{error_contents}")
def find_next_version(base_branch: str, is_major: bool) -> str: def find_next_version(base_branch: str, is_major: bool) -> str: