gct 0.3.7 → 0.3.93

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9918181f11fe9f5b6bcfbce81bccd2968f62d3ff6818b14a89697477c4708bf6
4
- data.tar.gz: cec3e19ab6d35eec9b0be4381ccbdcae73476b18406e41ea990b624899720ffd
3
+ metadata.gz: a90278a27edf99a940f703b359f26160c3534f51bb8e3ad7dc2b9af240209fe1
4
+ data.tar.gz: 9a62537fadb1678a6d8c1969e1b487c844117b1e58c9089038ccc9bbcaba8328
5
5
  SHA512:
6
- metadata.gz: ec151c785207033293bad1b7381328919fbf78f5f80bb7fbe24dbb093d743549aedb797d2447dfb46b5135f97a90e112a9a1e719733dfc5a7641896447c26541
7
- data.tar.gz: 1d0427577f8d39417823890a81e0911e28dfbd7570f76d5ef1a49f5470f1a385d1383447f9102fbbbb6a877827e9aeca4b287a5ebb28e5b109a9919d5700a1c7
6
+ metadata.gz: acfa21c1c8cc42efc63f2d06fd49799146e8a17f6fcbcefc7480a9d2579db448280cdd78ea035bcb9906ab0facaa00926452fe429f7733c35c54b035ca6c411d
7
+ data.tar.gz: feafb9b42ecdbc68b5dd91ef4415ebb6d0b0f871a0e70f11fe49537ecfa1319ad282bf1dca09c5c42974ff203c6123dbb3a0bf78b3c749657f0be9fcfff9801c
@@ -19,13 +19,14 @@ module Gct
19
19
  require 'gct/command/create'
20
20
  require 'gct/command/init'
21
21
  require 'gct/command/config'
22
- # require 'gct/command/analyze'
22
+ require 'gct/command/autotag'
23
23
  require 'gct/command/op'
24
24
  require 'gct/command/build'
25
25
  require 'gct/command/spec'
26
26
  require 'gct/command/repo'
27
27
  require 'gct/command/setup'
28
28
  require 'gct/command/update'
29
+ require 'gct/command/robot'
29
30
 
30
31
  self.abstract_command = true
31
32
  self.command = 'gct'
@@ -50,6 +51,8 @@ module Gct
50
51
  Colored2.disable!
51
52
  String.send(:define_method, :colorize) { |string, _| string }
52
53
  end
54
+
55
+ config_gitlab
53
56
  end
54
57
 
55
58
  def file_contents(project_id, file, branch)
@@ -59,20 +62,19 @@ module Gct
59
62
  end
60
63
 
61
64
  def config_gitlab
62
- if FileBase.exist_root
63
- token = FileBase.get_config("token")
64
- if token
65
- raise "请先配置token!gct config set token GITLAB_PERSON_TOKEN".red if token.nil?
66
- Gitlab.configure do |config|
67
- config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
68
- config.private_token = token
69
- end
70
- else
71
- raise "请先运行命令:gct config set token GITLAB_TOKEN,参考文档:http://febase.crgt.xyz/docs/app_ios/base".red
65
+ if FileBase.exist_root and token and Gitlab.endpoint.nil?
66
+ Gitlab.configure do |config|
67
+ config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
68
+ config.private_token = token
72
69
  end
73
70
  end
74
71
  end
75
72
 
73
+ def gitlab_error
74
+ FileBase.root_err
75
+ token_err
76
+ end
77
+
76
78
  def get_project
77
79
  proj = nil
78
80
  Dir.entries(Dir.pwd).each do |subfile|
@@ -102,5 +104,28 @@ module Gct
102
104
  end
103
105
  tag_points.join('.')
104
106
  end
