cocoapods-tools 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cocoapods-tools/command/git/component.rb +15 -0
- data/lib/cocoapods-tools/command/git/gt.rb +27 -0
- data/lib/cocoapods-tools/command/git/init.rb +0 -0
- data/lib/cocoapods-tools/command/git/merge.rb +180 -0
- data/lib/cocoapods-tools/command/spec/tag.rb +111 -252
- data/lib/cocoapods-tools/command/spec/tag_sigle.rb +308 -0
- data/lib/cocoapods-tools/command.rb +1 -0
- data/lib/cocoapods-tools/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbf3c000c6d717670638d82e28cfc181c9228b3242301300af3e4ba9f142ad28
|
4
|
+
data.tar.gz: d5f9c0d4bca3e37cd5e8440ac49327b6deaf8e01bdf94164d6cb08249d69a56f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32317ed32996bfe9032242e04bcea0202e80f4be79ed89aa09334349383381f186f35d595ab6af8e671a8360fa0b7ed8dcea9a1ea22183d5b177606f8f06d846
|
7
|
+
data.tar.gz: c263bc69d9c0db096bf53ea627ce94ffd6d989b5ba8b451dea169839bb55c5448f05ec0b01a92825df7508ee60497088466e34efcd049438a3110197a0f19f9d
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CocoapodsTools
|
4
|
+
# 组件类
|
5
|
+
class Component
|
6
|
+
|
7
|
+
attr_accessor :component_name, :component_url, :component_branch
|
8
|
+
|
9
|
+
def initialize(name, url, branch)
|
10
|
+
@component_name = name
|
11
|
+
@component_url = url
|
12
|
+
@component_branch = branch
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cocoapods-tools/helper/color'
|
2
|
+
|
3
|
+
module CocoapodsTools
|
4
|
+
# This command uses an argument for the extra parameter, instead of
|
5
|
+
# subcommands for each of the flavor.
|
6
|
+
class GT < Command
|
7
|
+
|
8
|
+
require 'cocoapods-tools/command/git/merge'
|
9
|
+
|
10
|
+
self.summary = 'cocoapods gt'
|
11
|
+
|
12
|
+
self.description = 'cocoapods gt'
|
13
|
+
|
14
|
+
self.arguments = [
|
15
|
+
CLAide::Argument.new('merge', '1.0')
|
16
|
+
]
|
17
|
+
|
18
|
+
def self.options
|
19
|
+
[%w[merge 自动打合并组件]].concat(super)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(argv)
|
23
|
+
@tag = argv.flag?('merge')
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
File without changes
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'cocoapods-tools/helper/color'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'git'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'cocoapods-tools/command/git/component'
|
6
|
+
|
7
|
+
module CocoapodsTools
|
8
|
+
# This command uses an argument for the extra parameter, instead of
|
9
|
+
# subcommands for each of the flavor
|
10
|
+
class Merge < GT
|
11
|
+
|
12
|
+
self.summary = 'ht git merge'
|
13
|
+
|
14
|
+
self.description = 'ht git merge'
|
15
|
+
|
16
|
+
self.arguments = [
|
17
|
+
# CLAide::Argument.new('TAG_VERSION', false, false),
|
18
|
+
]
|
19
|
+
|
20
|
+
def self.options
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(argv)
|
25
|
+
@arguments = argv.arguments!
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate!
|
30
|
+
super
|
31
|
+
# puts Color.color_text('validate spec', Color.green)
|
32
|
+
help! '输入参数过多' if @arguments.count > 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
super
|
37
|
+
|
38
|
+
return
|
39
|
+
# 1. 初始化
|
40
|
+
# current_branch:当前分支(主工程)。验证是否时最大分支,不是则报错提醒
|
41
|
+
# develop_branch:版本开发主分支
|
42
|
+
# need_merges: 需要手动合并的分支
|
43
|
+
# success_merges: 合并成功的分支
|
44
|
+
# pod_file: 读取 Podfile 文件
|
45
|
+
# change_components: 解析当前分支改动的组件,以当前分支名匹配
|
46
|
+
#
|
47
|
+
# 2. 遍历所有组件,进行合并分支操作
|
48
|
+
# component_dir: 修改工作目录,进入组件文件夹
|
49
|
+
# git reset:根据主工程当前分支,拉取组件远端仓库最新代码
|
50
|
+
# set-upstream-to:关联当前分支与 develop 分支
|
51
|
+
# git merge:检查当前分支与 develop 分支有无变动
|
52
|
+
# 有变动:加入 need_merges
|
53
|
+
# 无变动:合并操作
|
54
|
+
|
55
|
+
# 3. 输出执行结果
|
56
|
+
# ["need_merges": [], "success_merges": []]
|
57
|
+
|
58
|
+
# current_branch:当前分支(主工程)。验证是否时最大分支,不是则报错提醒
|
59
|
+
working_dir = Pathname.pwd
|
60
|
+
g = Git.open(working_dir)
|
61
|
+
current_branch = g.current_branch
|
62
|
+
puts Color.color_text "当前分支: #{current_branch}", Color.red
|
63
|
+
|
64
|
+
# 主业务线分支
|
65
|
+
business_branches = %w[/keep/ /voiceroom/ /live/ /vip/]
|
66
|
+
# 判断当前分支是否为业务线分支
|
67
|
+
is_business_branch = false
|
68
|
+
business_name = ''
|
69
|
+
business_version = ''
|
70
|
+
business_branches.each do |business|
|
71
|
+
next unless current_branch.include?(business)
|
72
|
+
|
73
|
+
business_version = current_branch.split(business).last
|
74
|
+
business_branch = (business_version.gsub '.', '').to_i
|
75
|
+
unless business_branch.is_a?(Numeric)
|
76
|
+
puts Color.color_text '非业务线版本分支,停止合并操作', Color.red
|
77
|
+
return
|
78
|
+
end
|
79
|
+
|
80
|
+
is_business_branch = true
|
81
|
+
business_name = business
|
82
|
+
|
83
|
+
remote_branches = g.branches.remote.select { |bran| bran.name.include? business }
|
84
|
+
remote_branches.each do |bran|
|
85
|
+
version = (bran.name.split(business).last.gsub! '.', '').to_i
|
86
|
+
if version.is_a?(Numeric) && version > business_branch
|
87
|
+
puts Color.color_text '非业务线最新版本分支,停止合并操作', Color.red
|
88
|
+
return
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
break
|
93
|
+
end
|
94
|
+
|
95
|
+
unless is_business_branch
|
96
|
+
puts Color.color_text '非业务线分支,停止合并操作', Color.red
|
97
|
+
return
|
98
|
+
end
|
99
|
+
|
100
|
+
puts Color.color_text "#{business_name.gsub! '/', ''} 业务线最新分支为:#{business_version}", Color.green
|
101
|
+
|
102
|
+
business_version.join('.') unless business_version.include? '.'
|
103
|
+
# 版本开发主分支
|
104
|
+
develop_branch = "develop/#{business_version}"
|
105
|
+
# 需要手动合并的分支
|
106
|
+
need_merges = []
|
107
|
+
# 合并成功的分支
|
108
|
+
success_merges = []
|
109
|
+
# change_components: 解析当前分支改动的组件,以当前分支名匹配
|
110
|
+
change_components = []
|
111
|
+
# 读取 Podfile 文件
|
112
|
+
File.open('Demo/Podfile').each do |line|
|
113
|
+
current_branch_without_dot = current_branch.gsub '.', ''
|
114
|
+
unless !(line.include? '#') && ((line.include? current_branch) || (line.include? current_branch_without_dot))
|
115
|
+
next
|
116
|
+
end
|
117
|
+
|
118
|
+
params = line.split ','
|
119
|
+
name = (params.first.split '\'').last
|
120
|
+
url = (params[1].split '\'').last
|
121
|
+
branch = (params[2].strip.split '\'').last
|
122
|
+
change_components.append(Component.new(name, url, branch))
|
123
|
+
end
|
124
|
+
|
125
|
+
# 测试用例
|
126
|
+
component = Component.new('Test2', 'ssh://git@git', '466')
|
127
|
+
|
128
|
+
# 对所有变动分支进行合并
|
129
|
+
# change_components.each do |component|
|
130
|
+
[component].each do |component|
|
131
|
+
|
132
|
+
# 组件总文件夹
|
133
|
+
component_parent_path = '../iOSLib'
|
134
|
+
FileUtils.makedirs(component_parent_path) unless File.exists? component_parent_path
|
135
|
+
Dir.chdir(component_parent_path) do
|
136
|
+
unless File.exists? component.component_name
|
137
|
+
Git.clone(component.component_url, component.component_name, branch: component.component_branch)
|
138
|
+
end
|
139
|
+
|
140
|
+
Dir.chdir(component.component_name) do
|
141
|
+
component_git = Git.open('./')
|
142
|
+
feature_branch_name = component.component_branch
|
143
|
+
component_git.checkout(feature_branch_name)
|
144
|
+
remote_develop_branch = component_git.branches["origin/#{develop_branch}"]
|
145
|
+
component_git.branch(develop_branch).checkout
|
146
|
+
|
147
|
+
# 每个组件都合并业务线分支和主分支
|
148
|
+
['origin/master', "origin/#{feature_branch_name}"].each do |branch|
|
149
|
+
puts Color.color_text "=======开始合并 #{component.component_name} 组件 #{branch} 分支=======", Color.green
|
150
|
+
merge_result = system("git merge #{branch} -m '合并组件分支'")
|
151
|
+
|
152
|
+
if remote_develop_branch.nil? # 开发分支当前版本不存在
|
153
|
+
system("git push --set-upstream origin #{develop_branch}")
|
154
|
+
puts Color.color_text "#{component.component_name} 组件 #{branch} 分支合并成功!", Color.green
|
155
|
+
success_merges.append("#{component.component_name}-#{branch}")
|
156
|
+
elsif merge_result # 合并成功
|
157
|
+
system("git push origin #{develop_branch}")
|
158
|
+
puts Color.color_text "#{component.component_name} 组件 #{branch} 分支合并成功!", Color.green
|
159
|
+
success_merges.append("#{component.component_name}-#{branch}")
|
160
|
+
else # 存在冲突
|
161
|
+
abort_result = system('git merge --abort')
|
162
|
+
if abort_result
|
163
|
+
puts Color.color_text "#{component.component_name} 组件 #{branch} 分支存在冲突,请手动合并!", Color.red
|
164
|
+
need_merges.append("#{component.component_name}-#{branch}")
|
165
|
+
else
|
166
|
+
puts Color.color_text "#{component.component_name} 组件 #{branch} 无变更,不需要合并!", Color.green
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
puts '==============合并结果=============='
|
174
|
+
puts Color.color_text "合并成功:#{success_merges}", Color.green
|
175
|
+
puts Color.color_text "需要手动合并:#{need_merges}", Color.red
|
176
|
+
puts '==================================='
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'cocoapods-tools/helper/color'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'git'
|
4
|
+
require 'open3'
|
5
|
+
require 'cocoapods-tools/helper/color'
|
3
6
|
|
4
7
|
module CocoapodsTools
|
5
8
|
# This command uses an argument for the extra parameter, instead of
|
@@ -12,7 +15,7 @@ module CocoapodsTools
|
|
12
15
|
self.description = 'cocoapods spec tag'
|
13
16
|
|
14
17
|
self.arguments = [
|
15
|
-
|
18
|
+
CLAide::Argument.new('TAG_VERSION', false, false),
|
16
19
|
]
|
17
20
|
|
18
21
|
def self.options
|
@@ -33,276 +36,132 @@ module CocoapodsTools
|
|
33
36
|
def run
|
34
37
|
super
|
35
38
|
|
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
|
-
serial = $stdin.gets.chomp
|
63
|
-
input_tag = (serial.to_i > pod_specs.count || serial.to_i <= 0)
|
64
|
-
if serial.empty?
|
65
|
-
input_tag = false
|
66
|
-
podspec_path = spec_default
|
67
|
-
elsif input_tag
|
68
|
-
puts "Input serial = #{serial}, it's invalid and you need to input 1~#{pod_specs.count}:"
|
69
|
-
else
|
70
|
-
input_tag = false
|
71
|
-
podspec_path = pod_specs[serial.to_i - 1]
|
72
|
-
end
|
39
|
+
# 工作目录
|
40
|
+
working_dir = Pathname.pwd
|
41
|
+
# pod 私有源库名
|
42
|
+
pod_spec_name = 'libspec'
|
43
|
+
# pod 私有源路径
|
44
|
+
pod_spec_path = Pathname.pwd.parent + pod_spec_name
|
45
|
+
# pod 私有源仓库
|
46
|
+
pod_repo_url = 'ssh://git@htsz.hellotalk.net:7999/~panda/libspec.git'
|
47
|
+
|
48
|
+
# 上传私有索引库
|
49
|
+
# 新 tag
|
50
|
+
new_tag_name = @arguments[0].to_s
|
51
|
+
# 版本号
|
52
|
+
last_tag_name = ''
|
53
|
+
|
54
|
+
# 初始化组件源码 git
|
55
|
+
pod_source_git = Git.open(working_dir)
|
56
|
+
|
57
|
+
# 取最近的 tag 号
|
58
|
+
max_tag_no = -1
|
59
|
+
pod_source_git.tags.each do |tag|
|
60
|
+
tag_name = tag.name
|
61
|
+
tag_no = (tag_name.gsub '.', '').to_i
|
62
|
+
if max_tag_no < tag_no
|
63
|
+
max_tag_no = tag_no
|
64
|
+
last_tag_name = tag_name
|
73
65
|
end
|
74
|
-
elsif pod_specs.count == 1
|
75
|
-
podspec_path = pod_specs.first.split.last
|
76
|
-
else
|
77
|
-
puts color_text("Can't find any podspec file", Color.red)
|
78
|
-
return
|
79
66
|
end
|
80
67
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
cur_version = ''
|
95
|
-
# 读取当前podspec文件的版本
|
96
|
-
File.open(podspec_absolute_path, 'r+') do |f|
|
97
|
-
f.each_line do |line|
|
98
|
-
# 查找.version
|
99
|
-
version_desc = /.*\.version\s*=.*/.match line
|
100
|
-
next if version_desc.nil?
|
101
|
-
|
102
|
-
cur_version = version_desc.to_s.split('=').last.to_s.gsub("'", '')
|
103
|
-
cur_version = cur_version.gsub(' ', '')
|
104
|
-
break
|
105
|
-
end
|
68
|
+
# 上次提交 sha
|
69
|
+
last_commit = pod_source_git.log(1).first
|
70
|
+
# 最近 tag 对应的提交 sha
|
71
|
+
last_tag = pod_source_git.tag(last_tag_name)
|
72
|
+
# 读取两个 sha 间的文件变更
|
73
|
+
changes = `git log --name-only --pretty=oneline --full-index #{last_commit}...#{last_tag} | grep -vE '^[0-9a-f]{40} ' | sort | uniq`
|
74
|
+
puts Color.color_text "===== 与 tag:#{last_tag_name} 对比,所有文件变更如下 ======", Color.green
|
75
|
+
puts changes
|
76
|
+
puts Color.color_text '==================变更文件打印结束=================', Color.green
|
77
|
+
|
78
|
+
specs = []
|
79
|
+
Dir.entries(working_dir).each do |sub|
|
80
|
+
specs.push(sub) if File.directory?(sub) && !sub.include?('.') && changes.include?("#{sub}/#{sub}")
|
106
81
|
end
|
107
82
|
|
108
|
-
puts Color.color_text
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
break
|
128
|
-
elsif input_v_s[v_index].to_i == cur_v_s[v_index].to_i
|
129
|
-
v_index += 1
|
130
|
-
else
|
131
|
-
break
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
puts Color.color_text "版本号 #{input_version} 无效,默认自增", Color.natural if input_valid == false
|
136
|
-
end
|
137
|
-
|
138
|
-
system("touch #{temp_podspec_path}") unless File.exist? temp_podspec_absolute_path
|
139
|
-
|
140
|
-
new_version = ''
|
141
|
-
git_source = ''
|
142
|
-
|
143
|
-
File.open(temp_podspec_absolute_path, 'r+') do |t|
|
144
|
-
File.open(podspec_absolute_path) do |f|
|
145
|
-
f.each_line do |line|
|
146
|
-
# # 查找.version
|
147
|
-
# s.version = "0.0.2"
|
148
|
-
# 需要注意的是,版本号可以是'',也可以是""
|
149
|
-
write_line = line
|
150
|
-
version_desc = /.*\.version\s*=.*/.match line
|
151
|
-
unless version_desc.nil?
|
152
|
-
version_comes = version_desc.to_s.split('=')
|
153
|
-
if (input_valid == true) && (@arguments.count == 1)
|
154
|
-
new_version = input_version.to_s
|
155
|
-
else
|
156
|
-
version_num = version_comes.last.to_s.gsub("'", '').gsub('"', '').gsub(' ', '')
|
157
|
-
v_s = version_num.split('.')
|
158
|
-
# 处理版本号 0.0.1
|
159
|
-
(0...v_s.count).each do |i|
|
160
|
-
new_version += if i == v_s.count - 1
|
161
|
-
(v_s[i].to_i + 1).to_s
|
162
|
-
else
|
163
|
-
"#{v_s[i]}."
|
164
|
-
end
|
165
|
-
end
|
83
|
+
puts Color.color_text "开始更新组件列表:#{specs}", Color.red
|
84
|
+
|
85
|
+
# 更新组件源码版本号
|
86
|
+
specs.each do |spec|
|
87
|
+
# 读取 podspec 文件
|
88
|
+
podspec_path = working_dir + spec + "#{spec}.podspec"
|
89
|
+
# 修改当前podspec文件的版本
|
90
|
+
File.open(podspec_path, 'r+') do |t|
|
91
|
+
File.open(podspec_path) do |f|
|
92
|
+
f.each_line do |line|
|
93
|
+
# 查找.version
|
94
|
+
# s.version = "0.0.2"
|
95
|
+
# 需要注意的是,版本号可以是'',也可以是""
|
96
|
+
write_line = line
|
97
|
+
version_desc = /.*\.version\s*=.*/.match line
|
98
|
+
unless version_desc.nil?
|
99
|
+
version_comes = version_desc.to_s.split('=')
|
100
|
+
puts Color.color_text('New Tag Name = ', Color.white) + Color.color_text(new_tag_name.to_s, Color.green)
|
101
|
+
write_line = "#{version_comes.first}= '#{new_tag_name}'\n"
|
166
102
|
end
|
167
|
-
|
168
|
-
write_line = "#{version_comes.first}= '#{new_version}'\n"
|
103
|
+
t.write write_line
|
169
104
|
end
|
170
|
-
source_desc = /.*\.source\s*=.*/.match line
|
171
|
-
unless source_desc.nil?
|
172
|
-
source_desc = /:git.*,/.match source_desc.to_s
|
173
|
-
source_desc = /'.*'/.match source_desc.to_s
|
174
|
-
git_source = source_desc.to_s.gsub("'", '')
|
175
|
-
puts "git source is #{git_source}"
|
176
|
-
end
|
177
|
-
t.write write_line
|
178
105
|
end
|
179
106
|
end
|
107
|
+
puts Color.color_text('当前版本号 = ', Color.white) + Color.color_text(last_tag_name, Color.green)
|
180
108
|
end
|
181
109
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
# 将新数据反写回到原始podspec中
|
187
|
-
system("cp -f #{temp_podspec_path} #{podspec_path}")
|
188
|
-
system("rm -f #{temp_podspec_path}")
|
189
|
-
|
190
|
-
# pod_repo_name = 'third_specs'
|
191
|
-
# pod_repo_name = ''
|
192
|
-
pod_repo_source = 'ssh://git@office.hellotalk.net:7999/third/third_specs.git'
|
193
|
-
#pod_repo_source = 'ssh://git@172.16.6.10:7999/third/third_specs.git'
|
194
|
-
|
195
|
-
# 处理正式 repo 逻辑,解析当前 repos
|
196
|
-
# pod_repos = `pod repo list`
|
197
|
-
#
|
198
|
-
# # pod_repos = Array.new
|
199
|
-
# # pod_repo = Array.new
|
200
|
-
# curren_pod_name = ''
|
201
|
-
# temp_pod_name = ''
|
202
|
-
# last_line = ''
|
203
|
-
# pod_repos.each_line do |line|
|
204
|
-
# continue if line == '\n'
|
205
|
-
#
|
206
|
-
# line = line.gsub(/\n/, '')
|
207
|
-
#
|
208
|
-
# if line.include?('- Type:')
|
209
|
-
# temp_pod_name = last_line
|
210
|
-
# elsif line.include?('- URL:')
|
211
|
-
# repo_url = line.split('- URL:').last.gsub(/ /, '')
|
212
|
-
# if repo_url == pod_repo_source
|
213
|
-
# pod_repo_name = temp_pod_name
|
214
|
-
# break
|
215
|
-
# end
|
216
|
-
# end
|
217
|
-
# last_line = line
|
218
|
-
# end
|
219
|
-
#
|
220
|
-
# if pod_repo_name == ''
|
221
|
-
pod_repo_name = pod_repo_source.split('/').last.split('.').first
|
222
|
-
# puts Color.color_text("Add pod repo named '#{pod_repo_name}' with source: #{pod_repo_source}", Color.white)
|
223
|
-
# system("pod repo add #{pod_repo_name} #{pod_repo_source}")
|
224
|
-
# end
|
225
|
-
|
226
|
-
# 提交代码到远程仓库
|
227
|
-
puts Color.color_text('Start upload code to remote', Color.white)
|
228
|
-
|
229
|
-
system("git commit -am 'update version to #{new_version}'")
|
230
|
-
Color.die_log('[!] git push code error') if system('git push origin master') == false
|
231
|
-
system("git tag #{new_version}")
|
232
|
-
if system('git push origin --tags') == false
|
233
|
-
Color.die_log('[!] git push tags error')
|
234
|
-
return
|
110
|
+
# 更新组件版本号私有库
|
111
|
+
unless File.exists? pod_spec_path
|
112
|
+
puts Color.color_text("Init Spec Repo... ☕️! Current tag = #{last_tag_name}", Color.green)
|
113
|
+
Git.clone(pod_repo_url, podspec_path, tag: last_tag_name)
|
235
114
|
end
|
236
115
|
|
237
|
-
#
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
116
|
+
# 更新组件版本号私有库
|
117
|
+
Dir.chdir(pod_spec_path) do
|
118
|
+
|
119
|
+
pod_spec_git = Git.open(pod_spec_path)
|
120
|
+
# ruby open 会重置代码,下方操作没必要
|
121
|
+
# pod_spec_git.checkout('master', { f: true })
|
122
|
+
# pod_spec_git.pull
|
123
|
+
|
124
|
+
specs.each do |spec|
|
125
|
+
pod_repo_spec_sorce = working_dir + spec + "#{spec}.podspec"
|
126
|
+
pod_repo_path = pod_spec_path + spec
|
127
|
+
new_tag_path = pod_repo_path + new_tag_name
|
128
|
+
FileUtils.mkdir_p(pod_repo_path, mode: 0o755) unless pod_repo_path.exist?
|
129
|
+
Dir.chdir(pod_repo_path) do
|
130
|
+
if new_tag_path.exist?
|
131
|
+
Color.die_log("[!] #{spec}组件#{new_tag_name}版本已存在,请确认后继续执行。")
|
132
|
+
# 发布时打开
|
133
|
+
# return
|
134
|
+
else
|
135
|
+
FileUtils.mkdir_p(new_tag_path, mode: 0o755)
|
136
|
+
end
|
258
137
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
if system('git push origin --tags') == false
|
268
|
-
Color.die_log('[!] git push tags error')
|
269
|
-
return
|
138
|
+
pod_repo_spec_dest = new_tag_path + "#{spec}.podspec"
|
139
|
+
if pod_repo_spec_dest.exist?
|
140
|
+
Color.die_log("[!] #{spec}组件#{new_tag_name}版本 podspec 已存在,请确认后继续执行。")
|
141
|
+
# 发布时打开
|
142
|
+
# return
|
143
|
+
else
|
144
|
+
FileUtils.copy_file(pod_repo_spec_sorce, pod_repo_spec_dest)
|
145
|
+
end
|
270
146
|
end
|
271
|
-
puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
|
272
|
-
|
273
147
|
end
|
274
148
|
|
149
|
+
# git 提交到私有源
|
150
|
+
puts Color.color_text("Start push pod repo to remote repo '#{pod_spec_name}'", Color.white)
|
151
|
+
pod_spec_git.add
|
152
|
+
pod_spec_git.commit_all("组件库tag:#{new_tag_name}")
|
153
|
+
pod_spec_git.push
|
154
|
+
puts Color.color_text("Update success ☕️! Current version = #{new_tag_name}", Color.green)
|
275
155
|
end
|
276
|
-
end
|
277
|
-
|
278
|
-
# system("pod repo update #{pod_repo_name}") unless specs_dir.exist?
|
279
|
-
# FileUtils.mkdir_p(specs_dir) unless specs_dir.exist?
|
280
|
-
|
281
|
-
# 验证podspec格式是否正确
|
282
|
-
# if verify_podspec_format == true
|
283
|
-
# puts Color.color_text("Start verify podspec '#{podspec_path}'...", Color.white)
|
284
|
-
# if system("pod lib lint #{podspec_path} --allow-warnings") == false
|
285
|
-
# die_log("[!] pod spec' format invalid")
|
286
|
-
# return
|
287
|
-
# end
|
288
|
-
# end
|
289
156
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
# puts "If not timeout, you need to check your 'trunk' account like: 'pod trunk me', and register code is 'pod trunk register <your email> <your name>'"
|
298
|
-
# return
|
299
|
-
# end
|
300
|
-
# else
|
301
|
-
# if (is_static_lib == true ? system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings --use-libraries") : system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings")) == false
|
302
|
-
# return
|
303
|
-
# end
|
304
|
-
# end
|
305
|
-
#
|
157
|
+
# 提交组件代码到远程仓库
|
158
|
+
puts Color.color_text('Start upload source code to remote', Color.white)
|
159
|
+
pod_source_git.add
|
160
|
+
pod_source_git.commit("组件库tag:#{new_tag_name}")
|
161
|
+
pod_source_git.push
|
162
|
+
pod_source_git.add_tag(new_tag_name)
|
163
|
+
puts Color.color_text("Update success ☕️! Current version = #{new_tag_name}", Color.green)
|
306
164
|
|
165
|
+
end
|
307
166
|
end
|
308
167
|
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
require 'cocoapods-tools/helper/color'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module CocoapodsTools
|
5
|
+
# This command uses an argument for the extra parameter, instead of
|
6
|
+
# subcommands for each of the flavor.
|
7
|
+
|
8
|
+
class Tag < Spec
|
9
|
+
|
10
|
+
self.summary = 'cocoapods spec tag'
|
11
|
+
|
12
|
+
self.description = 'cocoapods spec tag'
|
13
|
+
|
14
|
+
self.arguments = [
|
15
|
+
# CLAide::Argument.new('TAG_VERSION', false, false),
|
16
|
+
]
|
17
|
+
|
18
|
+
def self.options
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(argv)
|
23
|
+
@arguments = argv.arguments!
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate!
|
28
|
+
super
|
29
|
+
# puts Color.color_text('validate spec', Color.green)
|
30
|
+
help! '输入参数过多' if @arguments.count > 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
super
|
35
|
+
|
36
|
+
# 搜索podspec路径
|
37
|
+
podspec_path = ''
|
38
|
+
find_podspec_path = Pathname.pwd
|
39
|
+
|
40
|
+
# 有可能存在多个 podspec,当用户没有指定时,需要给用户自主选择
|
41
|
+
pod_specs = find_podspec_path.children.select { |pn| pn.extname == '.podspec' }
|
42
|
+
example_path = Pathname.new("#{find_podspec_path}/Example").expand_path
|
43
|
+
project_path = example_path.children.select { |pn| pn.extname == '.xcodeproj' }.first
|
44
|
+
project_name = File.basename(project_path, '.*')
|
45
|
+
default_name = "#{project_name}.podspec"
|
46
|
+
podspec_path = default_name
|
47
|
+
|
48
|
+
# 默认为工程名同名的 spec
|
49
|
+
# default_name = "#{project_name}.podspec"
|
50
|
+
# spec_default = pod_specs.select { |path| path.basename.to_s == default_name }.first
|
51
|
+
spec_default = "#{project_name}.podspec"
|
52
|
+
|
53
|
+
if pod_specs.count > 1
|
54
|
+
input_tag = true
|
55
|
+
serial = 0
|
56
|
+
puts Color.color_text(
|
57
|
+
"Find #{pod_specs.count} podspec files, please enter the serial number selection:\n(default:#{spec_default})", Color.white)
|
58
|
+
while input_tag
|
59
|
+
(0...pod_specs.count).each do |i|
|
60
|
+
puts "#{i + 1}. #{pod_specs[i]}"
|
61
|
+
end
|
62
|
+
serial = $stdin.gets.chomp
|
63
|
+
input_tag = (serial.to_i > pod_specs.count || serial.to_i <= 0)
|
64
|
+
if serial.empty?
|
65
|
+
input_tag = false
|
66
|
+
podspec_path = spec_default
|
67
|
+
elsif input_tag
|
68
|
+
puts "Input serial = #{serial}, it's invalid and you need to input 1~#{pod_specs.count}:"
|
69
|
+
else
|
70
|
+
input_tag = false
|
71
|
+
podspec_path = pod_specs[serial.to_i - 1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
elsif pod_specs.count == 1
|
75
|
+
podspec_path = pod_specs.first.split.last
|
76
|
+
else
|
77
|
+
puts Color.color_text("Can't find any podspec file", Color.red)
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
if !File.exist?(podspec_path)
|
82
|
+
puts ("找不到 podspec 文件: #{podspec_path}, 请确认当前路径")
|
83
|
+
return
|
84
|
+
else
|
85
|
+
puts "Ready to deal with podspec named #{Color.color_text(podspec_path.to_s, Color.white)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# 在当前podspec目录下新建一个临时 need_delete_temp.podspec 文件
|
89
|
+
podspec_dir = File.dirname podspec_path
|
90
|
+
podspec_absolute_path = "#{find_podspec_path}/#{podspec_path}"
|
91
|
+
temp_podspec_path = "#{podspec_dir}/need_delete_temp.podspec"
|
92
|
+
temp_podspec_absolute_path = "#{find_podspec_path}/#{temp_podspec_path}"
|
93
|
+
|
94
|
+
cur_version = ''
|
95
|
+
# 读取当前podspec文件的版本
|
96
|
+
File.open(podspec_path, 'r+') do |f|
|
97
|
+
f.each_line do |line|
|
98
|
+
# 查找.version
|
99
|
+
version_desc = /.*\.version\s*=.*/.match line
|
100
|
+
next if version_desc.nil?
|
101
|
+
|
102
|
+
cur_version = version_desc.to_s.split('=').last.to_s.gsub("'", '')
|
103
|
+
cur_version = cur_version.gsub(' ', '')
|
104
|
+
break
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
puts Color.color_text('Current version = ', Color.white) + Color.color_text(cur_version.to_s, Color.green)
|
109
|
+
|
110
|
+
# 自定义版本号
|
111
|
+
if @arguments.count == 1
|
112
|
+
|
113
|
+
input_version = @arguments.first
|
114
|
+
puts Color.color_text "不输入时默认自增。本次已输入,版本号:#{input_version}", Color.white
|
115
|
+
|
116
|
+
# 判断输入的version是否>当前的版本号
|
117
|
+
input_v_s = input_version.to_s.split('.')
|
118
|
+
cur_v_s = cur_version.split('.')
|
119
|
+
# 比较的位置,从最左边开始
|
120
|
+
v_index = 0
|
121
|
+
# 输入的version是否有效
|
122
|
+
input_valid = false
|
123
|
+
while v_index < cur_v_s.count && v_index < input_v_s.count do
|
124
|
+
if input_v_s[v_index].to_i > cur_v_s[v_index].to_i
|
125
|
+
# 说明用户输入的version比当前的大
|
126
|
+
input_valid = true
|
127
|
+
break
|
128
|
+
elsif input_v_s[v_index].to_i == cur_v_s[v_index].to_i
|
129
|
+
v_index += 1
|
130
|
+
else
|
131
|
+
break
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
puts Color.color_text "版本号 #{input_version} 无效,默认自增", Color.natural if input_valid == false
|
136
|
+
end
|
137
|
+
|
138
|
+
system("touch #{temp_podspec_path}") unless File.exist? temp_podspec_absolute_path
|
139
|
+
|
140
|
+
new_version = ''
|
141
|
+
git_source = ''
|
142
|
+
|
143
|
+
File.open(podspec_path, 'r+') do |t|
|
144
|
+
File.open(podspec_path) do |f|
|
145
|
+
f.each_line do |line|
|
146
|
+
# # 查找.version
|
147
|
+
# s.version = "0.0.2"
|
148
|
+
# 需要注意的是,版本号可以是'',也可以是""
|
149
|
+
write_line = line
|
150
|
+
version_desc = /.*\.version\s*=.*/.match line
|
151
|
+
unless version_desc.nil?
|
152
|
+
version_comes = version_desc.to_s.split('=')
|
153
|
+
if (input_valid == true) && (@arguments.count == 1)
|
154
|
+
new_version = input_version.to_s
|
155
|
+
else
|
156
|
+
version_num = version_comes.last.to_s.gsub("'", '').gsub('"', '').gsub(' ', '')
|
157
|
+
v_s = version_num.split('.')
|
158
|
+
# 处理版本号 0.0.1
|
159
|
+
(0...v_s.count).each do |i|
|
160
|
+
new_version += if i == v_s.count - 1
|
161
|
+
(v_s[i].to_i + 1).to_s
|
162
|
+
else
|
163
|
+
"#{v_s[i]}."
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
puts Color.color_text('New version = ', Color.white) + Color.color_text(new_version.to_s, Color.green)
|
168
|
+
write_line = "#{version_comes.first}= '#{new_version}'\n"
|
169
|
+
end
|
170
|
+
source_desc = /.*\.source\s*=.*/.match line
|
171
|
+
unless source_desc.nil?
|
172
|
+
source_desc = /:git.*,/.match source_desc.to_s
|
173
|
+
source_desc = /'.*'/.match source_desc.to_s
|
174
|
+
git_source = source_desc.to_s.gsub("'", '')
|
175
|
+
puts "git source is #{git_source}"
|
176
|
+
end
|
177
|
+
t.write write_line
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
puts Color.color_text('Update version from ',
|
183
|
+
Color.white) + Color.color_text(cur_version.to_s,
|
184
|
+
Color.green) + Color.color_text(' to ', Color.white) + Color.color_text(new_version.to_s, Color.green)
|
185
|
+
|
186
|
+
# 将新数据反写回到原始podspec中
|
187
|
+
system("cp -f #{temp_podspec_path} #{podspec_path}")
|
188
|
+
system("rm -f #{temp_podspec_path}")
|
189
|
+
|
190
|
+
# pod_repo_name = 'third_specs'
|
191
|
+
# pod_repo_name = ''
|
192
|
+
pod_repo_source = 'ssh://git@office.hellotalk.net:7999/third/third_specs.git'
|
193
|
+
#pod_repo_source = 'ssh://git@172.16.6.10:7999/third/third_specs.git'
|
194
|
+
|
195
|
+
# 处理正式 repo 逻辑,解析当前 repos
|
196
|
+
# pod_repos = `pod repo list`
|
197
|
+
#
|
198
|
+
# # pod_repos = Array.new
|
199
|
+
# # pod_repo = Array.new
|
200
|
+
# curren_pod_name = ''
|
201
|
+
# temp_pod_name = ''
|
202
|
+
# last_line = ''
|
203
|
+
# pod_repos.each_line do |line|
|
204
|
+
# continue if line == '\n'
|
205
|
+
#
|
206
|
+
# line = line.gsub(/\n/, '')
|
207
|
+
#
|
208
|
+
# if line.include?('- Type:')
|
209
|
+
# temp_pod_name = last_line
|
210
|
+
# elsif line.include?('- URL:')
|
211
|
+
# repo_url = line.split('- URL:').last.gsub(/ /, '')
|
212
|
+
# if repo_url == pod_repo_source
|
213
|
+
# pod_repo_name = temp_pod_name
|
214
|
+
# break
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# last_line = line
|
218
|
+
# end
|
219
|
+
#
|
220
|
+
# if pod_repo_name == ''
|
221
|
+
pod_repo_name = pod_repo_source.split('/').last.split('.').first
|
222
|
+
# puts Color.color_text("Add pod repo named '#{pod_repo_name}' with source: #{pod_repo_source}", Color.white)
|
223
|
+
# system("pod repo add #{pod_repo_name} #{pod_repo_source}")
|
224
|
+
# end
|
225
|
+
|
226
|
+
# 提交代码到远程仓库
|
227
|
+
puts Color.color_text('Start upload code to remote', Color.white)
|
228
|
+
|
229
|
+
system("git commit -am 'update version to #{new_version}'")
|
230
|
+
Color.die_log('[!] git push code error') if system('git push origin master') == false
|
231
|
+
system("git tag #{new_version}")
|
232
|
+
if system('git push origin --tags') == false
|
233
|
+
Color.die_log('[!] git push tags error')
|
234
|
+
return
|
235
|
+
end
|
236
|
+
|
237
|
+
# 获取当前 repo 缓存路径,建立新版本 spec 的文件夹
|
238
|
+
home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
|
239
|
+
specs_git_syn = Pathname.new("#{home_dir}/specs_git_syn").expand_path
|
240
|
+
FileUtils.mkdir_p(specs_git_syn) unless specs_git_syn.exist?
|
241
|
+
|
242
|
+
pod_spec_dir = Pathname.new("#{specs_git_syn}/#{pod_repo_name}").expand_path
|
243
|
+
|
244
|
+
Dir.chdir(specs_git_syn) do
|
245
|
+
# 同步文件夹中,没有当前源则克隆
|
246
|
+
|
247
|
+
system("git clone #{pod_repo_source} #{pod_spec_dir}") unless pod_spec_dir.exist?
|
248
|
+
|
249
|
+
pod_repo_dir = Pathname.new("#{pod_spec_dir}/#{project_name}").expand_path
|
250
|
+
|
251
|
+
# 添加最新版本文件夹
|
252
|
+
version_dir = Pathname.new("#{pod_repo_dir}/#{new_version.to_s}").expand_path
|
253
|
+
FileUtils.mkdir_p(version_dir, mode: 0o755)
|
254
|
+
|
255
|
+
# 将修改版本号的 spec 文件拷贝进去
|
256
|
+
spec_repo_path = Pathname.new("#{version_dir}/#{podspec_path}").expand_path
|
257
|
+
system("cp -f #{podspec_absolute_path} #{spec_repo_path}")
|
258
|
+
|
259
|
+
# 进入当前源对应的同步文件夹
|
260
|
+
Dir.chdir(pod_spec_dir) do
|
261
|
+
# git 提交到私有源
|
262
|
+
puts Color.color_text("Start push pod '#{pod_spec_dir}' to remote repo '#{pod_repo_name}'", Color.white)
|
263
|
+
system('git add .')
|
264
|
+
system("git commit -am 'update version to #{new_version}'")
|
265
|
+
Color.die_log('[!] git push code error') if system('git push origin master') == false
|
266
|
+
system("git tag #{new_version}")
|
267
|
+
if system('git push origin --tags') == false
|
268
|
+
Color.die_log('[!] git push tags error')
|
269
|
+
return
|
270
|
+
end
|
271
|
+
puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# system("pod repo update #{pod_repo_name}") unless specs_dir.exist?
|
279
|
+
# FileUtils.mkdir_p(specs_dir) unless specs_dir.exist?
|
280
|
+
|
281
|
+
# 验证podspec格式是否正确
|
282
|
+
# if verify_podspec_format == true
|
283
|
+
# puts Color.color_text("Start verify podspec '#{podspec_path}'...", Color.white)
|
284
|
+
# if system("pod lib lint #{podspec_path} --allow-warnings") == false
|
285
|
+
# die_log("[!] pod spec' format invalid")
|
286
|
+
# return
|
287
|
+
# end
|
288
|
+
# end
|
289
|
+
|
290
|
+
# 提交pod spec到spec仓库
|
291
|
+
# puts Color.color_text("Start push pod '#{podspec_path}' to remote repo '#{pod_repo_name}'", Color.white)
|
292
|
+
# system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings")
|
293
|
+
# puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
|
294
|
+
|
295
|
+
# if pod_repo_name == 'trunk'
|
296
|
+
# if (is_static_lib == true ? system("pod trunk push #{podspec_path} --allow-warnings --use-libraries") : system("pod trunk push #{podspec_path} --allow-warnings")) == false
|
297
|
+
# puts "If not timeout, you need to check your 'trunk' account like: 'pod trunk me', and register code is 'pod trunk register <your email> <your name>'"
|
298
|
+
# return
|
299
|
+
# end
|
300
|
+
# else
|
301
|
+
# if (is_static_lib == true ? system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings --use-libraries") : system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings")) == false
|
302
|
+
# return
|
303
|
+
# end
|
304
|
+
# end
|
305
|
+
#
|
306
|
+
|
307
|
+
end
|
308
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pandaleecn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03
|
11
|
+
date: 2022-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: claide
|
@@ -35,9 +35,14 @@ files:
|
|
35
35
|
- bin/ht
|
36
36
|
- lib/cocoapods-tools.rb
|
37
37
|
- lib/cocoapods-tools/command.rb
|
38
|
+
- lib/cocoapods-tools/command/git/component.rb
|
39
|
+
- lib/cocoapods-tools/command/git/gt.rb
|
40
|
+
- lib/cocoapods-tools/command/git/init.rb
|
41
|
+
- lib/cocoapods-tools/command/git/merge.rb
|
38
42
|
- lib/cocoapods-tools/command/spec/init.rb
|
39
43
|
- lib/cocoapods-tools/command/spec/spec.rb
|
40
44
|
- lib/cocoapods-tools/command/spec/tag.rb
|
45
|
+
- lib/cocoapods-tools/command/spec/tag_sigle.rb
|
41
46
|
- lib/cocoapods-tools/helper/color.rb
|
42
47
|
- lib/cocoapods-tools/version.rb
|
43
48
|
homepage: https://github.com/pandaleecn/cocoapods-tools
|