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.
@@ -17,21 +17,30 @@ module Gct
17
17
  [
18
18
  ['--skip-tag', '是否忽略tag,直接触发ci'],
19
19
  ['--update-ci', '是否更新CI'],
20
+ ['--auto-tag', '自动化'],
21
+ ['--pre', '是否预发tag']
20
22
  ].concat(super)
21
23
  end
22
24
 
23
25
  def initialize(argv)
24
- @update_version_branch = 'develop'
26
+ config_gitlab
25
27
  @skip_tag = argv.flag?('skip-tag', false)
26
28
  @update_ci = argv.flag?('update-ci', false)
27
- @file = get_spec_file
28
- name = argv.shift_argument
29
- @name = name.nil? ? @spec.name : name
29
+ @auto_tag = argv.flag?('auto-tag', false)
30
+ @pre = argv.flag?('pre', false)
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
36
+ @file = get_spec_file
37
+ if @name.nil?
38
+ @name = @spec.name
39
+ end
31
40
  @project_id = "#{Constant.NameSpace}#{@name}"
32
41
  super
33
42
  end
34
-
43
+
35
44
  def run
36
45
  update_ci_method if @update_ci
37
46
  if @skip_tag
@@ -42,10 +51,45 @@ module Gct
42
51
  end
43
52
 
44
53
  def skip_tag_method
54
+ if !@update_ci
55
+ isEmptyMR = mr_to_master
56
+ if !isEmptyMR
57
+ accept_merge_request
58
+ end
59
+ end
60
+ remove_and_create_tag
61
+ end
62
+
63
+ def remove_and_create_tag
45
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
46
70
  puts "tag == #{@new_tag}"
47
- delete_tag # remove tag
48
- create_tag # create tag
71
+ # remove 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
79
+ # create tag
80
+ create_tag
81
+ end
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
49
93
  end
50
94
 
51
95
  def update_ci_method
@@ -53,17 +97,30 @@ module Gct
53
97
  temp_local_file = TempLocalFile.new()
54
98
  path = File.expand_path("../../init", __FILE__)
55
99
  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
100
+ if check_ci
101
+ edit_file('.gitlab-ci.yml', ci_content, 'update ci')
102
+ else
103
+ create_file('.gitlab-ci.yml', ci_content, 'init ci')
104
+ end
59
105
  end
60
106
 
61
107
  def get_spec_file
108
+ spec_file = nil
109
+ full_path = nil
110
+ if @auto_tag
111
+ raise "podspec名不能为空!!!".red if spec_file.nil? if @name.nil?
112
+ Dir.chdir(FileBase.tmp_path) do
113
+ spec_file = Pathname.glob("#{@name}.podspec").first
114
+ full_path = spec_file.realpath
115
+ raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
116
+ end
117
+ else
62
118
  spec_file = Pathname.glob('*.podspec').first
119
+ full_path = spec_file
63
120
  raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
64
-
65
- @spec = Pod::Specification.from_file(spec_file)
66
- spec_file
121
+ end
122
+ @spec = Pod::Specification.from_file(full_path)
123
+ spec_file
67
124
  end
68
125
 
69
126
  def update_podspec_version
@@ -75,6 +132,9 @@ module Gct
75
132
  tag = tag_regex.match(version_match)
76
133
  @now_tag = tag
77
134
  @new_tag = @tag || auto_add_tag(tag.to_s)
135
+ if @pre
136
+ @new_tag = "#{@new_tag}" + @pre_tag_suffix
137
+ end
78
138
  replace_string = version_match.gsub(tag_regex, @new_tag)
79
139
  updated_podspec_content = podspec_content.gsub(version_match, replace_string)
80
140
  puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
@@ -88,29 +148,50 @@ module Gct
88
148
  Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
89
149
  end
90
150
 
151
+ def create_file(file, content, commit_message)
152
+ Gitlab.create_file(@project_id, file, @update_version_branch, content, commit_message)
153
+ end
154
+
91
155
  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' })
156
+ puts "正在创建MR请求将#{@update_version_branch}分支合并到#{@update_to_branch}分支!".green
157
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: "#{@update_to_branch}" })
94
158
  @id = mr.iid
95
159
  puts mr.merge_status
96
- if mr.merge_status == 'cannot_be_merged'
160
+ isEmptyMR = mr.diff_refs.base_sha.eql?(mr.diff_refs.head_sha)
161
+ close_mr if isEmptyMR
162
+ if mr.merge_status == 'cannot_be_merged' && !isEmptyMR
97
163
  raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
98
164
  end
165
+ isEmptyMR
99
166
  end
100
167
 
101
168
  def accept_merge_request
102
169
  mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
103
170
  if mr_result.state == 'merged'
104
- puts "成功合并到master分支".green
171
+ puts "成功合并到#{@update_to_branch}分支".green
105
172
  end
106
173
  end
107
174
 
108
- def delete_tag
109
- Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
175
+ def close_mr
176
+ Gitlab.update_merge_request("#{@project_id}", @id, {state_event: 'close'})
177
+ end
178
+
179
+ def remove_tag
180
+ tags = Gitlab.tags("#{@project_id}")
181
+ puts "remove tag is " + "#{@new_tag}"
182
+ tags.each do |t|
183
+ if t["name"].eql?("#{@new_tag}")
184
+ Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
185
+ break
186
+ end
187
+ end
110
188
  end
111
189
 
112
190
  def create_tag
113
- Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "master")
191
+ Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "#{@update_to_branch}")
192
+ db = Database::Data.new
193
+ 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"
194
+ db.query(sql)
114
195
  puts "打tag成功,开始上传podspec...".green
115
196
  end
116
197
  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,9 +21,25 @@ module Gct
21
21
  "ios-third/"
22
22
  end
23
23
 
