gct 0.4.0 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eacd230eb51e7c03f69df817172a1684c61a016b476ee9bede1a4490751084c
4
- data.tar.gz: 4f9525f907f827cbe90806a0fc11b42c64bc4cdefda2f6982da2e2ce6d117e1d
3
+ metadata.gz: a862c669dd00f8f75eac90ea9438a8774dd6c5fb190de25cc34024c028bbf6c3
4
+ data.tar.gz: da2c3466907b592e4bc02775b5b07ca2e69b64ad0122031b99fa00d49c212ae7
5
5
  SHA512:
6
- metadata.gz: d93d45b1ffee87733b11bc2f70fc4c35fb510c99bece66196d87b49dadb98f7a9648bb2a407cc78e98223ffbeafb1523f120ff8fec7b4ca127e9eb461a6dad24
7
- data.tar.gz: 606a302705d5305cb8d5260d489d551794ffedabea91b7da81bc7ea66cc31042d2dad835a6fd6edccc82369b45d7e4ba5de55a35fceb3b520d29468a73a36115
6
+ metadata.gz: 8c00440bc3426b6a629353a850bd652cb7a2d4d61efcbe4c1e81f45903606aa50c3c3bc5ea8983fff825a78de7c7d2a0231277aeedd85d526ce0ff7a63846f4c
7
+ data.tar.gz: c35c3dee9f8c30d38a334937eebc6203effa5cf38d6ff675e2876e04bd491fc64f4df3f38e1e0808b2d8707bc7cfd473696a7c5bfc8d974a0b333824a6422f36
data/lib/gct.rb CHANGED
@@ -13,4 +13,8 @@ module Gct
13
13
  require "gct/generator/gct_file"
14
14
  end
15
15
 
16
+ module Database
17
+ require "gct/database/data"
18
+ end
19
+
16
20
  end
@@ -52,8 +52,6 @@ module Gct
52
52
  Colored2.disable!
53
53
  String.send(:define_method, :colorize) { |string, _| string }
54
54
  end
55
-
56
- config_gitlab
57
55
  end
58
56
 
59
57
  def file_contents(project_id, file, branch)
@@ -63,7 +61,7 @@ module Gct
63
61
  end
64
62
 
65
63
  def config_gitlab
66
- if FileBase.exist_root and token and Gitlab.endpoint.nil?
64
+ if FileBase.exist_root and token
67
65
  Gitlab.configure do |config|
68
66
  config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
69
67
  config.private_token = token
@@ -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
@@ -13,20 +14,27 @@ module Gct
13
14
  self.arguments = [
14
15
  CLAide::Argument.new('PROJECT_ID', true),
15
16
  CLAide::Argument.new('BRANCH', true),
17
+ CLAide::Argument.new('VERSION', true),
16
18
  ]
17
19
 
18
20
  def initialize(argv)
19
21
  gitlab_error
22
+ config_gitlab
20
23
  @update_ci = argv.flag?('update-ci', false)
21
- @project_id = "ios/#{argv.shift_argument}"
24
+ @pre = argv.flag?('pre', false)
25
+ name = argv.shift_argument
26
+ @project_id = "ios/#{name}"
27
+ @project_name = name
22
28
  @branch = argv.shift_argument
29
+ @version = argv.shift_argument
23
30
  @file = 'Podfile'
24
31
  super
25
32
  end
26
33
 
27
34
  def self.options
28
35
  [
29
- ['--update-ci', '是否更新CI']
36
+ ['--update-ci', '是否更新CI'],
37
+ ['--pre', '是否为预发tag'],
30
38
  ].concat(super)
31
39
  end
32
40
 
@@ -34,22 +42,39 @@ module Gct
34
42
  super
35
43
  help! '请输入项目名.' unless @project_id
36
44
  help! '请输入分支名.' unless @branch
45
+ help! '请输入版本号.' unless @version
37
46
  end
38
47
 
39
48
  def run
40
49
  FileBase.root_err
41
50
  puts "开始分析podfile文件".green
42
51
  puts ""
43
- exist_dep = FileBase.exist_dependency
44
- if exist_dep
45
- tmp_podspecs
46
- priority_map = FileBase.yaml_dependency_read
47
- create_tag_by_priority(priority_map)
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
48
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)
49
75
  untagged_specs = analyze_dependencies
