forked from lovegaoshi/azusa-player-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_bump.py
60 lines (53 loc) · 2.3 KB
/
version_bump.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
import re
import json
from pathlib import Path
def get_version():
with open(Path('src/enums/Version.ts'), encoding='utf8') as f:
for line in f:
find_version = re.search(r'(\d+\.\d+\.\d+)', line)
if (find_version):
return find_version.group(0)
def bump_version():
new_version = get_version()
with open(Path('./package.json'), encoding='utf8') as f:
package_json = json.load(f)
package_json['version'] = new_version
with open(Path('./package.json'), 'w', encoding='utf8') as f:
json.dump(package_json, f, indent=2)
build_gradle = []
with open(Path('./android/app/build.gradle'), encoding='utf8') as f:
for line in f:
find_version_code = re.search(r'(.+versionCode )(\d+)', line)
find_version_name = re.search(r'(.+versionName )".+"', line)
if not '//' in line and find_version_code:
build_gradle.append(
f"{find_version_code.group(1)}{int(find_version_code.group(2)) + 1}\n")
elif find_version_name:
build_gradle.append(
f"{find_version_name.group(1)}\"{new_version}\"\n")
else:
build_gradle.append(line)
with open(Path('./android/app/build.gradle'), 'w', encoding='utf8') as f:
for line in build_gradle:
f.write(line)
build_gradle = []
with open(Path('./ios/APM.xcodeproj/project.pbxproj'), encoding='utf8') as f:
for line in f:
find_version_code = re.search(
r'(.+CURRENT_PROJECT_VERSION = )(\d+);', line)
find_version_name = re.search(
r'(.+MARKETING_VERSION = ).+;', line)
if not '//' in line and find_version_code:
build_gradle.append(
f"{find_version_code.group(1)}{int(find_version_code.group(2)) + 1};\n")
elif find_version_name:
build_gradle.append(
f"{find_version_name.group(1)}{new_version};\n")
else:
build_gradle.append(line)
with open(Path('./ios/APM.xcodeproj/project.pbxproj'), 'w', encoding='utf8') as f:
for line in build_gradle:
f.write(line)
if __name__ == '__main__':
bump_version()
print(f"Version bumped to {get_version()}")