This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
deploy.py
64 lines (51 loc) · 1.95 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import re
import sys
from pathlib import Path
from typing import Optional
import tomli
from git.repo import Repo
from packaging import version
# check if the active branch is master
SCRIPT_ROOT = Path(__file__).parent
repo = Repo(SCRIPT_ROOT)
assert str(repo.active_branch) == "main", "Checkout to main and try again."
assert len(repo.index.diff(None)) == 0, "There are uncommited changes, aborting."
assert not repo.head.is_detached, "You are on a detached HEAD, aborting."
# get current Starklings version
path = SCRIPT_ROOT / "pyproject.toml"
new_starklings_version_str: Optional[str] = None
with open(path, "r+", encoding="UTF-8") as file:
raw_pyproject = file.read()
pyproject = tomli.loads(raw_pyproject)
version_str = pyproject["tool"]["poetry"]["version"]
starklings_version = version.parse(version_str)
print(f"Current Starklings version: {starklings_version}")
# prompt new Starklings version
new_starklings_version_str = input("Provide the new Starklings version: ")
# validate new version
match_result = re.compile(r"^\d*\.\d*\.\d*$").match(new_starklings_version_str)
if match_result is None:
print("Invalid syntax")
sys.exit(1)
new_starklings_version = version.parse(new_starklings_version_str)
if new_starklings_version <= starklings_version:
print(f"New version must be greater than {starklings_version}")
sys.exit(1)
# update version in starklings.toml
file.seek(0)
file.truncate()
file.write(
raw_pyproject.replace(
f'version = "{starklings_version}"', f'version = "{new_starklings_version}"'
)
)
assert new_starklings_version_str is not None
# add commit
repo.git.add("pyproject.toml")
commit = repo.index.commit(f":bookmark: Starklings {new_starklings_version_str}")
# add tag
tag = repo.create_tag(f"v{new_starklings_version_str}", ref=commit.hexsha)
# push to main
origin = repo.remote(name="origin")
origin.push()
origin.push(tag.path)