50
- priority_map = priority_rank(untagged_specs)
51
- generate_dependency_file(priority_map)
52
- create_tag_by_priority(priority_map)
76
+ priority_rank(untagged_specs)
77
+ create_tag_by_priority()
53
78
  end
54
79
  end
55
80
 
@@ -59,33 +84,76 @@ module Gct
59
84
  end
60
85
 
61
86
  def podfile
62
- # if check_branch_can_be_update('zeus')
63
- # if check_branch('ft/tag') # TODO: Test branch
64
- contents = file_contents(@project_id, @file, @branch)
65
- contents.force_encoding('UTF-8')
66
- temp_local_file = TempLocalFile.new(contents, @file)
67
- temp_local_file.write
68
- full_path = temp_local_file.full_path
69
-
70
- @podfile ||= begin
71
- podfile = Pod::Podfile.from_ruby(full_path, contents)
72
- podfile
73
- end
74
- # 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
75
97
  end
76
98
 
77
99
  def tmp_podspecs
78
- untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
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
79
102
 
80
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
81
110
  file_name = "#{dep.name}.podspec"
82
- podspec_contents = file_contents("#{Constant.NameSpace}#{dep.name}", file_name, Constant.DefaultTagBranch)
111
+ podspec_contents = file_contents(project_name, file_name, branch)
83
112
  temp_local_spec_file = TempLocalFile.new(podspec_contents, file_name)
84
113
  temp_local_spec_file.write
85
- 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
86
118
  end
87
119
  spec_files
88
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
89
157
 
90
158
  def analyze_dependencies
91
159
  untagged_specs = tmp_podspecs.map do |spec_file|
@@ -164,69 +232,55 @@ module Gct
164
232
  end
165
233
  end
166
234
  end
167
- dependency_map = Hash.new()
168
- priority_map = Hash.new()
235
+
236
+ values = ""
169
237
  temp_spec_map.each do |key, value|
170
- dependency_map[key] = {"priority" => value.priority, "tag" => value.tag, "status" => value.status}
238
+ values.concat("('#{@version}', '#{key}', '#{@project_name}', '#{value.tag}', '#{value.status}', #{value.priority}" + (@pre ? ", 1)," : "),"))
171
239
  end
172
- priority = 1000
173
- while priority <= 1000 do
174
- tmp_hash = Hash.new()
175
- dependency_map.each do |key, value|
176
- if (value["priority"] == priority)
177
- tmp_hash.store(key, {"tag" => value["tag"], "status" => value["status"]})
178
- dependency_map.delete(value)
179
- end
180
- end
181
- if (tmp_hash.keys.count == 0)
182
- priority = 1001
183
- else
184
- priority_map[priority.to_s] = tmp_hash
185
- priority -= 1
186
- end
187
- end
188
- priority_map
189
- end
190
-
191
- def generate_dependency_file(priority_map)
192
- yaml_path = "#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
193
- 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)
194
245
  end
195
246
 
196
247
  # 按优先级打tag, 触发第一个优先级,其他的上一优先级打完之后自动触发
197
- def create_tag_by_priority(priority_map)
198
- priority = get_current_need_tag_priority
199
- value = priority_map[priority.to_s]
200
- raise "没有需要打tag的库".red if value.keys.count == 0
201
- value.each do |key, val|
202
- if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
203
- status = SpecPublishStatus::PENDING
204
- val["status"] = status
205
- system "gct update dependency #{key} status #{status}"
206
- system "gct update tag #{key} --auto-tag"
207
- end
208
- end
209
- end
210
-
211
- # 当前优先级是否已打完
212
- def get_current_need_tag_priority
213
- priority = 1000
214
- content_map = FileBase.yaml_dependency_read
215
- priority_map = content_map[priority.to_s]
216
- is_all_done = true
217
- while is_all_done do
218
- priority_map.each do |k, v|
219
- if !v["status"].eql?(SpecPublishStatus::SUCCESS)
220
- is_all_done = false
221
- 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}"
222
273
  end
223
274
  end
224
- if is_all_done
225
- priority -= 1
226
- priority_map = content_map[priority.to_s]
275
+ f_ins = ins[0, ins.length - 1]
276
+ sql = "update tag set tag_status = (
277
+ case
278
+ #{vals}
227
279
  end
