gct 0.4.0 → 0.4.1

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: 61f99077edb53ba0cf05eca381a814b9f41a17ecc191cc68a1950c2402dff1b7
4
+ data.tar.gz: 3132fd74ec8fd026ea13921f717e68c8f7bbb4aba1ee1265ba057eef823cd8cd
5
5
  SHA512:
6
- metadata.gz: d93d45b1ffee87733b11bc2f70fc4c35fb510c99bece66196d87b49dadb98f7a9648bb2a407cc78e98223ffbeafb1523f120ff8fec7b4ca127e9eb461a6dad24
7
- data.tar.gz: 606a302705d5305cb8d5260d489d551794ffedabea91b7da81bc7ea66cc31042d2dad835a6fd6edccc82369b45d7e4ba5de55a35fceb3b520d29468a73a36115
6
+ metadata.gz: 92432f4c66aa5d9a19c27c0c5c22ceb53253ff118e34586934516790134474d3f0c9360ef8dad2b51e8c7cd737d0441e1c019942ff8d4f94d2449d33d109ec19
7
+ data.tar.gz: 83d92ca4f72529e5be6db516fc667bc9dbddc6783e29aa0eaac68f109d91df346545b0c52be5fc14759b2cd03603f86ea8fcd94320e4f6e00ed23f83dd7f569e
@@ -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
@@ -13,13 +13,18 @@ module Gct
13
13
  self.arguments = [
14
14
  CLAide::Argument.new('PROJECT_ID', true),
15
15
  CLAide::Argument.new('BRANCH', true),
16
+ CLAide::Argument.new('VERSION', true),
16
17
  ]
17
18
 
18
19
  def initialize(argv)
19
20
  gitlab_error
21
+ config_gitlab
20
22
  @update_ci = argv.flag?('update-ci', false)
21
- @project_id = "ios/#{argv.shift_argument}"
23
+ name = argv.shift_argument
24
+ @project_id = "ios/#{name}"
25
+ @project_name = name
22
26
  @branch = argv.shift_argument
27
+ @version = argv.shift_argument
23
28
  @file = 'Podfile'
24
29
  super
25
30
  end
@@ -34,12 +39,14 @@ module Gct
34
39
  super
35
40
  help! '请输入项目名.' unless @project_id
36
41
  help! '请输入分支名.' unless @branch
42
+ help! '请输入版本号.' unless @version
37
43
  end
38
44
 
39
45
  def run
40
46
  FileBase.root_err
41
47
  puts "开始分析podfile文件".green
42
48
  puts ""
49
+ FileBase.write_version_message(@version, @project_name, @branch)
43
50
  exist_dep = FileBase.exist_dependency
44
51
  if exist_dep
45
52
  tmp_podspecs
@@ -62,6 +69,7 @@ module Gct
62
69
  # if check_branch_can_be_update('zeus')
63
70
  # if check_branch('ft/tag') # TODO: Test branch
64
71
  contents = file_contents(@project_id, @file, @branch)
72
+ # puts contents
65
73
  contents.force_encoding('UTF-8')
66
74
  temp_local_file = TempLocalFile.new(contents, @file)
67
75
  temp_local_file.write
@@ -196,14 +204,17 @@ module Gct
196
204
  # 按优先级打tag, 触发第一个优先级,其他的上一优先级打完之后自动触发
197
205
  def create_tag_by_priority(priority_map)
198
206
  priority = get_current_need_tag_priority
207
+ puts "priority is #{priority}"
199
208
  value = priority_map[priority.to_s]
200
209
  raise "没有需要打tag的库".red if value.keys.count == 0
201
210
  value.each do |key, val|
202
211
  if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
212
+ is_skip = val["status"].eql?(SpecPublishStatus::FAILED) || val["status"].eql?(SpecPublishStatus::CANCELED)
203
213
  status = SpecPublishStatus::PENDING
204
214
  val["status"] = status
205
- system "gct update dependency #{key} status #{status}"
206
- system "gct update tag #{key} --auto-tag"
215
+ system "gct update dependency #{key} status #{status}"
216
+ puts "gct update tag #{key} --auto-tag #{is_skip ? "--skip-tag" : ""}"
217
+ system "gct update tag #{key} --auto-tag --update-ci #{is_skip ? "--skip-tag" : ""}"
207
218
  end
208
219
  end
209
220
  end