107
+
108
+ def current_branch
109
+ branch = "#{`git branch | awk '$1 == "*" {print $2}'`}".rstrip
110
+ raise "该文件夹不是一个git仓库".red if branch.empty?
111
+ branch
112
+ end
113
+
114
+ def check_branch_can_be_update(branch)
115
+ can_be_update = current_branch.include?(branch)
116
+
117
+ puts "当前不是#{branch}分支".red if !can_be_update
118
+
119
+ can_be_update
120
+ end
121
+
122
+ private
123
+ def token
124
+ FileBase.get_config("token")
125
+ end
126
+
127
+ def token_err
128
+ raise "请先运行命令:gct config set token GITLAB_TOKEN,参考文档:http://febase.crgt.xyz/docs/app_ios/base".red if token.nil?
129
+ end
105
130
  end
106
131
  end
@@ -0,0 +1,161 @@
1
+ require 'pathname'
2
+ require 'tmpdir'
3
+ require 'parallel'
4
+
5
+ module Gct
6
+ class Command
7
+ class Autotag < Command
8
+ self.summary = '分析podfile完整依赖链'
9
+ self.description = <<-DESC
10
+ 分析podfile完整依赖链,并输出json文件.
11
+ DESC
12
+
13
+ self.arguments = [
14
+ CLAide::Argument.new('PROJECT_ID', true),
15
+ CLAide::Argument.new('BRANCH', true),
16
+ ]
17
+
18
+ def initialize(argv)
19
+ gitlab_error
20
+ @update_ci = argv.flag?('update-ci', false)
21
+ @project_id = "ios/#{argv.shift_argument}"
22
+ @branch = argv.shift_argument
23
+ @file = 'Podfile'
24
+ super
25
+ end
26
+
27
+ def self.options
28
+ [
29
+ ['--update-ci', '是否更新CI']
30
+ ].concat(super)
31
+ end
32
+
33
+ def validate!
34
+ super
35
+ help! '请输入项目名.' unless @project_id
36
+ help! '请输入分支名.' unless @branch
37
+ end
38
+
39
+ def run
40
+ FileBase.root_err
41
+ analyze_dependencies
42
+ end
43
+
44
+ def check_branch(branch)
45
+ ret = @branch.include?(branch)
46
+ raise "当前不是发布分支".red if !ret
47
+ end
48
+
49
+ def podfile
50
+ # if check_branch_can_be_update('zeus')
51
+ if check_branch('ft/tag') # TODO: Test branch
52
+ contents = file_contents(@project_id, @file, @branch)
53
+ contents.force_encoding('UTF-8')
54
+ puts contents
55
+ temp_local_file = TempLocalFile.new(contents, @file)
56
+ temp_local_file.write
57
+ full_path = temp_local_file.full_path
58
+
59
+ @podfile ||= begin
60
+ podfile = Pod::Podfile.from_ruby(full_path, contents)
61
+ podfile
62
+ end
63
+ end
64
+ end
65
+
66
+ def analyze_dependencies
67
+ untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
68
+
69
+ untagged_specs = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
70
+ file_name = "#{dep.name}.podspec"
71
+ podspec_contents = file_contents("#{Constant.NameSpace}#{dep.name}", file_name, Constant.DefaultTagBranch)
72
+ temp_local_spec_file = TempLocalFile.new(podspec_contents, file_name)
73
+ temp_local_spec_file.write
74
+ spec_file = temp_local_spec_file.full_path
75
+
76
+ # 创建podspec对象
77
+ spec = Pod::Specification.from_file(spec_file)
78
+ gct_spec = Specification.new()
79
+ gct_spec.name = spec.name
80
+ gct_spec.priority = 1000
81
+ gct_spec.status = SpecPublishStatus::CREATED
82
+ gct_spec.tag = "0"
83
+ dependencySpecs = Array.new()
84
+ if spec.subspecs.length == 0
85
+ dependencySpecs = spec.dependencies.map do |dep|
86
+ sub_spec = Specification.new()
87
+ sub_spec.name = dep.root_name
88
+ sub_spec.priority = 1000
89
+ sub_spec.status = SpecPublishStatus::CREATED
90
+ sub_spec.tag = "0"
91
+ sub_spec
92
+ end
93
+ else
94
+ temp_arr = Array.new()
95
+ spec.subspecs.map do |subspec|
96
+ arr = subspec.dependencies.map do |dep|
97
+ sub_spec = Specification.new()
98
+ sub_spec.name = dep.root_name
99
+ sub_spec.priority = 1000
100
+ sub_spec.status = SpecPublishStatus::CREATED
101
+ sub_spec.tag = "0"
102
+ sub_spec
103
+ end
104
+ temp_arr.concat(arr)
105
+ end
106
+ dependencySpecs = temp_arr
107
+ end
108
+ gct_spec.dependencySpecs = dependencySpecs
109
+ gct_spec
110
+ end
111
+
112
+ priority_rank(untagged_specs)
113
+ end
114
+
115
+ def eqlBetweenHash(hash1, hash2)
116
+ iseql = true
117
+ if hash1.empty? || hash2.empty?
118
+ return false
119
+ end
120
+ hash1.keys.map do |key|
121
+ if hash1[key].priority != hash2[key].priority
122
+ iseql = false
123
+ return iseql
124
+ end
125
+ end
126
+ !hash2.empty?
127
+ end
128
+
129
+ # 优先级排序
130
+ def priority_rank(specs)
131
+ temp_spec_map = Hash.new()
132
+ specs.map do |spec|
133
+ temp_spec_map[spec.name] = spec
134
+ end
135
+ temp_spec_map_copy = Hash.new()
136
+ count = 1
137
+
138
+ while !(eqlBetweenHash(temp_spec_map, temp_spec_map_copy)) do
139
+ # 深拷贝
140
+ temp_spec_map_copy = Marshal.load(Marshal.dump(temp_spec_map))
141
+ puts "--- times == #{count} ---"
142
+ specs.map do |spec|
143
+ temp_spec = temp_spec_map[spec.name]
144
+ spec.dependencySpecs.map do |subspec|
145
+ temp_sub_spec = temp_spec_map[subspec.name]
146
+ if temp_sub_spec && temp_sub_spec.name != temp_spec.name
147
+ if temp_spec.priority >= temp_sub_spec.priority - 1
148
+ temp_spec.priority = temp_sub_spec.priority - 1
149
+ end
150
+ end
151
+ end
152
+ end
153
+ count += 1
154
+ temp_spec_map.each { |key, value|
155
+ puts "#{key} => #{value.priority}"
156
+ }
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -52,7 +52,7 @@ module Gct
52
52
  puts "git命令为:<-- git clone #{branch} #{@url} -->".green