24
- def DefaultTagBranch
24
+ def DefaultTagFromBranch
25
25
  "develop"
26
26
  end
27
+
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"
42
+ end
27
43
  end
28
44
  end
29
45
  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,6 +7,21 @@ 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_write(key, value)
11
26
  begin
12
27
  config_map = YAML.load(File.open(@path, "r"))
@@ -21,6 +36,28 @@ module Gct
21
36
  end
22
37
  end
23
38
 
39
+ def yaml_write_map(path, content)
40
+ begin
41
+ yaml_file = File.open(path, "w")
42
+ YAML::dump(content, yaml_file)
43
+ rescue IOError => e
44
+ raise e.message
45
+ ensure
46
+ yaml_file.close unless yaml_file.nil?
47
+ end
48
+ end
49
+
50
+ def yaml_read_map(path, key)
51
+ begin
52
+ yaml_file = YAML.load(File.open(path, "r"))
53
+ if yaml_file
54
+ yaml_file[key]
55
+ end
56
+ rescue IOError => e
57
+ raise e.message
58
+ end
59
+ end
60
+
24
61
  def yaml_read(key)
25
62
  begin
26
63
  yaml_file = YAML.load(File.open(@path, "r"))
@@ -48,6 +85,14 @@ module Gct
48
85
  "#{Generator::GctFile.config_file_path}"
49
86
  end
50
87
 
88
+ def version_path
89
+ "#{Generator::GctFile.temp_folder_path}/version"
90
+ end
91
+
92
+ def tmp_path
93
+ "#{Generator::GctFile.temp_folder_path}"
94
+ end
95
+
51
96
  def exist_root
52
97
  root_exist = File.exist?(Generator::GctFile.root_folder_path)
53
98
  root_exist
@@ -2,5 +2,5 @@ module Gct
2
2
  # freeze 冻结对象,将对象变成一个常量
3
3
  # unless 右边的代码块成立,才会运行左边的代码块
4
4
  # defined? 是用来判断本地变量是否存在,也可用来判断是否存在方法
5
- VERSION = "0.3.93".freeze unless defined? Gct::VERSION
5
+ VERSION = "0.4.2".freeze unless defined? Gct::VERSION
6
6
  end
@@ -13,6 +13,10 @@ module Gct
13
13
  "#{get_system_home_path.rstrip}/.gct/config"
14
14
  end
15
15
 
16
+ def self.backup_folder_path
17
+ "#{get_system_home_path.rstrip}/.gct/backup"
18
+ end
19
+
16
20
  # 获取系统用户名
17
21
  def self.get_system_user_name
18
22
  # windows
@@ -30,15 +30,12 @@ module Gct
30
30
  end
31
31
 
32
32
  module SpecPublishStatus
33
- CREATED = '待分析'
34
- ANALYZING = '分析中'
35
- PREPARING = '准备中'
36
- PENDING = '等待中'
37
- WAITING = '待发布'
38
- SKIPPED = '已忽略'
39
- MERGED = '已合并'
40
- DEPLOYING = '发布中'
41
- SUCCESS = '发布成功'
42
- FAILED = '发布失败'
43
- 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'
44
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.3.93
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jieming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,20 @@ dependencies:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: mysql2
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
137
151
  description: '"gct ios 自动化脚本工具"'
138
152
  email:
139
153
  - 307113345@qq.com
@@ -149,6 +163,10 @@ files:
149
163
  - lib/gct/command/autotag.rb
150
164
  - lib/gct/command/build.rb
151
165
  - lib/gct/command/build/r.rb
166
+ - lib/gct/command/clean.rb
167
+ - lib/gct/command/clean/cache.rb
168
+ - lib/gct/command/clean/ci.rb
169
+ - lib/gct/command/clean/lint.rb
152
170
  - lib/gct/command/config.rb
153
171
  - lib/gct/command/config/get.rb
154
172
  - lib/gct/command/config/set.rb
@@ -163,6 +181,7 @@ files:
163
181
  - lib/gct/command/op.rb
164
182
  - lib/gct/command/op/gems.rb
165
183
  - lib/gct/command/op/gitconf.rb
184
+ - lib/gct/command/op/lint.rb
166
185
  - lib/gct/command/op/root.rb
167
186
  - lib/gct/command/op/xcache.rb
168
187
  - lib/gct/command/repo.rb
@@ -171,14 +190,20 @@ files:
171
190
  - lib/gct/command/repo/update.rb
172
191
  - lib/gct/command/robot.rb
173
192
  - lib/gct/command/robot/finish.rb
193
+ - lib/gct/command/robot/podfile.rb
174
194
  - lib/gct/command/robot/start.rb
175
195
  - lib/gct/command/setup.rb
176
196
  - lib/gct/command/spec.rb
177
197
  - lib/gct/command/spec/lint.rb
178
198
  - lib/gct/command/update.rb
199
+ - lib/gct/command/update/analyze.rb
200
+ - lib/gct/command/update/dependency.rb
201
+ - lib/gct/command/update/next.rb
202
+ - lib/gct/command/update/podfile.rb
179
203
  - lib/gct/command/update/tag.rb
180
204
  - lib/gct/command/update/version.rb
181
205
  - lib/gct/constant.rb
206
+ - lib/gct/database/data.rb
182
207
  - lib/gct/file_base.rb
183
208
  - lib/gct/gct_version.rb
184
209
  - lib/gct/generator/gct_file.rb
@@ -204,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
229
  - !ruby/object:Gem::Version
205
230
  version: '0'
206
231
  requirements: []
207
- rubygems_version: 3.0.8
232
+ rubygems_version: 3.0.3
208
233
  signing_key:
209
234
  specification_version: 4
210
235
  summary: '"gct ios 自动化脚本工具"'