280
+ ) where pod_name in (#{f_ins}) and project_version = '#{@version}'"
281
+ update_db = Database::Data.new
282
+ update_db.query(sql)
228
283
  end
229
- priority
230
284
  end
231
285
  end
232
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 "status" "发布中"
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 robot finish true --test
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 --test
26
- - gct update dependency $CI_PROJECT_NAME "status" "发布失败"
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
@@ -1,5 +1,7 @@
1
1
  require 'gct/command/robot/start'
2
2
  require 'gct/command/robot/finish'
3
+ require 'gct/command/robot/podfile'
4
+ require 'gct/command/robot/summary'
3
5
  require 'net/https'
4
6
  require 'json'
5
7
 
@@ -0,0 +1,38 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ module Gct
5
+ class Command
6
+ class Robot < Command
7
+ class Podfile < Robot
8
+
9
+ self.summary = 'podfile更新通知'
10
+ self.description = <<-DESC
11
+ podfile更新通知
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
+ @project_name = ENV['CI_PROJECT_NAME']
25
+ @tag = ENV['CI_COMMIT_REF_NAME']
26
+ @test = argv.flag?('test', false)
27
+ super
28
+ end
29
+
30
+ def run
31
+ message = " <font color=\"info\">podfile 更新完毕</font>"
32
+ content = "#{message}"
33
+ robot_send(content)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -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
- # lint_spec
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('KEY', false),
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
- @key = argv.shift_argument
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
- FileBase.yaml_dependency_update(@pod_name, @key, @value)
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
@@ -8,64 +8,58 @@ module Gct
8
8
  DESC
9
9
 
10
10
  def initialize(argv)
11
+ config_gitlab
11
12
  @project_name = ENV['CI_PROJECT_NAME']
12
13
  super
13
14
  end
14
15
 
15
16
  def run
16
- batch_tag
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
17
31
  end
18
32
 
19
33
  def batch_tag
20
- value = next_specs
21
- if val.nil?
22
- return
23
- end
24
- if value.keys.count == 0
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
25
41
  puts "tag已全部打完!!!".green
26
42
  # 执行更新podfile的操作
27
- # system "gct update podfile"
43
+ system "gct update podfile"
28
44
  else
29
- value.each do |key, val|
30
- if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
45
+ result.each do |row|
46
+ if row["tag_status"].eql?(SpecPublishStatus::WAITING) || row["tag_status"].eql?(SpecPublishStatus::CANCELED)
31
47
  status = SpecPublishStatus::PENDING
32
- val["status"] = status
33
- system "gct update dependency #{key} status #{status}"
34
- system "gct update tag #{key} --auto-tag --update-ci"
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}"
35
59
  end
36
60
  end
37
61
  end
38
62
  end
39
-
40
- def next_specs
41
- priority = get_current_project_priority
42
- content_map = FileBase.yaml_dependency_read
43
- priority_map = content_map[priority.to_s]
44
- is_all_done = true
45
- priority_map.each do |k, v|
46
- if !v["status"].eql?("发布成功")
47
- is_all_done = false
48
- break
49
- end
50
- end
51
- if is_all_done
52
- content_map[(priority - 1).to_s]
53
- else
54
- nil
55
- end
56
- end
57
-
58
- def get_current_project_priority
59
- content_map = FileBase.yaml_dependency_read
60
- priority = 1000
61
- content_map.each do |k, v|
62
- if v.keys.include?(@project_name)
63
- priority = k
64
- break
65
- end
66
- end
67
- priority
68
- end
69
63
  end
70
64
  end
71
65
  end
@@ -9,10 +9,10 @@ module Gct
9
9
  DESC
10
10
 
11
11
  self.arguments = [
12
- CLAide::Argument.new('VERSION', true),
13
- ]
12
+ ]
14
13
 
15
14
  def initialize(argv)
15
+ config_gitlab
16
16
  @version = argv.shift_argument
17
17
  super
18
18
  end
@@ -22,18 +22,61 @@ module Gct
22
22
  end
23
23
 
24
24
  def run
25
+ initParams
26
+ update_podfile
27
+ end
25
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
26
40
  end
27
41
 