53
53
  `git clone #{branch} #{@url}`
54
54
  Dir.chdir(path) do
55
- git_url = "#{Constant.GitURL}#{dir}"
55
+ git_url = "#{Constant.GitThirdURL}#{dir}"
56
56
  `git init`
57
57
  `git remote set-url origin #{git_url}.git`
58
58
  `git add .`
@@ -1,13 +1,24 @@
1
1
  stages:
2
2
  - push
3
+ - failure
3
4
 
4
5
  push_pod:
5
6
  stage: push
6
7
  script:
8
+ - gct robot start
7
9
  - echo "开始lint 和 push podspec"
8
10
  - gct repo update
9
11
  - gct repo push
12
+ - gct robot finish true
10
13
  only:
11
- - master
14
+ - tags
15
+ tags:
16
+ - iOS
17
+
18
+ on_failure:
19
+ stage: failure
20
+ script:
21
+ - gct robot finish false
22
+ when: on_failure
12
23
  tags:
13
24
  - iOS
@@ -0,0 +1,14 @@
1
+ require 'gct/command/robot/start'
2
+ require 'gct/command/robot/finish'
3
+
4
+ module Gct
5
+ class Command
6
+ class Robot < Command
7
+ self.abstract_command = true
8
+ self.summary = '企微机器人相关操作'
9
+ self.description = <<-DESC
10
+ 发送jenkins和gitlab机器人消息
11
+ DESC
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,66 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ module Gct
5
+ class Command
6
+ class Robot < Command
7
+ class Finish < Robot
8
+
9
+ self.summary = 'jenkins 企微机器人通知'
10
+ self.description = <<-DESC
11
+ jenkins 企微机器人通知
12
+ DESC
13
+
14
+ self.arguments = [
15
+ CLAide::Argument.new('BUILD_STATUS', true),
16
+ ]
17
+
18
+ def self.options
19
+ [
20
+ ['--test', '测试机器人,测试webhook'],
21
+ ].concat(super)
22
+ end
23
+
24
+ def initialize(argv)
25
+ @project_name = ENV['CI_PROJECT_NAME']
26
+ @user_name = ENV['GITLAB_USER_NAME']
27
+ @tag = ENV['CI_COMMIT_REF_NAME']
28
+ @build_status = argv.shift_argument
29
+ @commit_sha = ENV['CI_COMMIT_SHA']
30
+ @ci_url = ENV['CI_PIPELINE_URL']
31
+ @test = argv.flag?('test', false)
32
+ super
33
+ end
34
+
35
+ 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
51
+ 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)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,59 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ module Gct
5
+ class Command
6
+ class Robot < Command
7
+ class Start < 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
+ @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
+ 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
+ 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)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -22,7 +22,8 @@ module Gct
22
22
  end
