-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_pod.py
147 lines (103 loc) · 3.54 KB
/
update_pod.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import os, sys
import fileinput
# ====================== edit by yourself ======================
sources = [
#'https://github.com/MarcSteven/MemoryChainKit.git',
]
project_name = 'UserModule-master'
podspec_file_name = 'UserModule.podspec'
# ==================================================================
new_tag = ""
lib_command = ""
pod_push_command = ""
spec_file_path = "./" + podspec_file_name
find_version_flag = False
def podCommandEdit():
global lib_command
global pod_push_command
source_suffix = 'https://github.com/CocoaPods/Specs.git --allow-warnings'
lib_command = 'pod lib lint --sources='
pod_push_command = 'pod repo push ' + project_name + ' ' + podspec_file_name
if len(sources) > 0:
# rely on private sourece
pod_push_command += ' --sources='
for index,source in enumerate(sources):
lib_command += source
lib_command += ','
pod_push_command += source
pod_push_command += ','
lib_command += source_suffix
pod_push_command += source_suffix
else:
lib_command = 'pod lib lint'
def updateVersion():
f = open(spec_file_path, 'r+')
infos = f.readlines()
f.seek(0, 0)
file_data = ""
new_line = ""
global find_version_flag
for line in infos:
if line.find(".version") != -1:
if find_version_flag == False:
# find s.version = "xxxx"
spArr = line.split('.')
last = spArr[-1]
last = last.replace('"', '')
last = last.replace("'", "")
newNum = int(last) + 1
arr2 = line.split('"')
arr3 = line.split("'")
versionStr = ""
if len(arr2) > 2:
versionStr = arr2[1]
if len(arr3) > 2:
versionStr = arr3[1]
numArr = versionStr.split(".")
numArr[-1] = str(newNum)
# rejoint string
global new_tag
for index,subNumStr in enumerate(numArr):
new_tag += subNumStr
if index < len(numArr)-1:
new_tag += "."
# complete new_tag
if len(arr2) > 2:
line = arr2[0] + '"' + new_tag + '"' + '\n'
if len(arr3) > 2:
line = arr3[0] + "'" + new_tag + "'" + "\n"
# complete new_line
print "this is new tag " + new_tag
find_version_flag = True
file_data += line
with open(spec_file_path, 'w', ) as f1:
f1.write(file_data)
f.close()
print "--------- auto update version -------- "
def libLint():
print("-------- waiting for pod lib lint checking ...... ---------")
os.system(lib_command)
def gitOperation():
os.system('git add .')
commit_desc = "version_" + new_tag
commit_command = 'git commit -m "' + commit_desc + '"'
os.system(commit_command)
# git push
r = os.popen('git symbolic-ref --short -q HEAD')
current_branch = r.read()
r.close()
push_command = 'git push origin ' + current_branch
# tag
tag_command = 'git tag -m "' + new_tag + '" ' + new_tag
os.system(tag_command)
# push tags
os.system('git push --tags')
def podPush():
print("-------- waiting for pod push ...... ---------")
os.system(pod_push_command)
# run commands
updateVersion()
podCommandEdit()
libLint()
gitOperation()
podPush()