gct 0.3.5 → 0.3.91

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: c4c7ac5d299bdcd12bcf268d4f7d703d3cc928ec1bdf68a6a7607eb88776bfa1
4
- data.tar.gz: ec3a3e19a4934758f25b7782b18033a6b5ae7b4011fe7f72a9a0600c6e31ca52
3
+ metadata.gz: 2544c8db653759d99e1ddc1007090e03db770c715f30d9e5f5f770076226ddd0
4
+ data.tar.gz: aee1cfc33e68777d545884cdb0025c2018821d83ecb2668ea33a3e8b51cad34f
5
5
  SHA512:
6
- metadata.gz: 8ee1ec1276911016661047a4e3b85a78e51fbc8fee6d08531075bd26c43d598e4cf066a33712e9af51e9c6a317b5621e76d964a4c931a131f4952295696b4a2d
7
- data.tar.gz: 3a10b473568f55e49de457f50f367010db7742eaf2ecde4684703a66835cbc7a7d10b1dcf8f33c41721a286c660b0aa9c682018e8db0585d4043f5b43f57ff3e
6
+ metadata.gz: ec1ef12cfdf4ff81fa1fb7678da36d05a50657d5dbf4453718270657755330bed58eba1492ea42ca4ad9ce8c829a6083ac92101ce892ae2f0809741eb464fbdd
7
+ data.tar.gz: dd8d0bbf4646aca64790eae2c21aa9910f7912ee202f0a9547048978190813c1bcca6a19e338ce6865d3c73931e72bb0875ad8ae5783dfda8ca8d11b8002c29c
@@ -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 set token xxx,参考文档: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,54 @@
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 initialize(argv)
19
+ @project_name = ENV['CI_PROJECT_NAME']
20
+ @user_name = ENV['GITLAB_USER_NAME']
21
+ @tag = ENV['CI_COMMIT_REF_NAME']
22
+ @build_status = argv.shift_argument
23
+ @commit_sha = ENV['CI_COMMIT_SHA']
24
+ @ci_url = ENV['CI_PIPELINE_URL']
25
+ super
26
+ end
27
+
28
+ def run
29
+ build_text = @build_status ? "<font color=\"info\">CI运行成功</font>" : "<font color=\"comment\">CI运行失败</font>,请相关人员注意"
30
+ ci_text = "[点击跳转](#{@ci_url})"
31
+
32
+ webhook = FileBase.get_config("gitlab-robot-webhook")
33
+ url = URI(webhook)
34
+
35
+ http = Net::HTTP.new(url.host, url.port)
36
+ if url.scheme == "https"
37
+ http.use_ssl = true
38
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
+ end
40
+
41
+ data = {
42
+ "msgtype": "markdown",
43
+ "markdown": {
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
+ }
46
+ }.to_json
47
+
48
+ header = {'content-type':'application/json'}
49
+ response = http.post(url, data, header)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
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 initialize(argv)
18
+ @project_name = ENV['CI_PROJECT_NAME']
19
+ @tag = ENV['CI_COMMIT_REF_NAME']
20
+ super
21
+ end
22
+
23
+ def run
24
+ webhook = FileBase.get_config("gitlab-robot-webhook")
25
+ raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty?
26
+ url = URI(webhook)
27
+
28
+ http = Net::HTTP.new(url.host, url.port)
29
+ if url.scheme == "https"
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+ end
33
+
34
+ message = " <font color=\"info\">#{@tag}</font> 开始打tag"
35
+ data = {
36
+ "msgtype": "markdown",
37
+ "markdown": {
38
+ "content": "**#{@project_name}** #{message}"
39
+ }
40
+ }.to_json
41
+
42
+ header = {'content-type':'application/json'}
43
+ response = http.post(url, data, header)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ 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,8 +11,12 @@ module Gct
11
11
  DESC
12
12
 
13
13
  def initialize(argv)
14
+ gitlab_error
14
15
  super
15
- config_gitlab
16
+ end
17
+
18
+ def run
19
+
16
20
  end
17
21
  end
18
22
  end
@@ -9,41 +9,109 @@ 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)
24
+ @update_version_branch = 'develop'
25
+ @skip_tag = argv.flag?('skip-tag', false)
26
+ @update_ci = argv.flag?('update-ci', false)
27
+ @file = get_spec_file
28
+ name = argv.shift_argument
29
+ @name = name.nil? ? @spec.name : name
16
30
  @tag = argv.shift_argument
31
+ @project_id = "#{Constant.NameSpace}#{@name}"
17
32
  super
18
33
  end
19
34
 
20
- def validate!
21
- 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
22
42
  end
23
43
 
24
- def run
25
- get_now_tag
26
- add_push_new_tag
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
27
49
  end
28
50
 
29
- def update_tag_podspec
30
- # 更新podspec的版本号 @new_tag 创建MR推送到远端
31
-
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
32
59
  end
33
60
 
34
- def get_now_tag
61
+ def get_spec_file
35
62
  spec_file = Pathname.glob('*.podspec').first
36
63
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
37
64
 
