This repository was archived by the owner on May 19, 2025. It is now read-only.
forked from Materialious/Materialious
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_versions.py
More file actions
82 lines (62 loc) · 2.46 KB
/
update_versions.py
File metadata and controls
82 lines (62 loc) · 2.46 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
import os
import re
from datetime import datetime
LATEST_VERSION = "1.7.22"
RELEASE_DATE = datetime.now().strftime("%Y-%-m-%d") # Format: YYYY-M-D
WORKING_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "materialious"
)
ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json")
ELECTRON_PACKAGE = os.path.join(WORKING_DIR, "electron", "package.json")
ANDROID_PACKAGE = os.path.join(WORKING_DIR, "android", "app", "build.gradle")
METAINFO_FILE = os.path.join(
WORKING_DIR, "electron", "materialious.metainfo.xml"
)
def package_json_update_ver(location: str) -> None:
with open(location, "r") as f_:
package = json.load(f_)
if package["version"] == LATEST_VERSION:
return
package["version"] = LATEST_VERSION
with open(location, "w") as f_:
json.dump(package, f_, indent="\t")
def update_android_version() -> None:
with open(ANDROID_PACKAGE, "r") as f_:
contents = f_.read()
version_code_match = re.search(r"versionCode\s+(\d+)", contents)
version_name_match = re.search(r'versionName\s+"([^"]+)"', contents)
if version_code_match and version_name_match:
version_code = int(version_code_match.group(1)) + 1
contents = re.sub(
r"versionCode\s+\d+", f"versionCode {version_code}", contents
)
contents = re.sub(
r'versionName\s+"[^"]+"',
f'versionName "{LATEST_VERSION}"',
contents,
)
with open(ANDROID_PACKAGE, "w") as f_:
f_.write(contents)
def update_metainfo_release() -> None:
with open(METAINFO_FILE, "r") as f_:
contents = f_.read()
# Check if the version already exists in the releases
if re.search(rf'<release version="{re.escape(LATEST_VERSION)}"', contents):
print(f"Release version {LATEST_VERSION} already exists.")
return
new_release = f"""
<release version="{LATEST_VERSION}" date="{RELEASE_DATE}">
<url>https://github.com/Materialious/Materialious/releases/tag/{LATEST_VERSION}</url>
</release>"""
# Insert the new release after the opening <releases> tag
updated_contents = re.sub(
r"(<releases>\s*)", rf"\1{new_release}\n", contents
)
with open(METAINFO_FILE, "w") as f_:
f_.write(updated_contents)
if __name__ == "__main__":
for location in (ROOT_PACKAGE, ELECTRON_PACKAGE):
package_json_update_ver(location)
update_android_version()
update_metainfo_release()