gct 0.3.93 → 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.
@@ -2,6 +2,7 @@ require 'gct/command/op/gems'
2
2
  require 'gct/command/op/gitconf'
3
3
  require 'gct/command/op/xcache'
4
4
  require 'gct/command/op/root'
5
+ require 'gct/command/op/lint'
5
6
 
6
7
  module Gct
7
8
  class Command
@@ -0,0 +1,35 @@
1
+ module Gct
2
+ class Command
3
+ class Op < Command
4
+ class Lint < Op
5
+
6
+ self.summary = '打开lint 缓存文件夹'
7
+ self.description = <<-DESC
8
+ 打开lint 缓存文件夹
9
+ DESC
10
+
11
+ self.arguments = [
12
+ ]
13
+
14
+ def initialize(argv)
15
+ super
16
+ end
17
+
18
+ def validate!
19
+ super
20
+ end
21
+
22
+ def run
23
+ openLintCache
24
+ end
25
+
26
+ def openLintCache
27
+ lintCache = '~/Library/Caches/CocoaPods/Pods/External/'
28
+ puts "Xcode缓存路径为:#{lintCache}".green
29
+ system "open #{lintCache}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -1,5 +1,8 @@
1
1
  require 'gct/command/robot/start'
2
2
  require 'gct/command/robot/finish'
3
+ require 'gct/command/robot/podfile'
4
+ require 'net/https'
5
+ require 'json'
3
6
 
4
7
  module Gct
5
8
  class Command
@@ -9,6 +12,43 @@ module Gct
9
12
  self.description = <<-DESC
10
13
  发送jenkins和gitlab机器人消息
11
14
  DESC
15
+
16
+ def self.options
17
+ [
18
+ ['--test', '测试机器人,测试webhook'],
19
+ ].concat(super)
20
+ end
21
+
22
+ def initialize(argv)
23
+ @test = argv.flag?('test', false)
24
+ super
25
+ end
26
+
27
+ def robot_send(content)
28
+ if @test
29
+ webhook = FileBase.get_config("gitlab-robot-webhook-test")
30
+ else
31
+ webhook = FileBase.get_config("gitlab-robot-webhook")
32
+ end
33
+ raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty?
34
+ url = URI(webhook)
35
+
36
+ http = Net::HTTP.new(url.host, url.port)
37
+ if url.scheme == "https"
38
+ http.use_ssl = true
39
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
40
+ end
41
+
42
+ data = {
43
+ "msgtype": "markdown",
44
+ "markdown": {
45
+ "content": "#{content}"
46
+ }
47
+ }.to_json
48
+
49
+ header = {'content-type':'application/json'}
50
+ response = http.post(url, data, header)
51
+ end
12
52
  end
13
53
  end
14
54
  end
@@ -1,5 +1,4 @@
1
- require 'net/https'
2
- require 'json'
1
+
3
2
 
4
3
  module Gct
5
4
  class Command
@@ -33,32 +32,17 @@ module Gct
33
32
  end
34
33
 
35
34
  def run
36
- build_text = @build_status ? "<font color=\"info\">CI运行成功</font>" : "<font color=\"comment\">CI运行失败</font>,请相关人员注意"
37
- ci_text = "[点击跳转](#{@ci_url})"
38
-
39
- if @test
40
- webhook = FileBase.get_config("gitlab-robot-webhook-test")
41
- elsif
42
- webhook = FileBase.get_config("gitlab-robot-webhook")
43
- end
44
- raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty?
45
- url = URI(webhook)
46
-
47
- http = Net::HTTP.new(url.host, url.port)
48
- if url.scheme == "https"
49
- http.use_ssl = true
50
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
35
+ puts @build_status.class
36
+ puts "build_status == #{@build_status}"
37
+ if @build_status.eql?("false")
38
+ build_text = "<font color=\"comment\">CI运行失败</font>,请相关人员注意"
39
+ elsif @build_status.eql?("true")
40
+ build_text = "<font color=\"info\">CI运行成功</font>"
51
41
  end
52
-
53
- data = {
54
- "msgtype": "markdown",
55
- "markdown": {
56
- "content": "**#{@project_name} #{build_text}**\n\n\n>触发人:#{@user_name}\n\n>tag:#{@tag}\n\n>commitid:#{@commit_sha}\n\n>流水线地址:#{ci_text}"
57
- }
58
- }.to_json
59
-
60
- header = {'content-type':'application/json'}
61
- response = http.post(url, data, header)
42
+ ci_text = "[点击跳转](#{@ci_url})"
43
+
44
+ content = "**#{@project_name} #{build_text}**\n\n\n>触发人:#{@user_name}\n\n>tag:#{@tag}\n\n>commitid:#{@commit_sha}\n\n>流水线地址:#{ci_text}"
45
+ robot_send(content)
62
46
  end
63
47
  end
