Merge pull request #6935 from gdhameeja/Fix-6911

This commit is contained in:
Bruno Oliveira 2020-05-16 12:08:23 -03:00 committed by GitHub
commit d9f24bca9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 6 deletions

View File

@ -33,6 +33,9 @@ import sys
from pathlib import Path from pathlib import Path
from subprocess import check_call from subprocess import check_call
from subprocess import check_output from subprocess import check_output
from subprocess import PIPE
from subprocess import run
from subprocess import STDOUT
from textwrap import dedent from textwrap import dedent
from typing import Dict from typing import Dict
from typing import Optional from typing import Optional
@ -91,6 +94,7 @@ 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 = validate_and_get_issue_comment_payload(payload_path) payload, base_branch = 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"]
@ -119,19 +123,42 @@ def trigger_release(payload_path: Path, token: str) -> None:
release_branch = f"release-{version}" release_branch = f"release-{version}"
check_call(["git", "config", "user.name", "pytest bot"]) run(
check_call(["git", "config", "user.email", "pytestbot@gmail.com"]) ["git", "config", "user.name", "pytest bot"],
text=True,
check=True,
capture_output=True,
)
run(
["git", "config", "user.email", "pytestbot@gmail.com"],
text=True,
check=True,
capture_output=True,
)
check_call(["git", "checkout", "-b", release_branch, f"origin/{base_branch}"]) run(
["git", "checkout", "-b", release_branch, f"origin/{base_branch}"],
text=True,
check=True,
capture_output=True,
)
print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} created.") print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} created.")
check_call( run(
[sys.executable, "scripts/release.py", version, "--skip-check-links"] [sys.executable, "scripts/release.py", version, "--skip-check-links"],
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"
check_call(["git", "push", oauth_url, f"HEAD:{release_branch}", "--force"]) run(
["git", "push", oauth_url, f"HEAD:{release_branch}", "--force"],
text=True,
check=True,
capture_output=True,
)
print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} pushed.") print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} pushed.")
body = PR_BODY.format( body = PR_BODY.format(
@ -151,7 +178,10 @@ 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.") print(f"{Fore.GREEN}Success.")
except CallProcessError as e:
error_contents = e.output
except Exception as e: except Exception as e:
error_contents = str(e)
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( issue.create_comment(
dedent( dedent(
@ -168,6 +198,23 @@ def trigger_release(payload_path: Path, token: str) -> None:
) )
print_and_exit(f"{Fore.RED}{e}") print_and_exit(f"{Fore.RED}{e}")
if error_contents:
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:
```
{error_contents}
```
See: {link}.
"""
)
)
print_and_exit(f"{Fore.RED}{e}")
def find_next_version(base_branch: str) -> str: def find_next_version(base_branch: str) -> str:
output = check_output(["git", "tag"], encoding="UTF-8") output = check_output(["git", "tag"], encoding="UTF-8")