|
13 | 13 | Prerequisites:
|
14 | 14 | - This must be run from the root of the repository.
|
15 | 15 | - The repo must have a clean git working tree.
|
16 |
| - - The user must have the GITHUB_TOKEN environment variable set to a valid GitHub personal access token. |
| 16 | + - The user must have the GITHUB_TOKEN environment variable set to a GitHub personal access token with repository "Contents" read and write permission. |
17 | 17 | - The user will need credentials for the PyPI repository, which the user will be prompted for during the upload step. The user will need to paste the token manually from a password manager or similar.
|
18 | 18 | - The CHANGELOG.md file must already contain an entry for the version being released.
|
19 | 19 | - Install requirements with: pip install --upgrade --editable '.[release]'
|
|
22 | 22 |
|
23 | 23 | from __future__ import annotations
|
24 | 24 |
|
| 25 | +import contextlib |
25 | 26 | import os
|
26 | 27 | import re
|
27 | 28 | import subprocess
|
28 | 29 | import sys
|
| 30 | +from collections.abc import Iterator |
29 | 31 | from pathlib import Path
|
30 | 32 |
|
31 | 33 | import requests
|
32 | 34 |
|
33 | 35 |
|
34 |
| -def add_git_tag_for_version(version: str) -> None: |
| 36 | +@contextlib.contextmanager |
| 37 | +def add_git_tag_for_version(version: str) -> Iterator[None]: |
35 | 38 | """Add a git tag for the given version."""
|
36 | 39 | subprocess.run(["git", "tag", "-a", version, "-m", version], check=True)
|
37 | 40 | print(f"Version {version} tag added successfully.")
|
| 41 | + try: |
| 42 | + yield |
| 43 | + except Exception: |
| 44 | + subprocess.run(["git", "tag", "-d", version]) |
| 45 | + raise |
38 | 46 |
|
39 | 47 |
|
40 | 48 | def remove_previous_dist() -> None:
|
@@ -68,8 +76,6 @@ def verify_build(is_test: str) -> None:
|
68 | 76 | confirmation = input("Does the build look correct? (y/n): ")
|
69 | 77 | if confirmation == "y":
|
70 | 78 | print("Build verified successfully.")
|
71 |
| - upload_build_to_pypi(is_test) |
72 |
| - push_git_tags() |
73 | 79 | else:
|
74 | 80 | raise Exception("Could not verify. Build was not uploaded.")
|
75 | 81 |
|
@@ -227,10 +233,12 @@ def main() -> None:
|
227 | 233 | is_test = get_is_test_response()
|
228 | 234 | version_number = input("Enter the version number: ")
|
229 | 235 |
|
230 |
| - add_git_tag_for_version(version_number) |
231 |
| - remove_previous_dist() |
232 |
| - create_build() |
233 |
| - verify_build(is_test) |
| 236 | + with add_git_tag_for_version(version_number): |
| 237 | + remove_previous_dist() |
| 238 | + create_build() |
| 239 | + verify_build(is_test) |
| 240 | + upload_build_to_pypi(is_test) |
| 241 | + push_git_tags() |
234 | 242 | create_github_release_draft(github_token, version_number)
|
235 | 243 |
|
236 | 244 |
|
|
0 commit comments