64
48
  end
@@ -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
@@ -28,30 +28,9 @@ module Gct
28
28
  end
29
29
 
30
30
  def run
31
- if @test
32
- webhook = FileBase.get_config("gitlab-robot-webhook-test")
33
- elsif
34
- webhook = FileBase.get_config("gitlab-robot-webhook")
35
- end
36
- raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty?
37
- url = URI(webhook)
38
-
39
- http = Net::HTTP.new(url.host, url.port)
40
- if url.scheme == "https"
41
- http.use_ssl = true
42
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
- end
44
-
45
31
  message = " <font color=\"info\">#{@tag}</font> 开始打tag"
46
- data = {
47
- "msgtype": "markdown",
48
- "markdown": {
49
- "content": "**#{@project_name}** #{message}"
50
- }
51
- }.to_json
52
-
53
- header = {'content-type':'application/json'}
54
- response = http.post(url, data, header)
32
+ content = "**#{@project_name}** #{message}"
33
+ robot_send(content)
55
34
  end
56
35
  end
57
36
  end
@@ -15,9 +15,18 @@ module Gct
15
15
  create_root_folder
16
16
  create_temp_folder
17
17
  create_config_file
18
+ create_backup_folder
18
19
  puts "setup success!".green
19
20
  end
20
21
 
22
+ def create_backup_folder
23
+ backup_path = Generator::GctFile.backup_folder_path
24
+ if !File.exist?(backup_path)
25
+ system "mkdir #{backup_path}", exception: true
26
+ puts "#{backup_path} 创建成功!".green
27
+ end
28
+ end
29
+
21
30
  def create_root_folder
22
31
  gct_path = Generator::GctFile.root_folder_path
23
32
  if !File.exist?(gct_path)
@@ -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,5 +1,8 @@
1
- require 'gct/command/update/tag'
1
+ require 'gct/command/update/dependency'
2
+ require 'gct/command/update/podfile'
2
3
  require 'gct/command/update/version'
4
+ require 'gct/command/update/next'
5
+ require 'gct/command/update/tag'
3
6
 
4
7
  module Gct
5
8
  class Command
@@ -0,0 +1,22 @@
1
+ module Gct
2
+ class Command
3
+ class Update < Command
4
+ class Analyze < Update
5
+ self.summary = '编译'
6
+ self.description = <<-DESC
7
+ 下一个优先级打tag
8
+ DESC
9
+
10
+ def initialize(argv)
11
+
12
+ super
13
+ end
14
+
15
+ def run
16
+
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ require 'mysql2'
2
+ module Gct
3
+ class Command
4
+ class Update < Command
5
+ class Dependency < Update
6
+
7
+ self.summary = '更新依赖文件'
8
+ self.description = <<-DESC
9
+ 更新依赖文件
10
+ DESC
11
+
12
+ self.arguments = [
13
+ CLAide::Argument.new('POD_NAME', false),
14
+ CLAide::Argument.new('FIELD', false),
15
+ CLAide::Argument.new('VALUE', false),
16
+ ]
17
+
18
+ def initialize(argv)
19
+ @pod_name = argv.shift_argument
20
+ @field = argv.shift_argument
21
+ @value = argv.shift_argument
22
+ super
23
+ end
24
+
25
+ def validate!
26
+ super
27
+ end
28
+
29
+ def run
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)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ module Gct
2
+ class Command
3
+ class Update < Command
4
+ class Next < Update
5
+ self.summary = '编译'
6
+ self.description = <<-DESC
7
+ 下一个优先级打tag
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ config_gitlab
12
+ @project_name = ENV['CI_PROJECT_NAME']
13
+ super
14
+ end
15
+
16
+ def run
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
31
+ end
32
+
33
+ def batch_tag
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
41
+ puts "tag已全部打完!!!".green
42
+ # 执行更新podfile的操作
43
+ system "gct update podfile"
44
+ else
45
+ result.each do |row|
46
+ if row["tag_status"].eql?(SpecPublishStatus::WAITING) || row["tag_status"].eql?(SpecPublishStatus::CANCELED)
47
+ status = SpecPublishStatus::PENDING
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}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,83 @@
1
+ module Gct
2
+ class Command
3
+ class Update < Command
4
+ class Podfile < Update
5
+
6
+ self.summary = '更新podfile文件'
7
+ self.description = <<-DESC
8
+ 更新podfile文件
9
+ DESC
10
+
11
+ self.arguments = [
12
+ ]
13
+
14
+ def initialize(argv)
15
+ config_gitlab
16
+ @version = argv.shift_argument
17
+ super
18
+ end
19
+
20
+ def validate!
21
+ super
22
+ end
23
+
24
+ def run
25
+ initParams
26
+ update_podfile
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
40
+ end
41
+
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
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
+ end
76
+
77
+ def edit_file(content)
78
+ Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end