23
23
 
24
24
  def run
25
- 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
26
27
  end
27
28
 
28
29
  def generate_podfile(pod_name, spec_path)
@@ -11,22 +11,12 @@ module Gct
11
11
  DESC
12
12
 
13
13
  def initialize(argv)
14
+ gitlab_error
14
15
  super
15
- config_gitlab
16
16
  end
17
17
 
18
- def current_branch
19
- branch = "#{`git branch | awk '$1 == "*" {print $2}'`}".rstrip
20
- raise "该文件夹不是一个git仓库".red if branch.empty?
21
- branch
22
- end
23
-
24
- def check_branch_can_be_update(branch)
25
- can_be_update = current_branch.include?(branch)
26
-
27
- puts "当前不是#{branch}分支".red if !can_be_update
28
-
29
- can_be_update
18
+ def run
19
+
30
20
  end
31
21
  end
32
22
  end
@@ -9,23 +9,53 @@ module Gct
9
9
  DESC
10
10
 
11
11
  self.arguments = [
12
+ CLAide::Argument.new('NAME', false),
12
13
  CLAide::Argument.new('TAG', false),
13
14
  ]
14
15
 
16
+ def self.options
17
+ [
18
+ ['--skip-tag', '是否忽略tag,直接触发ci'],
19
+ ['--update-ci', '是否更新CI'],
20
+ ].concat(super)
21
+ end
22
+
15
23
  def initialize(argv)
16
- @tag = argv.shift_argument
17
24
  @update_version_branch = 'develop'
25
+ @skip_tag = argv.flag?('skip-tag', false)
26
+ @update_ci = argv.flag?('update-ci', false)
18
27
  @file = get_spec_file
19
- @project_id = "#{Constant.NameSpace}#{@spec.name}"
28
+ name = argv.shift_argument
29
+ @name = name.nil? ? @spec.name : name
30
+ @tag = argv.shift_argument
31
+ @project_id = "#{Constant.NameSpace}#{@name}"
20
32
  super
21
33
  end
22
34
 
23
- def validate!
24
- super
35
+ def run
36
+ update_ci_method if @update_ci
37
+ if @skip_tag
38
+ skip_tag_method
39
+ else
40
+ update_podspec_version
41
+ end
25
42
  end
26
43
 
