-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathupdate-version.py
More file actions
73 lines (62 loc) · 2.36 KB
/
Copy pathupdate-version.py
File metadata and controls
73 lines (62 loc) · 2.36 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
#!/usr/bin/env python3
"""Update Maple's release-version sources consistently."""
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def replace_once(path: Path, pattern: str, replacement: str) -> None:
contents = path.read_text()
updated, count = re.subn(pattern, replacement, contents, flags=re.MULTILINE)
if count != 1:
raise SystemExit(f"Expected one version field in {path.relative_to(ROOT)}, found {count}.")
path.write_text(updated)
def main() -> None:
if len(sys.argv) != 3:
raise SystemExit("Usage: update-version.py X.Y.Z ANDROID_VERSION_CODE")
version, android_version_code = sys.argv[1:]
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", version):
raise SystemExit(f"Invalid version: {version}")
if not re.fullmatch(r"[0-9]+", android_version_code):
raise SystemExit(f"Invalid Android version code: {android_version_code}")
replace_once(
ROOT / "apps/maple-research/frontend/package.json",
r'("version": ")[^"]*(")',
rf"\g<1>{version}\g<2>",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/tauri.conf.json",
r'("version": ")[^"]*(")',
rf"\g<1>{version}\g<2>",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/tauri.conf.json",
r'("versionCode": )\d+',
rf"\g<1>{android_version_code}",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/Cargo.toml",
r'^(version = ")[^"]*(")$',
rf"\g<1>{version}\g<2>",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/gen/apple/project.yml",
r'^(\s*CFBundleShortVersionString: ).*$',
rf"\g<1>{version}",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/gen/apple/project.yml",
r'^(\s*CFBundleVersion: ).*$',
rf"\g<1>{version}",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/gen/apple/maple_iOS/Info.plist",
r'(<key>CFBundleShortVersionString</key>\s*<string>)[^<]*(</string>)',
rf"\g<1>{version}\g<2>",
)
replace_once(
ROOT / "apps/maple-research/frontend/src-tauri/gen/apple/maple_iOS/Info.plist",
r'(<key>CFBundleVersion</key>\s*<string>)[^<]*(</string>)',
rf"\g<1>{version}\g<2>",
)
if __name__ == "__main__":
main()