28
- # 删除和备份
29
- def remove_and_backup
30
- d_name = Constant.DependencyName
31
- Dir.chdir(FileBase.tmp_path) do
32
- # 备份dependency文件到backup文件夹下
33
- system "cp #{d_name} ../backup/#{d_name}-#{@version}"
34
- # 删除tmp文件夹下所有文件
35
- system "rm -rf *"
42
+ def update_podfile
43
+ podspec_content = file_contents(@name, @file, @branch)
44
+ remove_regex = /dev_pod .*/
45
+ podspec_content = podspec_content.gsub!(remove_regex, "")
46
+
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
36
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
67
+
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
+
74
+ system "gct robot podfile"
75
+ system "gct robot summary"
76
+ end
77
+
78
+ def edit_file(content)
79
+ Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
37
80
  end
38
81
  end
39
82
  end
@@ -18,16 +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
- @update_version_branch = 'develop'
26
+ config_gitlab
26
27
  @skip_tag = argv.flag?('skip-tag', false)
27
28
  @update_ci = argv.flag?('update-ci', false)
28
29
  @auto_tag = argv.flag?('auto-tag', false)
30
+ @pre = argv.flag?('pre', false)
29
31
  @name = argv.shift_argument
30
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
31
36
  @file = get_spec_file
32
37
  if @name.nil?
33
38
  @name = @spec.name
@@ -46,27 +51,74 @@ module Gct
46
51
  end
47
52
 
48
53
  def skip_tag_method
49
- @new_tag = @spec.version
50
- puts "tag == #{@new_tag}"
51
54
  if !@update_ci
52
55
  isEmptyMR = mr_to_master
53
56
  if !isEmptyMR
54
57
  accept_merge_request
55
58
  end
56
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}"
57
71
  # remove tag
58
- `git tag -d #{@new_tag}`
59
- `git push origin :refs/tags/#{@new_tag}`
72
+ command = `git rev-parse --is-inside-work-tree`
73
+ if command.eql?("true")
74
+ `git tag -d #{@new_tag}`
75
+ `git push origin :refs/tags/#{@new_tag}`
76
+ else
77
+ remove_tag
78
+ end
60
79
  # create tag
61
80
  create_tag
62
81
  end
63
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
+
64
95
  def update_ci_method
65
- puts "更新ci文件".green
96
+ puts "正在检查CI文件".green
66
97
  temp_local_file = TempLocalFile.new()
67
98
  path = File.expand_path("../../init", __FILE__)
68
99
  ci_content = temp_local_file.read_path_file(path, "gitlab-ci.rb")
69
- edit_file('.gitlab-ci.yml', ci_content, 'update ci')
100
+ if check_ci
101
+ # 检查 ci 文件是否有变化
102
+ remote_content = file_contents("#{Constant.NameSpace}#{@name}", '.gitlab-ci.yml', @update_version_branch)
103
+ remote_content.force_encoding('UTF-8')
104
+ strip_remote_content = remote_content.gsub(/\s/,'')
105
+ ci_content.force_encoding('UTF-8')
106
+ strip_ci_content = ci_content.gsub(/\s/,'')
107
+
108
+ if strip_ci_content.eql?strip_remote_content
109
+ puts "无需更新CI文件".green
110
+ else
111
+ edit_file('.gitlab-ci.yml', ci_content, 'update ci')
112
+ mr_to_master_if_need
113
+ end
114
+ else
115
+ create_file('.gitlab-ci.yml', ci_content, 'init ci')
116
+ mr_to_master_if_need
117
+ end
118
+
119
+ end
120
+
121
+ def mr_to_master_if_need
70
122
  isEmptyMR = mr_to_master
71
123
  if !isEmptyMR
72
124
  accept_merge_request
@@ -75,17 +127,20 @@ module Gct
75
127
 
76
128
  def get_spec_file
77
129
  spec_file = nil
130
+ full_path = nil
78
131
  if @auto_tag
79
132
  raise "podspec名不能为空!!!".red if spec_file.nil? if @name.nil?
80
133
  Dir.chdir(FileBase.tmp_path) do
81
134
  spec_file = Pathname.glob("#{@name}.podspec").first
135
+ full_path = spec_file.realpath
82
136
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
83
137
  end
84
138
  else