27
- def run
28
- update_podspec_version
44
+ def skip_tag_method
45
+ @new_tag = @spec.version
46
+ puts "tag == #{@new_tag}"
47
+ delete_tag # remove tag
48
+ create_tag # create tag
49
+ end
50
+
51
+ def update_ci_method
52
+ puts "更新ci文件".green
53
+ temp_local_file = TempLocalFile.new()
54
+ path = File.expand_path("../../init", __FILE__)
55
+ ci_content = temp_local_file.read_path_file(path, "gitlab-ci.rb")
56
+ edit_file('.gitlab-ci.yml', ci_content, 'update ci')
57
+ mr_to_master
58
+ accept_merge_request
29
59
  end
30
60
 
31
61
  def get_spec_file
@@ -46,34 +76,37 @@ module Gct
46
76
  @now_tag = tag
47
77
  @new_tag = @tag || auto_add_tag(tag.to_s)
48
78
  replace_string = version_match.gsub(tag_regex, @new_tag)
49
- @updated_podspec_content = podspec_content.gsub(version_match, replace_string)
79
+ updated_podspec_content = podspec_content.gsub(version_match, replace_string)
50
80
  puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
51
- edit_file
81
+ edit_file(@file, updated_podspec_content, "@config 更新版本号:#{@new_tag}")
52
82
  mr_to_master
83
+ accept_merge_request
84
+ create_tag
53
85
  end
54
86
 
55
- def edit_file
56
- Gitlab.edit_file(@project_id, @file, @update_version_branch, @updated_podspec_content, "@config 更新版本号:#{@new_tag}")
87
+ def edit_file(file, content, commit_message)
88
+ Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
57
89
  end
58
90
 
59
91
  def mr_to_master
60
92
  puts "正在创建MR请求将develop分支合并到master!".green
61
- mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@spec.name}", "更新版本podpesc版本号", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
93
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "更新版本podpesc版本号", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
62
94
  @id = mr.iid
63
95
  puts mr.merge_status
64
96
  if mr.merge_status == 'cannot_be_merged'
65
- raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@spec.name}/merge_requests/#{@id} 解决".red
97
+ raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
66
98
  end
67
-
68
- mr_result = accept_merge_request
99
+ end
100
+
101
+ def accept_merge_request
102
+ mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
69
103
  if mr_result.state == 'merged'
70
104
  puts "成功合并到master分支".green
71
- create_tag
72
105
  end
73
106
  end
74
-
75
- def accept_merge_request
76
- Gitlab.accept_merge_request("#{@project_id}", @id)
107
+
108
+ def delete_tag
109
+ Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
77
110
  end
78
111
 
79
112
  def create_tag
@@ -9,8 +9,11 @@ module Gct
9
9
 
10
10
  def yaml_write(key, value)
11
11
  begin
12
+ config_map = YAML.load(File.open(@path, "r"))
13
+ config_map = Hash.new() if !config_map
14
+ config_map[key] = value
12
15
  yaml_file = File.open(@path, "w")
13
- YAML::dump({key => value}, yaml_file)
16
+ YAML::dump(config_map, yaml_file)
14
17
  rescue IOError => e
15
18
  raise e.message
16
19
  ensure
@@ -30,17 +33,15 @@ module Gct
30
33
  end
31
34
 
32
35
  def get_config(key)
33
- if exist_root
34
- @path = config_path
35
- yaml_read(key)
36
- end
36
+ root_err
37
+ @path = config_path
38
+ yaml_read(key)
37
39
  end
38
40
 
39
41
  def set_config(key, value)
40
- if exist_root
41
- @path = config_path
42
- yaml_write(key, value)
43
- end
42
+ root_err
43
+ @path = config_path
44
+ yaml_write(key, value)
44
45
  end
45
46
 
46
47
  def config_path
@@ -49,9 +50,12 @@ module Gct
49
50
 
50
51
  def exist_root
51
52
  root_exist = File.exist?(Generator::GctFile.root_folder_path)
52
- raise "请先运行命令:gct setup".red if !root_exist
53
53
  root_exist
54
54
  end
