Skip to content

Commit 44fc019

Browse files
authored
Merge pull request #7719 from nicoddemus/fix-release-script
Use tox to execute release script
2 parents 885d969 + 5371be4 commit 44fc019

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

scripts/release-on-comment.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
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 `release-on-comment.yml` workflow, which is triggered by two comment
6-
related events:
5+
This script is started by the `release-on-comment.yml` workflow, which always executes on
6+
`master` and is triggered by two comment 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
@@ -30,7 +30,7 @@
3030
import json
3131
import os
3232
import re
33-
import sys
33+
import traceback
3434
from pathlib import Path
3535
from subprocess import CalledProcessError
3636
from subprocess import check_call
@@ -94,7 +94,6 @@ def print_and_exit(msg) -> None:
9494

9595

9696
def trigger_release(payload_path: Path, token: str) -> None:
97-
error_contents = "" # to be used to store error output in case any command fails
9897
payload, base_branch, is_major = validate_and_get_issue_comment_payload(
9998
payload_path
10099
)
@@ -119,6 +118,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
119118
issue.create_comment(str(e))
120119
print_and_exit(f"{Fore.RED}{e}")
121120

121+
error_contents = ""
122122
try:
123123
print(f"Version: {Fore.CYAN}{version}")
124124

@@ -146,11 +146,12 @@ def trigger_release(payload_path: Path, token: str) -> None:
146146

147147
print(f"Branch {Fore.CYAN}{release_branch}{Fore.RESET} created.")
148148

149+
# important to use tox here because we have changed branches, so dependencies
150+
# might have changed as well
151+
cmdline = ["tox", "-e", "release", "--", version, "--skip-check-links"]
152+
print("Running", " ".join(cmdline))
149153
run(
150-
[sys.executable, "scripts/release.py", version, "--skip-check-links"],
151-
text=True,
152-
check=True,
153-
capture_output=True,
154+
cmdline, text=True, check=True, capture_output=True,
154155
)
155156

156157
oauth_url = f"https://{token}:[email protected]/{SLUG}.git"
@@ -178,43 +179,31 @@ def trigger_release(payload_path: Path, token: str) -> None:
178179
)
179180
print(f"Notified in original comment {Fore.CYAN}{comment.url}{Fore.RESET}.")
180181

181-
print(f"{Fore.GREEN}Success.")
182182
except CalledProcessError as e:
183-
error_contents = e.output
184-
except Exception as e:
185-
error_contents = str(e)
186-
link = f"https://github.com/{SLUG}/actions/runs/{os.environ['GITHUB_RUN_ID']}"
187-
issue.create_comment(
188-
dedent(
189-
f"""
190-
Sorry, the request to prepare release `{version}` from {base_branch} failed with:
191-
192-
```
193-
{e}
194-
```
195-
196-
See: {link}.
197-
"""
198-
)
199-
)
200-
print_and_exit(f"{Fore.RED}{e}")
183+
error_contents = f"CalledProcessError\noutput:\n{e.output}\nstderr:\n{e.stderr}"
184+
except Exception:
185+
error_contents = f"Exception:\n{traceback.format_exc()}"
201186

202187
if error_contents:
203188
link = f"https://github.com/{SLUG}/actions/runs/{os.environ['GITHUB_RUN_ID']}"
204-
issue.create_comment(
205-
dedent(
206-
f"""
207-
Sorry, the request to prepare release `{version}` from {base_branch} failed with:
208-
209-
```
210-
{error_contents}
211-
```
212-
213-
See: {link}.
214-
"""
215-
)
189+
msg = ERROR_COMMENT.format(
190+
version=version, base_branch=base_branch, contents=error_contents, link=link
216191
)
192+
issue.create_comment(msg)
217193
print_and_exit(f"{Fore.RED}{error_contents}")
194+
else:
195+
print(f"{Fore.GREEN}Success.")
196+
197+
198+
ERROR_COMMENT = """\
199+
The request to prepare release `{version}` from {base_branch} failed with:
200+
201+
```
202+
{contents}
203+
```
204+
205+
See: {link}.
206+
"""
218207

219208

220209
def find_next_version(base_branch: str, is_major: bool) -> str:

0 commit comments

Comments
 (0)