gct 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +6 -6
- 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 +39 -35
- data/lib/gct/command/update/tag.rb +54 -15
- 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 +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2543169b03dd0c5d196ea4af9fb3214efccfd54165fb5418c3fb36e9f04c0b88
|
4
|
+
data.tar.gz: a17f7e2f676904a9c8c6b0acd7ffc08fe0d8db6f07f974f8825e90a120ffa2cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c620629c7a89a8758a44c45635ed470cc42330f954c05a2bb7caf0adf2892215f7b40833f702a1378e18e648ec7ce383e5f81520622a5bd4677899ea74c7687
|
7
|
+
data.tar.gz: c1ad60709ac0c069086abccd377cf30a106f34f93ca224ca6541a0bcbf6010f521503beff69ee035648d1b74de8f73b751c7e819b638ea84928182d46970faff
|
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,14 @@ stages:
|
|
5
5
|
push_pod:
|
6
6
|
stage: push
|
7
7
|
script:
|
8
|
-
- gct robot start
|
8
|
+
- gct robot start
|
9
9
|
- echo "开始lint 和 push podspec"
|
10
|
-
- gct update dependency $CI_PROJECT_NAME "
|
10
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "deploying"
|
11
11
|
- gct clean lint $CI_PROJECT_NAME
|
12
12
|
- gct repo update
|
13
13
|
- gct repo push
|
14
|
-
- gct robot finish true
|
15
|
-
- gct update dependency $CI_PROJECT_NAME "
|
14
|
+
- gct robot finish true
|
15
|
+
- gct update dependency $CI_PROJECT_NAME "tag_version" $CI_COMMIT_REF_NAME
|
16
16
|
- gct update next
|
17
17
|
only:
|
18
18
|
- tags
|
@@ -22,8 +22,8 @@ push_pod:
|
|
22
22
|
on_failure:
|
23
23
|
stage: failure
|
24
24
|
script:
|
25
|
-
- gct robot finish false
|
26
|
-
- gct update dependency $CI_PROJECT_NAME "
|
25
|
+
- gct robot finish false
|
26
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "failed"
|
27
27
|
when: on_failure
|
28
28
|
only:
|
29
29
|
- tags
|
@@ -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,61 @@ 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"
|
60
75
|
end
|
61
76
|
|
62
77
|
def edit_file(content)
|
63
78
|
Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
|
64
79
|
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
80
|
end
|
77
81
|
end
|
78
82
|
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,23 @@ module Gct
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def skip_tag_method
|
50
|
-
@new_tag = @spec.version
|
51
|
-
puts "tag == #{@new_tag}"
|
52
54
|
if !@update_ci
|
53
55
|
isEmptyMR = mr_to_master
|
54
56
|
if !isEmptyMR
|
55
57
|
accept_merge_request
|
56
58
|
end
|
57
59
|
end
|
60
|
+
remove_and_create_tag
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove_and_create_tag
|
64
|
+
@new_tag = @spec.version
|
65
|
+
puts "new tag"
|
66
|
+
puts @new_tag
|
67
|
+
if @pre
|
68
|
+
@new_tag = "#{@new_tag}" + @pre_tag_suffix
|
69
|
+
end
|
70
|
+
puts "tag == #{@new_tag}"
|
58
71
|
# remove tag
|
59
72
|
command = `git rev-parse --is-inside-work-tree`
|
60
73
|
if command.eql?("true")
|
@@ -67,15 +80,27 @@ module Gct
|
|
67
80
|
create_tag
|
68
81
|
end
|
69
82
|
|
83
|
+
def check_ci
|
84
|
+
is_exist_ci = false
|
85
|
+
res = Gitlab.tree("#{Constant.NameSpace}#{@name}")
|
86
|
+
res.each do |g|
|
87
|
+
if g["name"].eql?('.gitlab-ci.yml')
|
88
|
+
is_exist_ci = true
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
is_exist_ci
|
93
|
+
end
|
94
|
+
|
70
95
|
def update_ci_method
|
71
96
|
puts "更新ci文件".green
|
72
97
|
temp_local_file = TempLocalFile.new()
|
73
98
|
path = File.expand_path("../../init", __FILE__)
|
74
99
|
ci_content = temp_local_file.read_path_file(path, "gitlab-ci.rb")
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
100
|
+
if check_ci
|
101
|
+
edit_file('.gitlab-ci.yml', ci_content, 'update ci')
|
102
|
+
else
|
103
|
+
create_file('.gitlab-ci.yml', ci_content, 'init ci')
|
79
104
|
end
|
80
105
|
end
|
81
106
|
|
@@ -107,6 +132,9 @@ module Gct
|
|
107
132
|
tag = tag_regex.match(version_match)
|
108
133
|
@now_tag = tag
|
109
134
|
@new_tag = @tag || auto_add_tag(tag.to_s)
|
135
|
+
if @pre
|
136
|
+
@new_tag = "#{@new_tag}" + @pre_tag_suffix
|
137
|
+
end
|
110
138
|
replace_string = version_match.gsub(tag_regex, @new_tag)
|
111
139
|
updated_podspec_content = podspec_content.gsub(version_match, replace_string)
|
112
140
|
puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
|
@@ -120,15 +148,16 @@ module Gct
|
|
120
148
|
Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
|
121
149
|
end
|
122
150
|
|
151
|
+
def create_file(file, content, commit_message)
|
152
|
+
Gitlab.create_file(@project_id, file, @update_version_branch, content, commit_message)
|
153
|
+
end
|
154
|
+
|
123
155
|
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
|
156
|
+
puts "正在创建MR请求将#{@update_version_branch}分支合并到#{@update_to_branch}分支!".green
|
157
|
+
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: "#{@update_to_branch}" })
|
127
158
|
@id = mr.iid
|
128
159
|
puts mr.merge_status
|
129
160
|
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
161
|
close_mr if isEmptyMR
|
133
162
|
if mr.merge_status == 'cannot_be_merged' && !isEmptyMR
|
134
163
|
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
|
@@ -139,7 +168,7 @@ module Gct
|
|
139
168
|
def accept_merge_request
|
140
169
|
mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
|
141
170
|
if mr_result.state == 'merged'
|
142
|
-
puts "
|
171
|
+
puts "成功合并到#{@update_to_branch}分支".green
|
143
172
|
end
|
144
173
|
end
|
145
174
|
|
@@ -148,11 +177,21 @@ module Gct
|
|
148
177
|
end
|
149
178
|
|
150
179
|
def remove_tag
|
151
|
-
Gitlab.
|
180
|
+
tags = Gitlab.tags("#{@project_id}")
|
181
|
+
puts "remove tag is " + "#{@new_tag}"
|
182
|
+
tags.each do |t|
|
183
|
+
if t["name"].eql?("#{@new_tag}")
|
184
|
+
Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
|
185
|
+
break
|
186
|
+
end
|
187
|
+
end
|
152
188
|
end
|
153
189
|
|
154
190
|
def create_tag
|
155
|
-
Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "
|
191
|
+
Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "#{@update_to_branch}")
|
192
|
+
db = Database::Data.new
|
193
|
+
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"
|
194
|
+
db.query(sql)
|
156
195
|
puts "打tag成功,开始上传podspec...".green
|
157
196
|
end
|
158
197
|
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.2
|
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-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,20 @@ dependencies:
|
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: mysql2
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :runtime
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
137
151
|
description: '"gct ios 自动化脚本工具"'
|
138
152
|
email:
|
139
153
|
- 307113345@qq.com
|
@@ -189,6 +203,7 @@ files:
|
|
189
203
|
- lib/gct/command/update/tag.rb
|
190
204
|
- lib/gct/command/update/version.rb
|
191
205
|
- lib/gct/constant.rb
|
206
|
+
- lib/gct/database/data.rb
|
192
207
|
- lib/gct/file_base.rb
|
193
208
|
- lib/gct/gct_version.rb
|
194
209
|
- lib/gct/generator/gct_file.rb
|