85
139
  spec_file = Pathname.glob('*.podspec').first
140
+ full_path = spec_file
86
141
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
87
142
  end
88
- @spec = Pod::Specification.from_file(spec_file)
143
+ @spec = Pod::Specification.from_file(full_path)
89
144
  spec_file
90
145
  end
91
146
 
@@ -98,9 +153,12 @@ module Gct
98
153
  tag = tag_regex.match(version_match)
99
154
  @now_tag = tag
100
155
  @new_tag = @tag || auto_add_tag(tag.to_s)
156
+ if @pre
157
+ @new_tag = "#{@new_tag}" + @pre_tag_suffix
158
+ end
101
159
  replace_string = version_match.gsub(tag_regex, @new_tag)
102
160
  updated_podspec_content = podspec_content.gsub(version_match, replace_string)
103
- puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
161
+ puts "#{@name} 更新版本号为:#{@new_tag}".green
104
162
  edit_file(@file, updated_podspec_content, "@config 更新版本号:#{@new_tag}")
105
163
  mr_to_master
106
164
  accept_merge_request
@@ -111,15 +169,16 @@ module Gct
111
169
  Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
112
170
  end
113
171
 
172
+ def create_file(file, content, commit_message)
173
+ Gitlab.create_file(@project_id, file, @update_version_branch, content, commit_message)
174
+ end
175
+
114
176
  def mr_to_master
115
- puts "正在创建MR请求将develop分支合并到master!".green
116
- mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
117
- # puts mr.to_hash
177
+ puts "正在创建MR请求将#{@update_version_branch}分支合并到#{@update_to_branch}分支!".green
178
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: "#{@update_to_branch}" })
118
179
  @id = mr.iid
119
180
  puts mr.merge_status
120
181
  isEmptyMR = mr.diff_refs.base_sha.eql?(mr.diff_refs.head_sha)
121
- # puts mr.diff_refs.base_sha
122
- # puts mr.diff_refs.head_sha
123
182
  close_mr if isEmptyMR
124
183
  if mr.merge_status == 'cannot_be_merged' && !isEmptyMR
125
184
  raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
@@ -130,7 +189,7 @@ module Gct
130
189
  def accept_merge_request
131
190
  mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
132
191
  if mr_result.state == 'merged'
133
- puts "成功合并到master分支".green
192
+ puts "成功合并到#{@update_to_branch}分支".green
134
193
  end
135
194
  end
136
195
 
@@ -138,9 +197,23 @@ module Gct
138
197
  Gitlab.update_merge_request("#{@project_id}", @id, {state_event: 'close'})
139
198
  end
140
199
 
200
+ def remove_tag
201
+ tags = Gitlab.tags("#{@project_id}")
202
+ puts "remove tag is " + "#{@new_tag}"
203
+ tags.each do |t|
204
+ if t["name"].eql?("#{@new_tag}")
205
+ Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
206
+ break
207
+ end
208
+ end
209
+ end
210
+
141
211
  def create_tag
142
- Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "master")
143
- puts "打tag成功,开始上传podspec...".green
212
+ Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "#{@update_to_branch}")
213
+ db = Database::Data.new
214
+ 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"
215
+ db.query(sql)
216
+ puts "开始上传podspec... 请在CI中查看结果".green
144
217
  end
145
218
  end
146
219
  end
@@ -14,6 +14,7 @@ module Gct
14
14
  ]
15
15
 
16
16
  def initialize(argv)
17
+ config_gitlab
17
18
  @name = argv.shift_argument
18
19
  @version = argv.shift_argument
19
20
  name = @name ||= "iLife"
@@ -21,12 +21,24 @@ module Gct
21
21
  "ios-third/"
22
22
  end
23
23
 
24
- def DefaultTagBranch
24
+ def DefaultTagFromBranch
25
25
  "develop"
26
26
  end
27
27
 
28
- def DependencyName
29
- "dependency"
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
@@ -7,35 +7,19 @@ module Gct
7
7
  @path = path
8
8
  end
9
9
 
10
- def yaml_dependency_read
11
- path = dependency_path
10
+ def read_version
11
+ path = version_path
12
+ if !File.exist?(path)
13
+ return nil
14
+ end
12
15
  config_map = YAML.load(File.open(path, "r"))
13
16
  config_map
