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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/cocoapods-tools/command/spec/tag.rb', line 36
def run
super
working_dir = Pathname.pwd
pod_spec_name = 'libspec'
pod_spec_path = Pathname.pwd.parent + pod_spec_name
pod_repo_url = 'ssh://git@htsz.hellotalk.net:7999/~panda/libspec.git'
new_tag_name = @arguments[0].to_s
last_tag_name = ''
pod_source_git = Git.open(working_dir)
max_tag_no = -1
pod_source_git.tags.each do |tag|
tag_name = tag.name
tag_no = (tag_name.gsub '.', '').to_i
if max_tag_no < tag_no
max_tag_no = tag_no
last_tag_name = tag_name
end
end
last_commit = pod_source_git.log(1).first
last_tag = pod_source_git.tag(last_tag_name)
changes = `git log --name-only --pretty=oneline --full-index #{last_commit}...#{last_tag} | grep -vE '^[0-9a-f]{40} ' | sort | uniq`
puts Color.color_text "===== 与 tag:#{last_tag_name} 对比,所有文件变更如下 ======", Color.green
puts changes
puts Color.color_text '==================变更文件打印结束=================', Color.green
specs = []
Dir.entries(working_dir).each do |sub|
specs.push(sub) if File.directory?(sub) && !sub.include?('.') && changes.include?("#{sub}/#{sub}")
end
puts Color.color_text "开始更新组件列表:#{specs}", Color.red
specs.each do |spec|
podspec_path = working_dir + spec + "#{spec}.podspec"
File.open(podspec_path, 'r+') do |t|
File.open(podspec_path) do |f|
f.each_line do |line|
write_line = line
version_desc = /.*\.version\s*=.*/.match line
unless version_desc.nil?
version_comes = version_desc.to_s.split('=')
puts Color.color_text('New Tag Name = ', Color.white) + Color.color_text(new_tag_name.to_s, Color.green)
write_line = "#{version_comes.first}= '#{new_tag_name}'\n"
end
t.write write_line
end
end
end
puts Color.color_text('当前版本号 = ', Color.white) + Color.color_text(last_tag_name, Color.green)
end
unless File.exists? pod_spec_path
puts Color.color_text("Init Spec Repo... ☕️! Current tag = #{last_tag_name}", Color.green)
Git.clone(pod_repo_url, podspec_path, tag: last_tag_name)
end
Dir.chdir(pod_spec_path) do
pod_spec_git = Git.open(pod_spec_path)
specs.each do |spec|
pod_repo_spec_sorce = working_dir + spec + "#{spec}.podspec"
pod_repo_path = pod_spec_path + spec
new_tag_path = pod_repo_path + new_tag_name
FileUtils.mkdir_p(pod_repo_path, mode: 0o755) unless pod_repo_path.exist?
Dir.chdir(pod_repo_path) do
if new_tag_path.exist?
Color.die_log("[!] #{spec}组件#{new_tag_name}版本已存在,请确认后继续执行。")
else
FileUtils.mkdir_p(new_tag_path, mode: 0o755)
end
pod_repo_spec_dest = new_tag_path + "#{spec}.podspec"
if pod_repo_spec_dest.exist?
Color.die_log("[!] #{spec}组件#{new_tag_name}版本 podspec 已存在,请确认后继续执行。")
else
FileUtils.copy_file(pod_repo_spec_sorce, pod_repo_spec_dest)
end
end
end
puts Color.color_text("Start push pod repo to remote repo '#{pod_spec_name}'", Color.white)
pod_spec_git.add
pod_spec_git.commit_all("组件库tag:#{new_tag_name}")
pod_spec_git.push
puts Color.color_text("Update success ☕️! Current version = #{new_tag_name}", Color.green)
end
puts Color.color_text('Start upload source code to remote', Color.white)
pod_source_git.add
pod_source_git.commit("组件库tag:#{new_tag_name}")
pod_source_git.push
pod_source_git.add_tag(new_tag_name)
puts Color.color_text("Update success ☕️! Current version = #{new_tag_name}", Color.green)
end
|