@@ -7,7 +7,7 @@ push_pod:
7
7
  script:
8
8
  - gct robot start --test
9
9
  - echo "开始lint 和 push podspec"
10
- - gct update dependency $CI_PROJECT_NAME "status" "发布中"
10
+ - gct update dependency $CI_PROJECT_NAME "status" "deploying"
11
11
  - gct clean lint $CI_PROJECT_NAME
12
12
  - gct repo update
13
13
  - gct repo push
@@ -23,7 +23,7 @@ on_failure:
23
23
  stage: failure
24
24
  script:
25
25
  - gct robot finish false --test
26
- - gct update dependency $CI_PROJECT_NAME "status" "发布失败"
26
+ - gct update dependency $CI_PROJECT_NAME "status" "failed"
27
27
  when: on_failure
28
28
  only:
29
29
  - tags
@@ -1,5 +1,6 @@
1
1
  require 'gct/command/robot/start'
2
2
  require 'gct/command/robot/finish'
3
+ require 'gct/command/robot/podfile'
3
4
  require 'net/https'
4
5
  require 'json'
5
6
 
@@ -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
@@ -8,6 +8,7 @@ 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
@@ -17,16 +18,16 @@ module Gct
17
18
  end
18
19
 
19
20
  def batch_tag
20
- value = next_specs
21
- if val.nil?
21
+ specs = next_specs
22
+ if specs.nil?
22
23
  return
23
24
  end
24
- if value.keys.count == 0
25
+ if specs.keys.count == 0
25
26
  puts "tag已全部打完!!!".green
26
27
  # 执行更新podfile的操作
27
- # system "gct update podfile"
28
+ system "gct update podfile"
28
29
  else
29
- value.each do |key, val|
30
+ specs.each do |key, val|
30
31
  if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
31
32
  status = SpecPublishStatus::PENDING
32
33
  val["status"] = status
@@ -38,34 +39,33 @@ module Gct
38
39
  end
39
40
 
40
41
  def next_specs
41
- priority = get_current_project_priority
42
42
  content_map = FileBase.yaml_dependency_read
43
+ if content_map.nil?
44
+ return nil
45
+ end
46
+ priority = 1000
47
+ content_map.each do |k, v|
48
+ if v.keys.include?(@project_name)
49
+ priority = k
50
+ break
51
+ end
52
+ end
53
+
43
54
  priority_map = content_map[priority.to_s]
44
55
  is_all_done = true
45
56
  priority_map.each do |k, v|
46
- if !v["status"].eql?("发布成功")
57
+ if !v["status"].eql?(SpecPublishStatus::SUCCESS)
47
58
  is_all_done = false
48
59
  break
49
60
  end
50
61
  end
62
+
51
63
  if is_all_done
52
- content_map[(priority - 1).to_s]
64
+ content_map[(priority.to_i - 1).to_s]
53
65
  else
54
66
  nil
55
67
  end
56
68
  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
69
  end
70
70
  end
71
71
  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,7 +22,45 @@ module Gct
22
22
  end
23
23
 
24
24
  def run
25
+ version_map = FileBase.read_version
26
+ @name = "ios/#{version_map["name"]}"
27
+ @branch = version_map["branch"]
28
+ @verison = version_map["version"]
29
+ @file = "Podfile"
30
+ puts @version
31
+ update_podfile
32
+ remove_and_backup
33
+ end
34
+
35
+ def update_podfile
36
+ podspec_content = file_contents(@name, @file, @branch)
37
+
38
+ remove_regex = /dev_pod .*/
39
+ podspec_content = podspec_content.gsub!(remove_regex, "")
40
+
41
+ # dependency
42
+ dependency_map = FileBase.yaml_dependency_read
43
+ dependencies = Array.new()
44
+ dependency_map.each do |k, v|
45
+ dependencies << v
46
+ end
47
+
48
+ dependencies.each { |dep|
49
+ dep.keys.each { |k|
50
+ value = dep[k]
51
+ tag = value["tag"]
52
+ update_regex = /.*#{k}.*/
53
+ update_match = update_regex.match(podspec_content).to_s
54
+ podspec_content = podspec_content.gsub!(update_match, " pod '#{k}', '#{tag}'")
55
+ }
56
+ }
57
+
58
+ edit_file(podspec_content)
59
+ system "gct robot podfile"
60
+ end
25
61
 
