gct 0.4.1 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gct.rb +4 -0
- data/lib/gct/command/autotag.rb +127 -84
- data/lib/gct/command/init/gitlab-ci.rb +4 -6
- data/lib/gct/command/repo/push.rb +2 -2
- data/lib/gct/command/robot.rb +1 -0
- data/lib/gct/command/robot/summary.rb +34 -0
- data/lib/gct/command/spec/lint.rb +2 -2
- data/lib/gct/command/update/dependency.rb +12 -5
- data/lib/gct/command/update/next.rb +34 -40
- data/lib/gct/command/update/podfile.rb +40 -35
- data/lib/gct/command/update/tag.rb +77 -19
- data/lib/gct/constant.rb +15 -3
- data/lib/gct/database/data.rb +28 -0
- data/lib/gct/file_base.rb +0 -45
- data/lib/gct/gct_version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c891620cdbf1ca7ebfbfea728c7119c50bdf57681153578179651c3dd5b92de
|
4
|
+
data.tar.gz: a141431922d4a1d38fc8a7feb9702da7023524eac255dde2e3433c97dd5b1b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 924af3952e8779c161663672988ed5b590841f5e9c4dca9d1c1acccd8d578a3d18ffd39f100e8539d980d7ce5b30145bf616d2fc159ab9d48cc1673ce674a8dc
|
7
|
+
data.tar.gz: 8e103f59abf58ea19c52628b947827a3b74e86aaafa7cdd42c4ab310a75b189f0530253fe1ea4106a7ab8758a5bdb50de683c76813f116c3d414e71b948e5515
|
data/lib/gct.rb
CHANGED
data/lib/gct/command/autotag.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'tmpdir'
|
3
3
|
require 'parallel'
|
4
|
+
require 'pp'
|
4
5
|
|
5
6
|
module Gct
|
6
7
|
class Command
|
@@ -20,6 +21,7 @@ module Gct
|
|
20
21
|
gitlab_error
|
21
22
|
config_gitlab
|
22
23
|
@update_ci = argv.flag?('update-ci', false)
|
24
|
+
@pre = argv.flag?('pre', false)
|
23
25
|
name = argv.shift_argument
|
24
26
|
@project_id = "ios/#{name}"
|
25
27
|
@project_name = name
|
@@ -31,7 +33,8 @@ module Gct
|
|
31
33
|
|
32
34
|
def self.options
|
33
35
|
[
|
34
|
-
['--update-ci', '是否更新CI']
|
36
|
+
['--update-ci', '是否更新CI'],
|
37
|
+
['--pre', '是否为预发tag'],
|
35
38
|
].concat(super)
|
36
39
|
end
|
37
40
|
|
@@ -46,17 +49,32 @@ module Gct
|
|
46
49
|
FileBase.root_err
|
47
50
|
puts "开始分析podfile文件".green
|
48
51
|
puts ""
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
where_statement = "and is_pre = #{@pre ? 1 : 0}"
|
53
|
+
p_db = Database::Data.new
|
54
|
+
p_sql = "select * from project where version = '#{@version}' #{where_statement}"
|
55
|
+
p_res = p_db.query(p_sql)
|
56
|
+
|
57
|
+
if !p_res.nil? && p_res.count > 0
|
58
|
+
res_first = nil
|
59
|
+
p_res.each do |row|
|
60
|
+
res_first = row
|
61
|
+
break
|
62
|
+
end
|
63
|
+
if res_first["is_done"].to_i == 0
|
64
|
+
tmp_podspecs
|
65
|
+
create_tag_by_priority()
|
66
|
+
else
|
67
|
+
raise "#{@project_name} #{@version} 版本已经打完tag了!!!".red
|
68
|
+
end
|
55
69
|
else
|
70
|
+
keys = "(version, name, branch" + (@pre ? ", is_pre)" : ")")
|
71
|
+
values = "('#{@version}', '#{@project_name}', '#{@branch}'" + (@pre ? ", 1)" : ")")
|
72
|
+
db = Database::Data.new
|
73
|
+
sql = "insert into project #{keys} values #{values}"
|
74
|
+
res = db.query(sql)
|
56
75
|
untagged_specs = analyze_dependencies
|
57
|
-
|
58
|
-
|
59
|
-
create_tag_by_priority(priority_map)
|
76
|
+
priority_rank(untagged_specs)
|
77
|
+
create_tag_by_priority()
|
60
78
|
end
|
61
79
|
end
|
62
80
|
|
@@ -66,34 +84,76 @@ module Gct
|
|
66
84
|
end
|
67
85
|
|
68
86
|
def podfile
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
80
|
-
podfile
|
81
|
-
end
|
82
|
-
# end
|
87
|
+
contents = file_contents(@project_id, @file, @branch)
|
88
|
+
contents.force_encoding('UTF-8')
|
89
|
+
temp_local_file = TempLocalFile.new(contents, @file)
|
90
|
+
temp_local_file.write
|
91
|
+
full_path = temp_local_file.full_path
|
92
|
+
|
93
|
+
@podfile ||= begin
|
94
|
+
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
95
|
+
podfile
|
96
|
+
end
|
83
97
|
end
|
84
98
|
|
85
99
|
def tmp_podspecs
|
86
|
-
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.
|
100
|
+
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagFromBranch}
|
101
|
+
raise "没有需要打tag的库".red if untagged_git_dependencies.count == 0
|
87
102
|
|
88
103
|
spec_files = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
|
104
|
+
project_name = "#{Constant.NameSpace}#{dep.name}"
|
105
|
+
branch = Constant.DefaultTagFromBranch
|
106
|
+
if @pre
|
107
|
+
branch = Constant.PreTagFromBranch
|
108
|
+
create_pre_branch(branch, project_name)
|
109
|
+
end
|
89
110
|
file_name = "#{dep.name}.podspec"
|
90
|
-
podspec_contents = file_contents(
|
111
|
+
podspec_contents = file_contents(project_name, file_name, branch)
|
91
112
|
temp_local_spec_file = TempLocalFile.new(podspec_contents, file_name)
|
92
113
|
temp_local_spec_file.write
|
93
|
-
temp_local_spec_file.full_path
|
114
|
+
path = temp_local_spec_file.full_path
|
115
|
+
spec = Pod::Specification.from_file(path)
|
116
|
+
remove_tag(auto_add_tag(spec.version.to_s), project_name)
|
117
|
+
path
|
94
118
|
end
|
95
119
|
spec_files
|
96
120
|
end
|
121
|
+
|
122
|
+
def create_pre_branch(branch, project_name)
|
123
|
+
puts "正在创建#{project_name}预发分支!".green
|
124
|
+
bs = Gitlab.branches(project_name)
|
125
|
+
to_b = Constant.DefaultTagToBranch
|
126
|
+
pre_to_b = Constant.PreTagToBranch
|
127
|
+
from_b = Constant.DefaultTagFromBranch
|
128
|
+
bs.each do |b|
|
129
|
+
if b["name"].eql?(branch)
|
130
|
+
Gitlab.delete_branch(project_name, branch)
|
131
|
+
end
|
132
|
+
if b["name"].eql?(pre_to_b)
|
133
|
+
Gitlab.delete_branch(project_name, pre_to_b)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
Gitlab.create_branch(project_name, branch, from_b)
|
137
|
+
Gitlab.create_branch(project_name, pre_to_b, to_b)
|
138
|
+
end
|
139
|
+
|
140
|
+
def remove_tag(tag, name)
|
141
|
+
# 判断是否有这个tag
|
142
|
+
tag = "#{tag}#{Constant.PreHuffix}"
|
143
|
+
command = `git rev-parse --is-inside-work-tree`
|
144
|
+
if command.eql?("true")
|
145
|
+
`git tag -d #{tag}`
|
146
|
+
`git push origin :refs/tags/#{tag}`
|
147
|
+
else
|
148
|
+
tags = Gitlab.tags("#{name}")
|
149
|
+
tags.each do |t|
|
150
|
+
if t["name"].eql?("#{tag}")
|
151
|
+
Gitlab.delete_tag("#{name}", "#{tag}")
|
152
|
+
break
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
97
157
|
|
98
158
|
def analyze_dependencies
|
99
159
|
untagged_specs = tmp_podspecs.map do |spec_file|
|
@@ -172,72 +232,55 @@ module Gct
|
|
172
232
|
end
|
173
233
|
end
|
174
234
|
end
|
175
|
-
|
176
|
-
|
235
|
+
|
236
|
+
values = ""
|
177
237
|
temp_spec_map.each do |key, value|
|
178
|
-
|
238
|
+
values.concat("('#{@version}', '#{key}', '#{@project_name}', '#{value.tag}', '#{value.status}', #{value.priority}" + (@pre ? ", 1)," : "),"))
|
179
239
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
tmp_hash.store(key, {"tag" => value["tag"], "status" => value["status"]})
|
186
|
-
dependency_map.delete(value)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
if (tmp_hash.keys.count == 0)
|
190
|
-
priority = 1001
|
191
|
-
else
|
192
|
-
priority_map[priority.to_s] = tmp_hash
|
193
|
-
priority -= 1
|
194
|
-
end
|
195
|
-
end
|
196
|
-
priority_map
|
197
|
-
end
|
198
|
-
|
199
|
-
def generate_dependency_file(priority_map)
|
200
|
-
yaml_path = "#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
|
201
|
-
FileBase.yaml_write_map(yaml_path, priority_map)
|
240
|
+
val = values[0, values.length - 1]
|
241
|
+
keys = "(project_version, pod_name, project_name, tag_version, tag_status, priority" + (@pre ? ", is_pre)" : ")")
|
242
|
+
sql = "insert into tag #{keys} values #{val}"
|
243
|
+
db = Database::Data.new
|
244
|
+
db.query(sql)
|
202
245
|
end
|
203
246
|
|
204
247
|
# 按优先级打tag, 触发第一个优先级,其他的上一优先级打完之后自动触发
|
205
|
-
def create_tag_by_priority(
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
if !v["status"].eql?(SpecPublishStatus::SUCCESS)
|
231
|
-
is_all_done = false
|
232
|
-
break
|
248
|
+
def create_tag_by_priority()
|
249
|
+
db = Database::Data.new
|
250
|
+
# 查询优先级最高的为完成打tag的数据
|
251
|
+
where_statement = "and is_pre = " + (@pre ? "1" : "0")
|
252
|
+
sql = "select * from tag where priority = (select MAX(priority) from tag where project_version = '#{@version}' and tag_status != '#{SpecPublishStatus::SUCCESS}' #{where_statement})"
|
253
|
+
result = db.query(sql)
|
254
|
+
vals = ""
|
255
|
+
ins = ""
|
256
|
+
if !result.nil? && result.count > 0
|
257
|
+
result.each do |row|
|
258
|
+
if row["tag_status"].eql?(SpecPublishStatus::WAITING) || row["tag_status"].eql?(SpecPublishStatus::CANCELED) || row["tag_status"].eql?(SpecPublishStatus::FAILED)
|
259
|
+
status = SpecPublishStatus::PENDING
|
260
|
+
name = row["pod_name"]
|
261
|
+
vals.concat("when pod_name = '#{name}' then '#{status}' ")
|
262
|
+
ins.concat("'#{name}',")
|
263
|
+
system "gct update dependency #{name} tag_status #{status}"
|
264
|
+
skip_tag = ""
|
265
|
+
if row["is_tag"].to_i == 1
|
266
|
+
skip_tag = "--skip-tag"
|
267
|
+
end
|
268
|
+
pre = ""
|
269
|
+
if row["is_pre"].to_i == 1
|
270
|
+
pre = "--pre"
|
271
|
+
end
|
272
|
+
system "gct update tag #{name} --auto-tag --update-ci #{skip_tag} #{pre}"
|
233
273
|
end
|
234
274
|
end
|
235
|
-
|
236
|
-
|
237
|
-
|
275
|
+
f_ins = ins[0, ins.length - 1]
|
276
|
+
sql = "update tag set tag_status = (
|
277
|
+
case
|
278
|
+
#{vals}
|
238
279
|
end
|
280
|
+
) where pod_name in (#{f_ins}) and project_version = '#{@version}'"
|
281
|
+
update_db = Database::Data.new
|
282
|
+
update_db.query(sql)
|
239
283
|
end
|
240
|
-
priority
|
241
284
|
end
|
242
285
|
end
|
243
286
|
end
|
@@ -5,14 +5,12 @@ stages:
|
|
5
5
|
push_pod:
|
6
6
|
stage: push
|
7
7
|
script:
|
8
|
-
- gct robot start --test
|
9
8
|
- echo "开始lint 和 push podspec"
|
10
|
-
- gct update dependency $CI_PROJECT_NAME "
|
9
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "deploying"
|
11
10
|
- gct clean lint $CI_PROJECT_NAME
|
12
11
|
- gct repo update
|
13
12
|
- gct repo push
|
14
|
-
- gct
|
15
|
-
- gct update dependency $CI_PROJECT_NAME "tag" $CI_COMMIT_REF_NAME
|
13
|
+
- gct update dependency $CI_PROJECT_NAME "tag_version" $CI_COMMIT_REF_NAME
|
16
14
|
- gct update next
|
17
15
|
only:
|
18
16
|
- tags
|
@@ -22,8 +20,8 @@ push_pod:
|
|
22
20
|
on_failure:
|
23
21
|
stage: failure
|
24
22
|
script:
|
25
|
-
- gct robot finish false
|
26
|
-
- gct update dependency $CI_PROJECT_NAME "
|
23
|
+
- gct robot finish false
|
24
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "failed"
|
27
25
|
when: on_failure
|
28
26
|
only:
|
29
27
|
- tags
|
@@ -24,9 +24,9 @@ module Gct
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def pushRepo
|
27
|
-
puts "pod 命令为:pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings".green
|
27
|
+
puts "pod 命令为:pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings --use-modular-headers".green
|
28
28
|
# exception: ruby 2.6 以上生效
|
29
|
-
system "pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings", exception: true
|
29
|
+
system "pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings --use-modular-headers", exception: true
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/gct/command/robot.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Gct
|
5
|
+
class Command
|
6
|
+
class Robot < Command
|
7
|
+
class Summary < Robot
|
8
|
+
|
9
|
+
self.summary = '汇总'
|
10
|
+
self.description = <<-DESC
|
11
|
+
汇总
|
12
|
+
DESC
|
13
|
+
|
14
|
+
self.arguments = [
|
15
|
+
]
|
16
|
+
|
17
|
+
def self.options
|
18
|
+
[
|
19
|
+
['--test', '测试机器人,测试webhook'],
|
20
|
+
].concat(super)
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(argv)
|
24
|
+
@test = argv.flag?('test', false)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -22,8 +22,8 @@ module Gct
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def run
|
25
|
-
system "pod lib lint --sources=#{Constant.GitURL}iOSCRGTPodSource.git --allow-warnings --verbose --skip-import-validation --use-libraries", exception: true
|
26
|
-
|
25
|
+
# system "pod lib lint --sources=#{Constant.GitURL}iOSCRGTPodSource.git --allow-warnings --verbose --skip-import-validation --use-libraries", exception: true
|
26
|
+
lint_spec
|
27
27
|
end
|
28
28
|
|
29
29
|
def generate_podfile(pod_name, spec_path)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'mysql2'
|
1
2
|
module Gct
|
2
3
|
class Command
|
3
4
|
class Update < Command
|
@@ -9,16 +10,14 @@ module Gct
|
|
9
10
|
DESC
|
10
11
|
|
11
12
|
self.arguments = [
|
12
|
-
# CLAide::Argument.new('PRIORITY', false),
|
13
13
|
CLAide::Argument.new('POD_NAME', false),
|
14
|
-
CLAide::Argument.new('
|
14
|
+
CLAide::Argument.new('FIELD', false),
|
15
15
|
CLAide::Argument.new('VALUE', false),
|
16
16
|
]
|
17
17
|
|
18
18
|
def initialize(argv)
|
19
|
-
# @priority = argv.shift_argument
|
20
19
|
@pod_name = argv.shift_argument
|
21
|
-
@
|
20
|
+
@field = argv.shift_argument
|
22
21
|
@value = argv.shift_argument
|
23
22
|
super
|
24
23
|
end
|
@@ -28,7 +27,15 @@ module Gct
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def run
|
31
|
-
|
30
|
+
db = Database::Data.new
|
31
|
+
set_val = ""
|
32
|
+
if (@field.eql?("tag_version"))
|
33
|
+
set_val = "t.#{@field} = '#{@value}', t.tag_status = '#{SpecPublishStatus::SUCCESS}'"
|
34
|
+
else
|
35
|
+
set_val = "t.#{@field} = '#{@value}'"
|
36
|
+
end
|
37
|
+
sql = "update tag t left join project p on t.project_version = p.version set #{set_val} where t.pod_name = '#{@pod_name}' and p.is_done = 0"
|
38
|
+
db.query(sql)
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -14,58 +14,52 @@ module Gct
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def run
|
17
|
-
|
17
|
+
db = Database::Data.new
|
18
|
+
sql = "select * from project where is_done = 0 limit 1"
|
19
|
+
res = db.query(sql)
|
20
|
+
if !res.nil? && res.count > 0
|
21
|
+
res.each do |row|
|
22
|
+
@project_name = row["name"]
|
23
|
+
@branch = row["branch"]
|
24
|
+
@version = row["version"]
|
25
|
+
puts "pre is #{row["is_pre"].to_i == 1}"
|
26
|
+
@pre = row["is_pre"].to_i == 1
|
27
|
+
break
|
28
|
+
end
|
29
|
+
batch_tag
|
30
|
+
end
|
18
31
|
end
|
19
32
|
|
20
33
|
def batch_tag
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
db = Database::Data.new
|
35
|
+
# 查询优先级最高的为完成打tag的数据
|
36
|
+
where_statement = "and is_pre = " + (@pre ? "1" : "0")
|
37
|
+
sql = "select * from tag where priority = (select MAX(priority) from tag where project_version = '#{@version}' and tag_status != '#{SpecPublishStatus::SUCCESS}' #{where_statement})"
|
38
|
+
result = db.query(sql)
|
39
|
+
puts result.count
|
40
|
+
if result.count == 0
|
26
41
|
puts "tag已全部打完!!!".green
|
27
42
|
# 执行更新podfile的操作
|
28
43
|
system "gct update podfile"
|
29
44
|
else
|
30
|
-
|
31
|
-
if
|
45
|
+
result.each do |row|
|
46
|
+
if row["tag_status"].eql?(SpecPublishStatus::WAITING) || row["tag_status"].eql?(SpecPublishStatus::CANCELED)
|
32
47
|
status = SpecPublishStatus::PENDING
|
33
|
-
|
34
|
-
|
35
|
-
|
48
|
+
name = row["pod_name"]
|
49
|
+
skip_tag = ""
|
50
|
+
if row["is_tag"].to_i == 1
|
51
|
+
skip_tag = "--skip-tag"
|
52
|
+
end
|
53
|
+
pre = ""
|
54
|
+
if row["is_pre"].to_i == 1
|
55
|
+
pre = "--pre"
|
56
|
+
end
|
57
|
+
system "gct update dependency #{name} status #{status}"
|
58
|
+
system "gct update tag #{name} --auto-tag --update-ci #{skip_tag} #{pre}"
|
36
59
|
end
|
37
60
|
end
|
38
61
|
end
|
39
62
|
end
|
40
|
-
|
41
|
-
def next_specs
|
42
|
-
content_map = FileBase.yaml_dependency_read
|
43
|
-
if content_map.nil?
|
44
|
-
return nil
|
45
|
-
end
|
46
|
-
priority = 1000
|
47
|
-
content_map.each do |k, v|
|
48
|
-
if v.keys.include?(@project_name)
|
49
|
-
priority = k
|
50
|
-
break
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
priority_map = content_map[priority.to_s]
|
55
|
-
is_all_done = true
|
56
|
-
priority_map.each do |k, v|
|
57
|
-
if !v["status"].eql?(SpecPublishStatus::SUCCESS)
|
58
|
-
is_all_done = false
|
59
|
-
break
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
if is_all_done
|
64
|
-
content_map[(priority.to_i - 1).to_s]
|
65
|
-
else
|
66
|
-
nil
|
67
|
-
end
|
68
|
-
end
|
69
63
|
end
|
70
64
|
end
|
71
65
|
end
|
@@ -22,57 +22,62 @@ module Gct
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def run
|
25
|
-
|
26
|
-
@name = "ios/#{version_map["name"]}"
|
27
|
-
@branch = version_map["branch"]
|
28
|
-
@verison = version_map["version"]
|
29
|
-
@file = "Podfile"
|
30
|
-
puts @version
|
25
|
+
initParams
|
31
26
|
update_podfile
|
32
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def initParams
|
30
|
+
db = Database::Data.new
|
31
|
+
sql = "select * from project where is_done = 0 order by 'create_time' desc"
|
32
|
+
result = db.query(sql)
|
33
|
+
result.each do |row|
|
34
|
+
@name = "ios/#{row["name"]}"
|
35
|
+
@branch = row["branch"]
|
36
|
+
@version = row["version"]
|
37
|
+
@file = "Podfile"
|
38
|
+
break
|
39
|
+
end
|
33
40
|
end
|
34
41
|
|
35
42
|
def update_podfile
|
36
43
|
podspec_content = file_contents(@name, @file, @branch)
|
37
|
-
|
38
44
|
remove_regex = /dev_pod .*/
|
39
45
|
podspec_content = podspec_content.gsub!(remove_regex, "")
|
40
|
-
|
41
|
-
# dependency
|
42
|
-
dependency_map = FileBase.yaml_dependency_read
|
43
|
-
dependencies = Array.new()
|
44
|
-
dependency_map.each do |k, v|
|
45
|
-
dependencies << v
|
46
|
-
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
db = Database::Data.new
|
48
|
+
sql = "select * from tag where project_version = '#{@version}'"
|
49
|
+
result = db.query(sql)
|
50
|
+
if result.count == 0
|
51
|
+
puts "ERROR: 没有tag库".red
|
52
|
+
return
|
53
|
+
end
|
54
|
+
result.each do |row|
|
55
|
+
name = row["pod_name"]
|
56
|
+
tag = row["tag_version"]
|
57
|
+
update_regex = /.*#{name}.*/
|
58
|
+
update_match = update_regex.match(podspec_content).to_s
|
59
|
+
update_str = " pod '#{name}', '#{tag}'"
|
60
|
+
if update_match.empty?
|
61
|
+
empty_match = "# Pods for iLife"
|
62
|
+
podspec_content = podspec_content.gsub!(empty_match, "#{empty_match} \n#{update_str}") # Pods for iLife
|
63
|
+
else
|
64
|
+
podspec_content = podspec_content.gsub!(update_match, update_str)
|
65
|
+
end
|
66
|
+
end
|
57
67
|
|
58
68
|
edit_file(podspec_content)
|
69
|
+
|
70
|
+
u_db = Database::Data.new
|
71
|
+
u_sql = "update project set is_done = 1 where version = '#{@version}'"
|
72
|
+
u_db.query(u_sql)
|
73
|
+
|
59
74
|
system "gct robot podfile"
|
75
|
+
system "gct robot summary"
|
60
76
|
end
|
61
77
|
|
62
78
|
def edit_file(content)
|
63
79
|
Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
|
64
80
|
end
|
65
|
-
|
66
|
-
# 删除和备份
|
67
|
-
def remove_and_backup
|
68
|
-
d_name = Constant.DependencyName
|
69
|
-
Dir.chdir(FileBase.tmp_path) do
|
70
|
-
# 备份dependency文件到backup文件夹下
|
71
|
-
system "cp #{d_name} ../backup/#{d_name}-#{@version}"
|
72
|
-
# 删除tmp文件夹下所有文件
|
73
|
-
system "rm -rf *"
|
74
|
-
end
|
75
|
-
end
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
@@ -18,17 +18,21 @@ module Gct
|
|
18
18
|
['--skip-tag', '是否忽略tag,直接触发ci'],
|
19
19
|
['--update-ci', '是否更新CI'],
|
20
20
|
['--auto-tag', '自动化'],
|
21
|
+
['--pre', '是否预发tag']
|
21
22
|
].concat(super)
|
22
23
|
end
|
23
24
|
|
24
25
|
def initialize(argv)
|
25
26
|
config_gitlab
|
26
|
-
@update_version_branch = 'develop'
|
27
27
|
@skip_tag = argv.flag?('skip-tag', false)
|
28
28
|
@update_ci = argv.flag?('update-ci', false)
|
29
29
|
@auto_tag = argv.flag?('auto-tag', false)
|
30
|
+
@pre = argv.flag?('pre', false)
|
30
31
|
@name = argv.shift_argument
|
31
32
|
@tag = argv.shift_argument
|
33
|
+
@pre_tag_suffix = Constant.PreHuffix
|
34
|
+
@update_version_branch = @pre ? Constant.PreTagFromBranch : Constant.DefaultTagFromBranch
|
35
|
+
@update_to_branch = @pre ? Constant.PreTagToBranch : Constant.DefaultTagToBranch
|
32
36
|
@file = get_spec_file
|
33
37
|
if @name.nil?
|
34
38
|
@name = @spec.name
|
@@ -47,14 +51,21 @@ module Gct
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def skip_tag_method
|
54
|
+
isEmptyMR = mr_to_master
|
55
|
+
if !isEmptyMR
|
56
|
+
accept_merge_request
|
57
|
+
end
|
58
|
+
remove_and_create_tag
|
59
|
+
end
|
60
|
+
|
61
|
+
def remove_and_create_tag
|
50
62
|
@new_tag = @spec.version
|
51
|
-
puts "tag
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
accept_merge_request
|
56
|
-
end
|
63
|
+
puts "new tag"
|
64
|
+
puts @new_tag
|
65
|
+
if @pre
|
66
|
+
@new_tag = "#{@new_tag}" + @pre_tag_suffix
|
57
67
|
end
|
68
|
+
puts "tag == #{@new_tag}"
|
58
69
|
# remove tag
|
59
70
|
command = `git rev-parse --is-inside-work-tree`
|
60
71
|
if command.eql?("true")
|
@@ -67,12 +78,45 @@ module Gct
|
|
67
78
|
create_tag
|
68
79
|
end
|
69
80
|
|
81
|
+
def check_ci
|
82
|
+
is_exist_ci = false
|
83
|
+
res = Gitlab.tree("#{Constant.NameSpace}#{@name}")
|
84
|
+
res.each do |g|
|
85
|
+
if g["name"].eql?('.gitlab-ci.yml')
|
86
|
+
is_exist_ci = true
|
87
|
+
break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
is_exist_ci
|
91
|
+
end
|
92
|
+
|
70
93
|
def update_ci_method
|
71
|
-
puts "
|
94
|
+
puts "正在检查CI文件".green
|
72
95
|
temp_local_file = TempLocalFile.new()
|
73
96
|
path = File.expand_path("../../init", __FILE__)
|
74
97
|
ci_content = temp_local_file.read_path_file(path, "gitlab-ci.rb")
|
75
|
-
|
98
|
+
if check_ci
|
99
|
+
# 检查 ci 文件是否有变化
|
100
|
+
remote_content = file_contents("#{Constant.NameSpace}#{@name}", '.gitlab-ci.yml', @update_version_branch)
|
101
|
+
remote_content.force_encoding('UTF-8')
|
102
|
+
strip_remote_content = remote_content.gsub(/\s/,'')
|
103
|
+
ci_content.force_encoding('UTF-8')
|
104
|
+
strip_ci_content = ci_content.gsub(/\s/,'')
|
105
|
+
|
106
|
+
if strip_ci_content.eql?strip_remote_content
|
107
|
+
puts "无需更新CI文件".green
|
108
|
+
else
|
109
|
+
edit_file('.gitlab-ci.yml', ci_content, 'update ci')
|
110
|
+
mr_to_master_if_need
|
111
|
+
end
|
112
|
+
else
|
113
|
+
create_file('.gitlab-ci.yml', ci_content, 'init ci')
|
114
|
+
mr_to_master_if_need
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def mr_to_master_if_need
|
76
120
|
isEmptyMR = mr_to_master
|
77
121
|
if !isEmptyMR
|
78
122
|
accept_merge_request
|
@@ -107,9 +151,12 @@ module Gct
|
|
107
151
|
tag = tag_regex.match(version_match)
|
108
152
|
@now_tag = tag
|
109
153
|
@new_tag = @tag || auto_add_tag(tag.to_s)
|
154
|
+
if @pre
|
155
|
+
@new_tag = "#{@new_tag}" + @pre_tag_suffix
|
156
|
+
end
|
110
157
|
replace_string = version_match.gsub(tag_regex, @new_tag)
|
111
158
|
updated_podspec_content = podspec_content.gsub(version_match, replace_string)
|
112
|
-
puts "
|
159
|
+
puts "#{@name} 更新版本号为:#{@new_tag}".green
|
113
160
|
edit_file(@file, updated_podspec_content, "@config 更新版本号:#{@new_tag}")
|
114
161
|
mr_to_master
|
115
162
|
accept_merge_request
|
@@ -120,15 +167,16 @@ module Gct
|
|
120
167
|
Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
|
121
168
|
end
|
122
169
|
|
170
|
+
def create_file(file, content, commit_message)
|
171
|
+
Gitlab.create_file(@project_id, file, @update_version_branch, content, commit_message)
|
172
|
+
end
|
173
|
+
|
123
174
|
def mr_to_master
|
124
|
-
puts "正在创建MR
|
125
|
-
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch:
|
126
|
-
# puts mr.to_hash
|
175
|
+
puts "正在创建MR请求将#{@update_version_branch}分支合并到#{@update_to_branch}分支!".green
|
176
|
+
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: "#{@update_to_branch}" })
|
127
177
|
@id = mr.iid
|
128
178
|
puts mr.merge_status
|
129
179
|
isEmptyMR = mr.diff_refs.base_sha.eql?(mr.diff_refs.head_sha)
|
130
|
-
# puts mr.diff_refs.base_sha
|
131
|
-
# puts mr.diff_refs.head_sha
|
132
180
|
close_mr if isEmptyMR
|
133
181
|
if mr.merge_status == 'cannot_be_merged' && !isEmptyMR
|
134
182
|
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
|
@@ -139,7 +187,7 @@ module Gct
|
|
139
187
|
def accept_merge_request
|
140
188
|
mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
|
141
189
|
if mr_result.state == 'merged'
|
142
|
-
puts "
|
190
|
+
puts "成功合并到#{@update_to_branch}分支".green
|
143
191
|
end
|
144
192
|
end
|
145
193
|
|
@@ -148,12 +196,22 @@ module Gct
|
|
148
196
|
end
|
149
197
|
|
150
198
|
def remove_tag
|
151
|
-
Gitlab.
|
199
|
+
tags = Gitlab.tags("#{@project_id}")
|
200
|
+
puts "remove tag is " + "#{@new_tag}"
|
201
|
+
tags.each do |t|
|
202
|
+
if t["name"].eql?("#{@new_tag}")
|
203
|
+
Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
|
204
|
+
break
|
205
|
+
end
|
206
|
+
end
|
152
207
|
end
|
153
208
|
|
154
209
|
def create_tag
|
155
|
-
Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "
|
156
|
-
|
210
|
+
Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "#{@update_to_branch}")
|
211
|
+
db = Database::Data.new
|
212
|
+
sql = "update tag t left join project p on t.project_version = p.version set t.is_tag = 1 where t.pod_name = '#{@name}' and t.is_tag != 1 and p.is_done = 0"
|
213
|
+
db.query(sql)
|
214
|
+
puts "开始上传podspec... 请在CI中查看结果".green
|
157
215
|
end
|
158
216
|
end
|
159
217
|
end
|
data/lib/gct/constant.rb
CHANGED
@@ -21,12 +21,24 @@ module Gct
|
|
21
21
|
"ios-third/"
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def DefaultTagFromBranch
|
25
25
|
"develop"
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
"
|
28
|
+
def PreTagFromBranch
|
29
|
+
"pre_develop"
|
30
|
+
end
|
31
|
+
|
32
|
+
def DefaultTagToBranch
|
33
|
+
"master"
|
34
|
+
end
|
35
|
+
|
36
|
+
def PreTagToBranch
|
37
|
+
"pre_master"
|
38
|
+
end
|
39
|
+
|
40
|
+
def PreHuffix
|
41
|
+
"-pre"
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
|
3
|
+
module Gct
|
4
|
+
module Database
|
5
|
+
class Data
|
6
|
+
def initialize
|
7
|
+
@host = FileBase.get_config("host")
|
8
|
+
@password = FileBase.get_config("password")
|
9
|
+
raise "请设置数据库ip地址!".red if @host.nil?
|
10
|
+
raise "请设置数据库密码!".red if @password.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def query(sql)
|
14
|
+
client = nil
|
15
|
+
puts "current sql is 👇👇👇"
|
16
|
+
puts sql
|
17
|
+
begin
|
18
|
+
client = Mysql2::Client.new(:host => @host, :username => "root", :database => "ios_db", :password => @password, :encoding => "utf8")
|
19
|
+
client.query(sql)
|
20
|
+
rescue => exception
|
21
|
+
puts exception
|
22
|
+
ensure
|
23
|
+
client.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/gct/file_base.rb
CHANGED
@@ -22,42 +22,6 @@ module Gct
|
|
22
22
|
yaml_write_map(yaml_path, content_map)
|
23
23
|
end
|
24
24
|
|
25
|
-
def yaml_dependency_read
|
26
|
-
path = dependency_path
|
27
|
-
if !File.exist?(path)
|
28
|
-
return nil
|
29
|
-
end
|
30
|
-
config_map = YAML.load(File.open(path, "r"))
|
31
|
-
config_map
|
32
|
-
end
|
33
|
-
|
34
|
-
def yaml_dependency_update(pod_name, key, value)
|
35
|
-
path = dependency_path
|
36
|
-
if !File.exist?(dependency_path)
|
37
|
-
return
|
38
|
-
end
|
39
|
-
begin
|
40
|
-
config_map = YAML.load(File.open(path, "r"))
|
41
|
-
config_map = Hash.new() if !config_map
|
42
|
-
config_map.each do |k, v|
|
43
|
-
v.each do |sk, sv|
|
44
|
-
if sk.eql?(pod_name)
|
45
|
-
sv[key] = value
|
46
|
-
if key.eql?("tag")
|
47
|
-
sv["status"] = SpecPublishStatus::SUCCESS
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
yaml_file = File.open(path, "w")
|
53
|
-
YAML::dump(config_map, yaml_file)
|
54
|
-
rescue IOError => e
|
55
|
-
raise e.message
|
56
|
-
ensure
|
57
|
-
yaml_file.close unless yaml_file.nil?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
25
|
def yaml_write(key, value)
|
62
26
|
begin
|
63
27
|
config_map = YAML.load(File.open(@path, "r"))
|
@@ -121,10 +85,6 @@ module Gct
|
|
121
85
|
"#{Generator::GctFile.config_file_path}"
|
122
86
|
end
|
123
87
|
|
124
|
-
def dependency_path
|
125
|
-
"#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
|
126
|
-
end
|
127
|
-
|
128
88
|
def version_path
|
129
89
|
"#{Generator::GctFile.temp_folder_path}/version"
|
130
90
|
end
|
@@ -138,11 +98,6 @@ module Gct
|
|
138
98
|
root_exist
|
139
99
|
end
|
140
100
|
|
141
|
-
def exist_dependency
|
142
|
-
root_exist = File.exist?(dependency_path)
|
143
|
-
root_exist
|
144
|
-
end
|
145
|
-
|
146
101
|
def root_err
|
147
102
|
raise "请先运行命令:gct setup".red if !exist_root
|
148
103
|
end
|
data/lib/gct/gct_version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jieming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mysql2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: claide
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +192,7 @@ files:
|
|
178
192
|
- lib/gct/command/robot/finish.rb
|
179
193
|
- lib/gct/command/robot/podfile.rb
|
180
194
|
- lib/gct/command/robot/start.rb
|
195
|
+
- lib/gct/command/robot/summary.rb
|
181
196
|
- lib/gct/command/setup.rb
|
182
197
|
- lib/gct/command/spec.rb
|
183
198
|
- lib/gct/command/spec/lint.rb
|
@@ -189,6 +204,7 @@ files:
|
|
189
204
|
- lib/gct/command/update/tag.rb
|
190
205
|
- lib/gct/command/update/version.rb
|
191
206
|
- lib/gct/constant.rb
|
207
|
+
- lib/gct/database/data.rb
|
192
208
|
- lib/gct/file_base.rb
|
193
209
|
- lib/gct/gct_version.rb
|
194
210
|
- lib/gct/generator/gct_file.rb
|