-
Notifications
You must be signed in to change notification settings - Fork 185
/
pod_push.py
93 lines (73 loc) · 2.56 KB
/
pod_push.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import os
import re
pod_spec_filename = 'M80AttributedLabel.podspec'
def run():
new_version = get_new_version()
old_version = get_old_version()
print('current version is [' + old_version + ']')
if new_version is not None and old_version is not None:
question = 'do u want to upgrade current pod to \'' + new_version + '\' ? (y/n)\n'
choice = input(question).lower()
if choice == 'y' or choice == 'yes':
update(old_version,new_version)
def update(old_version,new_version):
if run_shell('pod lib lint --no-clean') != 0:
return
if update_pod_spec(old_version,new_version) == False:
return
git_add = 'git add .'
git_commit = 'git commit . -m " pod version update to ' + new_version + '"'
git_push = 'git push'
git_add_tag = 'git tag ' + new_version
git_push_tag = 'git push --tags'
pod_push = 'pod trunk push ' + pod_spec_filename
command_list = [git_add,git_commit,git_push,git_add_tag,git_push_tag,pod_push]
for command in command_list:
run_shell(command)
def get_old_version():
old_version = None
version_pattern = r"\s*s.version\s+=\s+'(\d+.\d+.\d+)'"
pod_file = './' + pod_spec_filename
with open(pod_file) as podspec:
content = podspec.read()
old_version = re.search(version_pattern,content).group(1)
return old_version
def update_pod_spec(old_version,new_version):
pod_file = './' + pod_spec_filename
new_content = None
with open(pod_file) as podspec:
content = podspec.read()
new_content = content.replace(old_version,new_version,1)
if new_content is not None:
with open(pod_file,'w') as podspec:
podspec.write(new_content)
return True
return False
def run_shell(command):
return os.system(command)
def get_new_version():
version = None
if len(sys.argv) == 2:
candidate_version = sys.argv[1].strip()
if is_valid_version(candidate_version):
version = candidate_version
else:
print('version needed')
return version
def is_valid_version(version):
valid = False
components = version.split('.')
if len(components) >= 3:
for component in components:
try:
num = int(component)
except:
print('invalid version: ',version)
return False
valid = True
if valid is False:
print('invalid version: ',version)
return valid
if __name__ == '__main__':
run()