62
+ def edit_file(content)
63
+ Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
26
64
  end
27
65
 
28
66
  # 删除和备份
@@ -22,6 +22,7 @@ module Gct
22
22
  end
23
23
 
24
24
  def initialize(argv)
25
+ config_gitlab
25
26
  @update_version_branch = 'develop'
26
27
  @skip_tag = argv.flag?('skip-tag', false)
27
28
  @update_ci = argv.flag?('update-ci', false)
@@ -55,8 +56,13 @@ module Gct
55
56
  end
56
57
  end
57
58
  # remove tag
58
- `git tag -d #{@new_tag}`
59
- `git push origin :refs/tags/#{@new_tag}`
59
+ command = `git rev-parse --is-inside-work-tree`
60
+ if command.eql?("true")
61
+ `git tag -d #{@new_tag}`
62
+ `git push origin :refs/tags/#{@new_tag}`
63
+ else
64
+ remove_tag
65
+ end
60
66
  # create tag
61
67
  create_tag
62
68
  end
@@ -75,17 +81,20 @@ module Gct
75
81
 
76
82
  def get_spec_file
77
83
  spec_file = nil
84
+ full_path = nil
78
85
  if @auto_tag
79
86
  raise "podspec名不能为空!!!".red if spec_file.nil? if @name.nil?
80
87
  Dir.chdir(FileBase.tmp_path) do
81
88
  spec_file = Pathname.glob("#{@name}.podspec").first
89
+ full_path = spec_file.realpath
82
90
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
83
91
  end
84
92
  else
85
93
  spec_file = Pathname.glob('*.podspec').first
94
+ full_path = spec_file
86
95
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
87
96
  end
88
- @spec = Pod::Specification.from_file(spec_file)
97
+ @spec = Pod::Specification.from_file(full_path)
89
98
  spec_file
90
99
  end
91
100
 
@@ -138,6 +147,10 @@ module Gct
138
147
  Gitlab.update_merge_request("#{@project_id}", @id, {state_event: 'close'})
139
148
  end
140
149
 
150
+ def remove_tag
151
+ Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
152
+ end
153
+
141
154
  def create_tag
142
155
  Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "master")
143
156
  puts "打tag成功,开始上传podspec...".green
@@ -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"
@@ -7,17 +7,37 @@ module Gct
7
7
  @path = path
8
8
  end
9
9
 
10
+ def read_version
11
+ path = version_path
12
+ if !File.exist?(path)
13
+ return nil
14
+ end
15
+ config_map = YAML.load(File.open(path, "r"))
16
+ config_map
17
+ end
18
+
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)
23
+ end
24
+
10
25
  def yaml_dependency_read
11
26
  path = dependency_path
27
+ if !File.exist?(path)
28
+ return nil
29
+ end
12
30
  config_map = YAML.load(File.open(path, "r"))
13
31
  config_map
14
32
  end
15
33
 
16
34
  def yaml_dependency_update(pod_name, key, value)
35
+ path = dependency_path
36
+ if !File.exist?(dependency_path)
37
+ return
38
+ end
17
39
  begin
18
- path = dependency_path
19
40
  config_map = YAML.load(File.open(path, "r"))
20
- puts config_map
21
41
  config_map = Hash.new() if !config_map
22
42
  config_map.each do |k, v|
23
43
  v.each do |sk, sv|
@@ -105,6 +125,10 @@ module Gct
105
125
  "#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
106
126
  end
107
127
 
128
+ def version_path
129
+ "#{Generator::GctFile.temp_folder_path}/version"
130
+ end
131
+
108
132
  def tmp_path
109
133
  "#{Generator::GctFile.temp_folder_path}"
110
134
  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.1".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.1
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-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -176,11 +176,11 @@ files:
176
176
  - lib/gct/command/repo/update.rb
177
177
  - lib/gct/command/robot.rb
178
178
  - lib/gct/command/robot/finish.rb
179
+ - lib/gct/command/robot/podfile.rb
179
180
  - lib/gct/command/robot/start.rb
180
181
  - lib/gct/command/setup.rb
181
182
  - lib/gct/command/spec.rb
182
183
  - lib/gct/command/spec/lint.rb
183
- - lib/gct/command/tag.rb
184
184
  - lib/gct/command/update.rb
185
185
  - lib/gct/command/update/analyze.rb
186
186
  - lib/gct/command/update/dependency.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