38
- spec = Pod::Specification.from_file(spec_file)
39
- @now_tag = spec.version
65
+ @spec = Pod::Specification.from_file(spec_file)
66
+ spec_file
67
+ end
68
+
69
+ def update_podspec_version
70
+ puts "开始读取podspec文件...".green
71
+ podspec_content = file_contents(@project_id, @file, @update_version_branch)
72
+ version_regex = /.*version.*/
73
+ version_match = version_regex.match(podspec_content).to_s
74
+ tag_regex = /(?<=')\w.*(?=')/
75
+ tag = tag_regex.match(version_match)
76
+ @now_tag = tag
77
+ @new_tag = @tag || auto_add_tag(tag.to_s)
78
+ replace_string = version_match.gsub(tag_regex, @new_tag)
79
+ updated_podspec_content = podspec_content.gsub(version_match, replace_string)
80
+ puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
81
+ edit_file(@file, updated_podspec_content, "@config 更新版本号:#{@new_tag}")
82
+ mr_to_master
83
+ accept_merge_request
84
+ create_tag
85
+ end
86
+
87
+ def edit_file(file, content, commit_message)
88
+ Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
89
+ end
90
+
91
+ def mr_to_master
92
+ puts "正在创建MR请求将develop分支合并到master!".green
93
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "更新版本podpesc版本号", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
94
+ @id = mr.iid
95
+ puts mr.merge_status
96
+ if mr.merge_status == 'cannot_be_merged'
97
+ raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
98
+ end
99
+ end
100
+
101
+ def accept_merge_request
102
+ mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
103
+ if mr_result.state == 'merged'
104
+ puts "成功合并到master分支".green
105
+ end
106
+ end
107
+
108
+ def delete_tag
109
+ Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
40
110
  end
41
111
 
42
- def add_push_new_tag
43
- @new_tag = @tag || auto_add_tag(@now_tag.to_s)
44
- update_tag_podspec
45
- `git tag #{@new_tag}`
46
- `git push origin #{@new_tag} || { exit 1; }`
112
+ def create_tag
113
+ Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "master")
114
+ puts "打tag成功,开始上传podspec...".green
47
115
  end
48
116
  end
49
117
  end
@@ -9,8 +9,8 @@ module Gct
9
9
  DESC
10
10
 
11
11
  self.arguments = [
12
- CLAide::Argument.new('NAME', false),
13
12
  CLAide::Argument.new('VERSION', false),
13
+ CLAide::Argument.new('NAME', false),
14
14
  ]
15
15
 
16
16
  def initialize(argv)
@@ -32,7 +32,12 @@ module Gct
32
32
  end
33
33
 
34
34
  def update_version
35
- if check_branch_can_be_update
35
+ puts @project_id
36
+ puts @file
37
+ puts @branch
38
+ content = file_contents(@project_id, @file, @branch)
39
+ puts content
40
+ if check_branch_can_be_update('release')
36
41
  content = file_contents(@project_id, @file, @branch)
37
42
  version_var_name = 'MARKETING_VERSION = '
38
43
  version_regex = /(?<=#{version_var_name})\w.*(?=;)/
@@ -40,24 +45,12 @@ module Gct
40
45
  version = @version ||= auto_add_tag(version_match)
41
46
  updated_content = content.gsub(version_regex, version)
42
47
  edit_file(updated_content, version)
43
- else
44
- puts "当前不是release分支".red
45
48
  end
46
49
  end
47
50
 
48
51
  def edit_file(content, version)
49
52
  Gitlab.edit_file(@project_id, @file, @branch, content, "@config 更新版本号:#{version}")
50
53
  end
51
-
52
- def check_branch_can_be_update
53
- current_branch.include?('release')
54
- end
55
-
56
- def current_branch
57
- branch = "#{`git branch | awk '$1 == "*" {print $2}'`}".rstrip
58
- raise "该文件夹不是一个git仓库".red if branch.empty?
59
- branch
60
- end
61
54
  end
62
55
  end
63
56
  end
@@ -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.nil? || config_map.empty?
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.5".freeze unless defined? Gct::VERSION
5
+ VERSION = "0.3.91".freeze unless defined? Gct::VERSION
6
6
  end
@@ -1,17 +1,16 @@
1
1
  module Gct
2
2
  module Generator
3
3
  class GctFile
4
-
5
4
  def self.root_folder_path
6
- "/Users/#{get_system_user_name.rstrip}/.gct"
5
+ "#{get_system_home_path.rstrip}/.gct"
7
6
  end
8
7
 
9
8
  def self.temp_folder_path
10
- "/Users/#{get_system_user_name.rstrip}/.gct/tmp"
9
+ "#{get_system_home_path.rstrip}/.gct/tmp"
11
10
  end
12
11
 
13
12
  def self.config_file_path
14
- "/Users/#{get_system_user_name.rstrip}/.gct/config"
13
+ "#{get_system_home_path.rstrip}/.gct/config"
15
14
  end
16
15
 
17
16
  # 获取系统用户名
@@ -27,6 +26,10 @@ module Gct
27
26
  end
28
27
  end
29
28
 
29
+ def self.get_system_home_path
30
+ "#{`echo ~`}"
31
+ end
32
+
30
33
  end
31
34
  end
32
35
  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.5
4
+ version: 0.3.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - jieming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 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