|
1 | 1 | # /// script |
2 | 2 | # requires-python = ">=3.10" |
3 | 3 | # dependencies = [ |
4 | | -# cookiecutter, |
5 | | -# cruft, |
6 | | -# typer, |
| 4 | +# "cookiecutter", |
| 5 | +# "cruft", |
| 6 | +# "python-dotenv", |
| 7 | +# "typer", |
7 | 8 | # ] |
8 | 9 | # /// |
| 10 | +import itertools |
| 11 | +import subprocess |
9 | 12 | from pathlib import Path |
10 | 13 | from typing import Annotated |
11 | 14 |
|
12 | 15 | import typer |
13 | 16 | from cookiecutter.utils import work_in |
| 17 | +from loguru import logger |
14 | 18 |
|
| 19 | +from util import get_current_branch |
15 | 20 | from util import get_demo_name |
| 21 | +from util import gh |
16 | 22 | from util import git |
17 | | -from util import is_ancestor |
18 | | -from util import uv |
19 | | -from util import validate_is_synced_ancestor |
| 23 | +from util import nox |
| 24 | +from util import require_clean_and_up_to_date_repo |
20 | 25 | from util import FolderOption |
| 26 | +from util import RepoMetadata |
| 27 | +from util import DEMO |
21 | 28 |
|
22 | 29 |
|
23 | 30 | cli: typer.Typer = typer.Typer() |
|
26 | 33 | @cli.callback(invoke_without_command=True) |
27 | 34 | def release_demo( |
28 | 35 | demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c")], |
29 | | - min_python_version: Annotated[str, typer.Option("--min-python-version")], |
30 | | - max_python_version: Annotated[str, typer.Option("--max-python-version")], |
31 | 36 | add_rust_extension: Annotated[bool, typer.Option("--add-rust-extension", "-r")] = False |
32 | 37 | ) -> None: |
33 | 38 | """Creates a release of the demo's current develop branch if changes exist.""" |
34 | 39 | demo_name: str = get_demo_name(add_rust_extension=add_rust_extension) |
35 | 40 | demo_path: Path = demos_cache_folder / demo_name |
36 | 41 |
|
| 42 | + with work_in(demo_path): |
| 43 | + require_clean_and_up_to_date_repo() |
| 44 | + git("checkout", DEMO.develop_branch) |
| 45 | + try: |
| 46 | + nox("setup-release", "--", "MINOR") |
| 47 | + logger.success(f"Successfully created release {demo_name}") |
| 48 | + _ensure_github_repo_set(repo=DEMO) |
37 | 49 |
|
| 50 | + except subprocess.CalledProcessError as error: |
| 51 | + logger.warning(f"Failed to setup release: {error}") |
| 52 | + _rollback_failed_release() |
| 53 | + raise error |
38 | 54 |
|
| 55 | + git("push", "-u") |
| 56 | + _create_demo_pr(version=) |
39 | 57 |
|
40 | | -def _validate_demo_develop_up_to_date(demo_path: Path) -> None: |
41 | | - """Ensures the demo's develop branch is up to date.""" |
42 | | - with work_in(demo_path): |
43 | | - validate_is_synced_ancestor(ancestor=) |
| 58 | + |
| 59 | +def _ensure_github_repo_set(repo: RepoMetadata) -> None: |
| 60 | + """Ensures the repo has a github repo set.""" |
| 61 | + gh("repo", "set-default", repo.app_author, repo.app_name) |
44 | 62 |
|
45 | 63 |
|
| 64 | +def _rollback_failed_release() -> None: |
| 65 | + """Returns the demo repo back to the state it was prior to the release attempt.""" |
| 66 | + starting_demo_branch: str = get_current_branch() |
46 | 67 |
|
| 68 | + if starting_demo_branch != "develop": |
| 69 | + git("checkout", DEMO.develop_branch) |
47 | 70 |
|
| 71 | + git("checkout", ".") |
| 72 | + git("branch", "-D", starting_demo_branch) |
48 | 73 |
|
49 | 74 |
|
| 75 | +def _create_demo_pr(version: str) -> None: |
| 76 | + """Creates a pull request to merge the demo's feature branch into .""" |
| 77 | + pr_kwargs: dict[str, str] = { |
| 78 | + "--title": f"Release/{version}" |
| 79 | + } |
| 80 | + publish_release_commands: list[list[str]] = [ |
| 81 | + ["gh", "pr", "create", *itertools.chain(pr_kwargs.items())], |
| 82 | + ] |
50 | 83 |
|
0 commit comments