diff --git a/rio/snippets/snippet-files/project-template-Authentication/root_init.py b/rio/snippets/snippet-files/project-template-Authentication/root_init.py index bedc1832..13562516 100644 --- a/rio/snippets/snippet-files/project-template-Authentication/root_init.py +++ b/rio/snippets/snippet-files/project-template-Authentication/root_init.py @@ -67,6 +67,9 @@ async def on_session_start(rio_session: rio.Session) -> None: ) +# + + # async def on_demo_session_start(rio_session: rio.Session) -> None: # Create a persistence instance. This class hides the gritty details of diff --git a/scripts/publish_new_release.py b/scripts/publish_new_release.py index 0c4ea941..cdf00abd 100644 --- a/scripts/publish_new_release.py +++ b/scripts/publish_new_release.py @@ -1,13 +1,20 @@ +import os +import shutil import subprocess import sys +import tempfile +from pathlib import Path import revel +import rio.cli.project_setup +import rio.snippets from rio.version import Version def main() -> None: - revel.print("Running sanity checks...") + # Sanity checks + revel.print_chapter("Running sanity checks") ensure_branch("main") ensure_no_uncommitted_changes() @@ -16,7 +23,14 @@ def main() -> None: build_frontend() ensure_tests_pass() - revel.print("Everything is in order.") + revel.success("Everything is in order.") + + # Update the templates repository + revel.print_chapter("Updating templates repository") + publish_current_templates() + + # Publish + revel.print_chapter("Building & Publishing release") make_new_release() @@ -75,6 +89,85 @@ def ensure_tests_pass() -> None: revel.print("Publishing...") +def has_git_changes() -> bool: + result = subprocess.run( + ["git", "status", "--porcelain"], + capture_output=True, + text=True, + check=True, + ) + return bool(result.stdout.strip()) + + +def publish_current_templates() -> None: + """ + All of Rio's built-in templates are available in source code form in a + public repository. This allows users to browse the code. This function + ensures that the latest versions of all templates are available in the + repository. + + It's unclear whether this function should be in the `rio` project itself, or + the website. While not strongly linked to the website, having the repository + update here ensures that the links on the Rio website are always correct, + i.e. all templates that the site links to are also definitely in that + repository. + """ + # Check out the repository + template_repo_dir = Path(tempfile.mkdtemp()) + + subprocess.run( + [ + "git", + "clone", + "git@github.com:rio-labs/rio-templates.git", + str(template_repo_dir), + ], + check=True, + ) + + # Wipe the current templates + keep_files = ( + ".git", + "LICENSE.txt", + "README.md", + ) + + for file_path in template_repo_dir.iterdir(): + if file_path.name not in keep_files: + assert file_path.is_dir(), file_path + shutil.rmtree(file_path) + + # Save the current working directory + original_working_directory = os.getcwd() + + # Re-instantiate all templates + # + # This prints profusely, so tell it to be quiet + original_stdout = sys.stdout + sys.stdout = open(os.devnull, "w") + + os.chdir(template_repo_dir) + + for template in rio.snippets.get_project_templates(include_empty=False): + rio.cli.project_setup.create_project( + raw_name=template.name, + type="website", + template_name=template.name, + target_parent_directory=template_repo_dir, + ) + + # Commit and push, if there are changes + subprocess.run(["git", "add", "."], check=True) + + if has_git_changes(): + subprocess.run(["git", "commit", "-m", "Update templates"], check=True) + subprocess.run(["git", "push"], check=True) + + # Restore previous state + sys.stdout = original_stdout + os.chdir(original_working_directory) + + def make_new_release() -> None: # Bump version bump_version()