14
17
  end
15
18
 
16
- def yaml_dependency_update(pod_name, key, value)
17
- begin
18
- path = dependency_path
19
- config_map = YAML.load(File.open(path, "r"))
20
- puts config_map
21
- config_map = Hash.new() if !config_map
22
- config_map.each do |k, v|
23
- v.each do |sk, sv|
24
- if sk.eql?(pod_name)
25
- sv[key] = value
26
- if key.eql?("tag")
27
- sv["status"] = SpecPublishStatus::SUCCESS
28
- end
29
- end
30
- end
31
- end
32
- yaml_file = File.open(path, "w")
33
- YAML::dump(config_map, yaml_file)
34
- rescue IOError => e
35
- raise e.message
36
- ensure
37
- yaml_file.close unless yaml_file.nil?
38
- end
19
+ def write_version_message(verison, name, branch)
20
+ yaml_path = "#{Generator::GctFile.temp_folder_path}/version"
21
+ content_map = {"version" => verison, "name" => name, "branch" => branch}
22
+ yaml_write_map(yaml_path, content_map)
39
23
  end
40
24
 
41
25
  def yaml_write(key, value)
@@ -101,8 +85,8 @@ module Gct
101
85
  "#{Generator::GctFile.config_file_path}"
102
86
  end
103
87
 
104
- def dependency_path
105
- "#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
88
+ def version_path
89
+ "#{Generator::GctFile.temp_folder_path}/version"
106
90
  end
107
91
 
108
92
  def tmp_path
@@ -114,11 +98,6 @@ module Gct
114
98
  root_exist
115
99
  end
116
100
 
117
- def exist_dependency
118
- root_exist = File.exist?(dependency_path)
119
- root_exist
120
- end
121
-
122
101
  def root_err
123
102
  raise "请先运行命令:gct setup".red if !exist_root
124
103
  end
@@ -2,5 +2,5 @@ module Gct
2
2
  # freeze 冻结对象,将对象变成一个常量
3
3
  # unless 右边的代码块成立,才会运行左边的代码块
4
4
  # defined? 是用来判断本地变量是否存在,也可用来判断是否存在方法
5
- VERSION = "0.4.0".freeze unless defined? Gct::VERSION
5
+ VERSION = "0.4.6".freeze unless defined? Gct::VERSION
6
6
  end
@@ -30,12 +30,12 @@ module Gct
30
30
  end
31
31
 
32
32
  module SpecPublishStatus
33
- PENDING = '队列中'
34
- WAITING = '待发布'
35
- SKIPPED = '已忽略'
36
- MERGED = '已合并'
37
- DEPLOYING = '发布中'
38
- SUCCESS = '发布成功'
39
- FAILED = '发布失败'
40
- CANCELED = '已取消'
33
+ PENDING = 'pending'
34
+ WAITING = 'waiting'
35
+ SKIPPED = 'skipped'
36
+ MERGED = 'merged'
37
+ DEPLOYING = 'deploying'
38
+ SUCCESS = 'success'
39
+ FAILED = 'failed'
40
+ CANCELED = 'canceled'
41
41
  end
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.0
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jieming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2020-10-21 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
@@ -176,11 +190,12 @@ files:
176
190
  - lib/gct/command/repo/update.rb
177
191
  - lib/gct/command/robot.rb
178
192
  - lib/gct/command/robot/finish.rb
193
+ - lib/gct/command/robot/podfile.rb
179
194
  - lib/gct/command/robot/start.rb
195
+ - lib/gct/command/robot/summary.rb
180
196
  - lib/gct/command/setup.rb
181
197
  - lib/gct/command/spec.rb
182
198
  - lib/gct/command/spec/lint.rb
183
- - lib/gct/command/tag.rb
184
199
  - lib/gct/command/update.rb
185
200
  - lib/gct/command/update/analyze.rb
186
201
  - lib/gct/command/update/dependency.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
@@ -1,13 +0,0 @@
1
- require 'gct/command/tag/next'
2
-
3
- module Gct
4
- class Command
5
- class Tag < Command
6
- self.abstract_command = true
7
- self.summary = 'tag 相关操作'
8
- self.description = <<-DESC
9
- tag 相关操作
10
- DESC
11
- end
12
- end
13
- end