From d5049e315d39ff00e0b2425f0cd2fb688bde74da Mon Sep 17 00:00:00 2001 From: Aran-Fey Date: Sun, 14 Apr 2024 18:43:19 +0200 Subject: [PATCH] add release script (untested) --- scripts/publish_new_release.py | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/publish_new_release.py diff --git a/scripts/publish_new_release.py b/scripts/publish_new_release.py new file mode 100644 index 00000000..b8f0faf3 --- /dev/null +++ b/scripts/publish_new_release.py @@ -0,0 +1,56 @@ +import subprocess +import tomllib +from pathlib import Path + +import pytest +import requests +import revel + +PROJECT_DIR = Path(__file__).absolute().parent.parent + + +def main() -> None: + # Make sure we're on the correct branch + process = subprocess.run( + ["git", "branch"], check=True, capture_output=True, text=True + ) + if process.stdout.strip("\n") != "dev": + revel.fatal("You must checkout the 'dev' branch") + + # Make sure the version number got bumped + version = get_current_version() + if version == get_latest_published_version(): + revel.fatal("You forgot to increment the version number") + + # Build the TS code + subprocess.run(["npm", "run", "build"], check=True) + + # Run the test suite + if not tests_pass(): + revel.fatal("The test don't pass") + + # Merge dev into main and push + subprocess.run(["git", "fetch", ".", "dev:main"], check=True) + subprocess.run(["git", "push", "-u", "origin", "main"], check=True) + + # Publish + subprocess.run(["poetry", "publish"], check=True) + + +def get_latest_published_version() -> str: + response = requests.get(f"https://pypi.org/pypi/rio-ui/json") + return response.json()["info"]["version"] + + +def get_current_version() -> str: + with open(PROJECT_DIR / "pyproject.toml", "rb", encoding="utf8") as file: + data = tomllib.load(file) + + return data["tool"]["poetry"]["version"] + + +def tests_pass() -> bool: + return pytest.main([str(PROJECT_DIR / "tests")]) == 0 + + +main()