55
+
56
+ def root_err
57
+ raise "请先运行命令:gct setup".red if !exist_root
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -2,5 +2,5 @@ module Gct
2
2
  # freeze 冻结对象,将对象变成一个常量
3
3
  # unless 右边的代码块成立,才会运行左边的代码块
4
4
  # defined? 是用来判断本地变量是否存在,也可用来判断是否存在方法
5
- VERSION = "0.3.7".freeze unless defined? Gct::VERSION
5
+ VERSION = "0.3.93".freeze unless defined? Gct::VERSION
6
6
  end
@@ -3,8 +3,6 @@ module Gct
3
3
  # attr_reader only get
4
4
  # attr_writer only set
5
5
  class Specification
6
- # Pod::Dependency
7
- attr_accessor :specification
8
6
 
9
7
  # 优先级
10
8
  attr_accessor :priority
@@ -15,11 +13,18 @@ module Gct
15
13
  # 发布状态
16
14
  attr_accessor :status
17
15
 
16
+ # 依赖specs
17
+ attr_accessor :dependencySpecs
18
+
19
+ # spec name
20
+ attr_accessor :name
21
+
18
22
  def initialize()
19
- @specification = specification
20
23
  @priority = priority
21
24
  @status = status
22
25
  @tag = tag
26
+ @dependencySpecs = dependencySpecs
27
+ @name = name
23
28
  end
24
29
  end
25
30
  end
@@ -1,10 +1,10 @@
1
1
  module Gct
2
2
  class TempLocalFile
3
- attr_reader :content
3
+ attr_accessor :content
4
4
 
5
- attr_reader :file_name
5
+ attr_accessor :file_name
6
6
 
7
- def initialize(content, file_name)
7
+ def initialize(content = '', file_name = '')
8
8
  @content = content
9
9
  @file_name = file_name
10
10
  end
@@ -31,6 +31,17 @@ module Gct
31
31
  end
32
32
  end
33
33
 
34
+ def read_path_file(path, file)
35
+ begin
36
+ file = File.new(File.join(path, file), "r")
37
+ file.read
38
+ rescue IOError => e
39
+ raise e.message
40
+ ensure
41
+ file.close unless file.nil?
42
+ end
43
+ end
44
+
34
45
  def full_path
35
46
  tmp_folder
36
47
  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.3.7
4
+ version: 0.3.93
5
5
  platform: ruby
6
6
  authors:
7
7
  - jieming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,7 +146,7 @@ files:
146
146
  - bin/gct
147
147
  - lib/gct.rb
148
148
  - lib/gct/command.rb
149
- - lib/gct/command/analyze.rb
149
+ - lib/gct/command/autotag.rb
150
150
  - lib/gct/command/build.rb
151
151
  - lib/gct/command/build/r.rb
152
152
  - lib/gct/command/config.rb
@@ -169,6 +169,9 @@ files:
169
169
  - lib/gct/command/repo/add.rb
170
170
  - lib/gct/command/repo/push.rb
171
171
  - lib/gct/command/repo/update.rb
172
+ - lib/gct/command/robot.rb
173
+ - lib/gct/command/robot/finish.rb
174
+ - lib/gct/command/robot/start.rb
172
175
  - lib/gct/command/setup.rb
173
176
  - lib/gct/command/spec.rb
174
177
  - lib/gct/command/spec/lint.rb
@@ -1,128 +0,0 @@
1
- require 'pathname'
2
- require 'tmpdir'
3
- require 'parallel'
4
-
5
- module Gct
6
- class Command
7
- class Analyze < Command
8
- self.summary = '分析podfile完整依赖链'
9
- self.description = <<-DESC
10
- 分析podfile完整依赖链,并输出json文件.
11
- DESC
12
-
13
- self.arguments = [
14
- CLAide::Argument.new('PROJECT_ID', true),
15
- CLAide::Argument.new('FILE', true),
16
- CLAide::Argument.new('BRANCH', true),
17
- ]
18
-
19
- def initialize(argv)
20
- @project_id = argv.shift_argument
21
- @file = argv.shift_argument
22
- @branch = argv.shift_argument
23
- config_gitlab
24
- super
25
- end
26
-
27
- def self.options
28
- [
29
- ].concat(super)
30
- end
31
-
32
- def validate!
33
- help! '必须输入项目名.' unless @project_id
34
- help! '必须输入读取文件的相对路径.' unless @file
35
- help! '必须输入读取文件的项目分支.' unless @branch
36
- super
37
- end
38
-
39
- def run
40
- analyze_dependencies
41
- # update_podspec_version()
42
- end
43
-
44
- def podfile
45
- contents = file_contents(@project_id, @file, @branch)
46
- contents.force_encoding('UTF-8')
47
-
48
- temp_local_file = TempLocalFile.new(contents, @file)
49
- temp_local_file.write
50
- full_path = temp_local_file.full_path
51
-
52
- @podfile ||= begin
53
- podfile = Pod::Podfile.from_ruby(full_path, contents)
54
- podfile
55
- end
56
- end
57
-
58
- def analyze_dependencies
59
- untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
60
- puts untagged_git_dependencies
61
- # untagged_specs = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
62
- # require 'json'
63
- # puts "#{Constant.NameSpace}#{dep.name}"
64
- # puts "#{dep.name}.podspec"
65
- # puts Constant.DefaultTagBranch
66
-
67
- # contents_json = file_contents("#{Constant.NameSpace}#{dep.name}", "#{dep.name}.podspec", Constant.DefaultTagBranch)
68
- # podspec = system contents_json
69
- # puts podspec.class
70
- # puts podspec
71
- # podspec = from_string("", contents_json)
72
- # podspec = Pod::Spec.new do |spec|
73
-
74
- # end
75
-
76
-
77
- # puts podspec.class.to_s
78
- # puts podspec.to_s
79
- # gct_spec = Specification.new()
80
- # gct_spec.specification = podspec
81
- # gct_spec.priority = 1000
82
- # gct_spec.status = SpecPublishStatus::CREATED
83
- # gct_spec.tag = "0"
84
-
85
- # update_podspec_version(spec)
86
- # gct_spec
87
- # end
88
- end
89
-
90
- def update_podspec_version(spec)
91
- content = file_contents("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch)
92
- now_version = spec.version
93
- version = auto_add_tag(now_version)
94
- require_variable_prefix = true
95
- version_var_name = 'version'
96
- variable_prefix = require_variable_prefix ? /\w\./ : //
97
- version_regex = /^(?<begin>[^#]*#{variable_prefix}#{version_var_name}\s*=\s*['"])(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?(?<appendix>(\.[0-9]+)*)?(-(?<prerelease>(.+)))?)(?<end>['"])/i
98
- version_match = version_regex.match(content)
99
- updated_podspec_content = content.gsub(version_regex, "#{version_match[:begin]}#{version}#{version_match[:end]}")
100
- updated_podspec_content
101
-
102
- edit_file(spec, updated_podspec_content, version)
103
- mr_to_master(spec)
104
- end
105
-
106
-
107
-
108
- def edit_file(spec, content, version)
109
- Gitlab.edit_file("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch, content, "@config 升级版本号:#{version}")
110
- end
111
-
112
- def mr_to_master(spec)
113
- mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{dep.name}", "podpesc修改", { source_branch: 'develop', target_branch: 'master' })
114
- id = mr.iid
115
- puts mr.to_hash
116
- if mr.merge_status == 'cannot_be_merged'
117
- raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{spec.name}/merge_requests/#{id} 解决".red
118
- end
119
-
120
- accept_merge_request(spec, id)
121
- end
122
-
123
- def accept_merge_request(spec, id)
124
- Gitlab.accept_merge_request("#{Constant.NameSpace}#{dep.name}", id)
125
- end
126
- end
127
- end
128
- end