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.
- checksums.yaml +4 -4
- data/lib/gct.rb +4 -0
- data/lib/gct/command.rb +2 -3
- data/lib/gct/command/autotag.rb +158 -32
- data/lib/gct/command/clean.rb +15 -0
- data/lib/gct/command/clean/cache.rb +26 -0
- data/lib/gct/command/clean/ci.rb +23 -0
- data/lib/gct/command/clean/lint.rb +28 -0
- data/lib/gct/command/init/gitlab-ci.rb +7 -0
- data/lib/gct/command/op.rb +1 -0
- data/lib/gct/command/op/lint.rb +35 -0
- data/lib/gct/command/robot.rb +40 -0
- data/lib/gct/command/robot/finish.rb +11 -27
- data/lib/gct/command/robot/podfile.rb +38 -0
- data/lib/gct/command/robot/start.rb +2 -23
- data/lib/gct/command/setup.rb +9 -0
- data/lib/gct/command/spec/lint.rb +2 -2
- data/lib/gct/command/update.rb +4 -1
- data/lib/gct/command/update/analyze.rb +22 -0
- data/lib/gct/command/update/dependency.rb +43 -0
- data/lib/gct/command/update/next.rb +66 -0
- data/lib/gct/command/update/podfile.rb +83 -0
- data/lib/gct/command/update/tag.rb +101 -20
- data/lib/gct/command/update/version.rb +1 -0
- data/lib/gct/constant.rb +17 -1
- data/lib/gct/database/data.rb +28 -0
- data/lib/gct/file_base.rb +45 -0
- data/lib/gct/gct_version.rb +1 -1
- data/lib/gct/generator/gct_file.rb +4 -0
- data/lib/gct/specification.rb +8 -11
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2543169b03dd0c5d196ea4af9fb3214efccfd54165fb5418c3fb36e9f04c0b88
|
4
|
+
data.tar.gz: a17f7e2f676904a9c8c6b0acd7ffc08fe0d8db6f07f974f8825e90a120ffa2cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c620629c7a89a8758a44c45635ed470cc42330f954c05a2bb7caf0adf2892215f7b40833f702a1378e18e648ec7ce383e5f81520622a5bd4677899ea74c7687
|
7
|
+
data.tar.gz: c1ad60709ac0c069086abccd377cf30a106f34f93ca224ca6541a0bcbf6010f521503beff69ee035648d1b74de8f73b751c7e819b638ea84928182d46970faff
|
data/lib/gct.rb
CHANGED
data/lib/gct/command.rb
CHANGED
@@ -27,6 +27,7 @@ module Gct
|
|
27
27
|
require 'gct/command/setup'
|
28
28
|
require 'gct/command/update'
|
29
29
|
require 'gct/command/robot'
|
30
|
+
require 'gct/command/clean'
|
30
31
|
|
31
32
|
self.abstract_command = true
|
32
33
|
self.command = 'gct'
|
@@ -51,8 +52,6 @@ module Gct
|
|
51
52
|
Colored2.disable!
|
52
53
|
String.send(:define_method, :colorize) { |string, _| string }
|
53
54
|
end
|
54
|
-
|
55
|
-
config_gitlab
|
56
55
|
end
|
57
56
|
|
58
57
|
def file_contents(project_id, file, branch)
|
@@ -62,7 +61,7 @@ module Gct
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def config_gitlab
|
65
|
-
if FileBase.exist_root and token
|
64
|
+
if FileBase.exist_root and token
|
66
65
|
Gitlab.configure do |config|
|
67
66
|
config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
|
68
67
|
config.private_token = token
|
data/lib/gct/command/autotag.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'tmpdir'
|
3
3
|
require 'parallel'
|
4
|
+
require 'pp'
|
4
5
|
|
5
6
|
module Gct
|
6
7
|
class Command
|
@@ -13,20 +14,27 @@ module Gct
|
|
13
14
|
self.arguments = [
|
14
15
|
CLAide::Argument.new('PROJECT_ID', true),
|
15
16
|
CLAide::Argument.new('BRANCH', true),
|
17
|
+
CLAide::Argument.new('VERSION', true),
|
16
18
|
]
|
17
19
|
|
18
20
|
def initialize(argv)
|
19
21
|
gitlab_error
|
22
|
+
config_gitlab
|
20
23
|
@update_ci = argv.flag?('update-ci', false)
|
21
|
-
@
|
24
|
+
@pre = argv.flag?('pre', false)
|
25
|
+
name = argv.shift_argument
|
26
|
+
@project_id = "ios/#{name}"
|
27
|
+
@project_name = name
|
22
28
|
@branch = argv.shift_argument
|
29
|
+
@version = argv.shift_argument
|
23
30
|
@file = 'Podfile'
|
24
31
|
super
|
25
32
|
end
|
26
33
|
|
27
34
|
def self.options
|
28
35
|
[
|
29
|
-
['--update-ci', '是否更新CI']
|
36
|
+
['--update-ci', '是否更新CI'],
|
37
|
+
['--pre', '是否为预发tag'],
|
30
38
|
].concat(super)
|
31
39
|
end
|
32
40
|
|
@@ -34,11 +42,40 @@ module Gct
|
|
34
42
|
super
|
35
43
|
help! '请输入项目名.' unless @project_id
|
36
44
|
help! '请输入分支名.' unless @branch
|
45
|
+
help! '请输入版本号.' unless @version
|
37
46
|
end
|
38
47
|
|
39
48
|
def run
|
40
49
|
FileBase.root_err
|
41
|
-
|
50
|
+
puts "开始分析podfile文件".green
|
51
|
+
puts ""
|
52
|
+
where_statement = "and is_pre = #{@pre ? 1 : 0}"
|
53
|
+
p_db = Database::Data.new
|
54
|
+
p_sql = "select * from project where version = '#{@version}' #{where_statement}"
|
55
|
+
p_res = p_db.query(p_sql)
|
56
|
+
|
57
|
+
if !p_res.nil? && p_res.count > 0
|
58
|
+
res_first = nil
|
59
|
+
p_res.each do |row|
|
60
|
+
res_first = row
|
61
|
+
break
|
62
|
+
end
|
63
|
+
if res_first["is_done"].to_i == 0
|
64
|
+
tmp_podspecs
|
65
|
+
create_tag_by_priority()
|
66
|
+
else
|
67
|
+
raise "#{@project_name} #{@version} 版本已经打完tag了!!!".red
|
68
|
+
end
|
69
|
+
else
|
70
|
+
keys = "(version, name, branch" + (@pre ? ", is_pre)" : ")")
|
71
|
+
values = "('#{@version}', '#{@project_name}', '#{@branch}'" + (@pre ? ", 1)" : ")")
|
72
|
+
db = Database::Data.new
|
73
|
+
sql = "insert into project #{keys} values #{values}"
|
74
|
+
res = db.query(sql)
|
75
|
+
untagged_specs = analyze_dependencies
|
76
|
+
priority_rank(untagged_specs)
|
77
|
+
create_tag_by_priority()
|
78
|
+
end
|
42
79
|
end
|
43
80
|
|
44
81
|
def check_branch(branch)
|
@@ -47,38 +84,85 @@ module Gct
|
|
47
84
|
end
|
48
85
|
|
49
86
|
def podfile
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@podfile ||= begin
|
60
|
-
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
61
|
-
podfile
|
62
|
-
end
|
87
|
+
contents = file_contents(@project_id, @file, @branch)
|
88
|
+
contents.force_encoding('UTF-8')
|
89
|
+
temp_local_file = TempLocalFile.new(contents, @file)
|
90
|
+
temp_local_file.write
|
91
|
+
full_path = temp_local_file.full_path
|
92
|
+
|
93
|
+
@podfile ||= begin
|
94
|
+
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
95
|
+
podfile
|
63
96
|
end
|
64
97
|
end
|
65
98
|
|
66
|
-
def
|
67
|
-
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.
|
99
|
+
def tmp_podspecs
|
100
|
+
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagFromBranch}
|
101
|
+
raise "没有需要打tag的库".red if untagged_git_dependencies.count == 0
|
68
102
|
|
69
|
-
|
103
|
+
spec_files = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
|
104
|
+
project_name = "#{Constant.NameSpace}#{dep.name}"
|
105
|
+
branch = Constant.DefaultTagFromBranch
|
106
|
+
if @pre
|
107
|
+
branch = Constant.PreTagFromBranch
|
108
|
+
create_pre_branch(branch, project_name)
|
109
|
+
end
|
70
110
|
file_name = "#{dep.name}.podspec"
|
71
|
-
podspec_contents = file_contents(
|
111
|
+
podspec_contents = file_contents(project_name, file_name, branch)
|
72
112
|
temp_local_spec_file = TempLocalFile.new(podspec_contents, file_name)
|
73
113
|
temp_local_spec_file.write
|
74
|
-
|
114
|
+
path = temp_local_spec_file.full_path
|
115
|
+
spec = Pod::Specification.from_file(path)
|
116
|
+
remove_tag(auto_add_tag(spec.version.to_s), project_name)
|
117
|
+
path
|
118
|
+
end
|
119
|
+
spec_files
|
120
|
+
end
|
121
|
+
|
122
|
+
def create_pre_branch(branch, project_name)
|
123
|
+
puts "正在创建#{project_name}预发分支!".green
|
124
|
+
bs = Gitlab.branches(project_name)
|
125
|
+
to_b = Constant.DefaultTagToBranch
|
126
|
+
pre_to_b = Constant.PreTagToBranch
|
127
|
+
from_b = Constant.DefaultTagFromBranch
|
128
|
+
bs.each do |b|
|
129
|
+
if b["name"].eql?(branch)
|
130
|
+
Gitlab.delete_branch(project_name, branch)
|
131
|
+
end
|
132
|
+
if b["name"].eql?(pre_to_b)
|
133
|
+
Gitlab.delete_branch(project_name, pre_to_b)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
Gitlab.create_branch(project_name, branch, from_b)
|
137
|
+
Gitlab.create_branch(project_name, pre_to_b, to_b)
|
138
|
+
end
|
75
139
|
|
140
|
+
def remove_tag(tag, name)
|
141
|
+
# 判断是否有这个tag
|
142
|
+
tag = "#{tag}#{Constant.PreHuffix}"
|
143
|
+
command = `git rev-parse --is-inside-work-tree`
|
144
|
+
if command.eql?("true")
|
145
|
+
`git tag -d #{tag}`
|
146
|
+
`git push origin :refs/tags/#{tag}`
|
147
|
+
else
|
148
|
+
tags = Gitlab.tags("#{name}")
|
149
|
+
tags.each do |t|
|
150
|
+
if t["name"].eql?("#{tag}")
|
151
|
+
Gitlab.delete_tag("#{name}", "#{tag}")
|
152
|
+
break
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def analyze_dependencies
|
159
|
+
untagged_specs = tmp_podspecs.map do |spec_file|
|
76
160
|
# 创建podspec对象
|
77
161
|
spec = Pod::Specification.from_file(spec_file)
|
78
162
|
gct_spec = Specification.new()
|
79
163
|
gct_spec.name = spec.name
|
80
164
|
gct_spec.priority = 1000
|
81
|
-
gct_spec.status = SpecPublishStatus::
|
165
|
+
gct_spec.status = SpecPublishStatus::WAITING
|
82
166
|
gct_spec.tag = "0"
|
83
167
|
dependencySpecs = Array.new()
|
84
168
|
if spec.subspecs.length == 0
|
@@ -86,7 +170,7 @@ module Gct
|
|
86
170
|
sub_spec = Specification.new()
|
87
171
|
sub_spec.name = dep.root_name
|
88
172
|
sub_spec.priority = 1000
|
89
|
-
sub_spec.status = SpecPublishStatus::
|
173
|
+
sub_spec.status = SpecPublishStatus::WAITING
|
90
174
|
sub_spec.tag = "0"
|
91
175
|
sub_spec
|
92
176
|
end
|
@@ -97,7 +181,7 @@ module Gct
|
|
97
181
|
sub_spec = Specification.new()
|
98
182
|
sub_spec.name = dep.root_name
|
99
183
|
sub_spec.priority = 1000
|
100
|
-
sub_spec.status = SpecPublishStatus::
|
184
|
+
sub_spec.status = SpecPublishStatus::WAITING
|
101
185
|
sub_spec.tag = "0"
|
102
186
|
sub_spec
|
103
187
|
end
|
@@ -108,8 +192,7 @@ module Gct
|
|
108
192
|
gct_spec.dependencySpecs = dependencySpecs
|
109
193
|
gct_spec
|
110
194
|
end
|
111
|
-
|
112
|
-
priority_rank(untagged_specs)
|
195
|
+
untagged_specs
|
113
196
|
end
|
114
197
|
|
115
198
|
def eqlBetweenHash(hash1, hash2)
|
@@ -133,12 +216,10 @@ module Gct
|
|
133
216
|
temp_spec_map[spec.name] = spec
|
134
217
|
end
|
135
218
|
temp_spec_map_copy = Hash.new()
|
136
|
-
count = 1
|
137
219
|
|
138
220
|
while !(eqlBetweenHash(temp_spec_map, temp_spec_map_copy)) do
|
139
221
|
# 深拷贝
|
140
222
|
temp_spec_map_copy = Marshal.load(Marshal.dump(temp_spec_map))
|
141
|
-
puts "--- times == #{count} ---"
|
142
223
|
specs.map do |spec|
|
143
224
|
temp_spec = temp_spec_map[spec.name]
|
144
225
|
spec.dependencySpecs.map do |subspec|
|
@@ -150,10 +231,55 @@ module Gct
|
|
150
231
|
end
|
151
232
|
end
|
152
233
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
234
|
+
end
|
235
|
+
|
236
|
+
values = ""
|
237
|
+
temp_spec_map.each do |key, value|
|
238
|
+
values.concat("('#{@version}', '#{key}', '#{@project_name}', '#{value.tag}', '#{value.status}', #{value.priority}" + (@pre ? ", 1)," : "),"))
|
239
|
+
end
|
240
|
+
val = values[0, values.length - 1]
|
241
|
+
keys = "(project_version, pod_name, project_name, tag_version, tag_status, priority" + (@pre ? ", is_pre)" : ")")
|
242
|
+
sql = "insert into tag #{keys} values #{val}"
|
243
|
+
db = Database::Data.new
|
244
|
+
db.query(sql)
|
245
|
+
end
|
246
|
+
|
247
|
+
# 按优先级打tag, 触发第一个优先级,其他的上一优先级打完之后自动触发
|
248
|
+
def create_tag_by_priority()
|
249
|
+
db = Database::Data.new
|
250
|
+
# 查询优先级最高的为完成打tag的数据
|
251
|
+
where_statement = "and is_pre = " + (@pre ? "1" : "0")
|
252
|
+
sql = "select * from tag where priority = (select MAX(priority) from tag where project_version = '#{@version}' and tag_status != '#{SpecPublishStatus::SUCCESS}' #{where_statement})"
|
253
|
+
result = db.query(sql)
|
254
|
+
vals = ""
|
255
|
+
ins = ""
|
256
|
+
if !result.nil? && result.count > 0
|
257
|
+
result.each do |row|
|
258
|
+
if row["tag_status"].eql?(SpecPublishStatus::WAITING) || row["tag_status"].eql?(SpecPublishStatus::CANCELED) || row["tag_status"].eql?(SpecPublishStatus::FAILED)
|
259
|
+
status = SpecPublishStatus::PENDING
|
260
|
+
name = row["pod_name"]
|
261
|
+
vals.concat("when pod_name = '#{name}' then '#{status}' ")
|
262
|
+
ins.concat("'#{name}',")
|
263
|
+
system "gct update dependency #{name} tag_status #{status}"
|
264
|
+
skip_tag = ""
|
265
|
+
if row["is_tag"].to_i == 1
|
266
|
+
skip_tag = "--skip-tag"
|
267
|
+
end
|
268
|
+
pre = ""
|
269
|
+
if row["is_pre"].to_i == 1
|
270
|
+
pre = "--pre"
|
271
|
+
end
|
272
|
+
system "gct update tag #{name} --auto-tag --update-ci #{skip_tag} #{pre}"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
f_ins = ins[0, ins.length - 1]
|
276
|
+
sql = "update tag set tag_status = (
|
277
|
+
case
|
278
|
+
#{vals}
|
279
|
+
end
|
280
|
+
) where pod_name in (#{f_ins}) and project_version = '#{@version}'"
|
281
|
+
update_db = Database::Data.new
|
282
|
+
update_db.query(sql)
|
157
283
|
end
|
158
284
|
end
|
159
285
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'gct/command/clean/cache'
|
2
|
+
require 'gct/command/clean/ci'
|
3
|
+
require 'gct/command/clean/lint'
|
4
|
+
|
5
|
+
module Gct
|
6
|
+
class Command
|
7
|
+
class Clean < Command
|
8
|
+
self.abstract_command = true
|
9
|
+
self.summary = '清理缓存的相关操作'
|
10
|
+
self.description = <<-DESC
|
11
|
+
清理lint缓存,Xcode build缓存,ci build 缓存
|
12
|
+
DESC
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Clean < Command
|
4
|
+
class Cache < Clean
|
5
|
+
|
6
|
+
self.summary = '清理Xcode build缓存'
|
7
|
+
self.description = <<-DESC
|
8
|
+
清理Xcode build缓存
|
9
|
+
DESC
|
10
|
+
|
11
|
+
def initialize(argv)
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
home_path = Generator::GctFile.get_system_home_path().rstrip
|
18
|
+
xcache_path = "#{home_path}/Library/Developer/Xcode/DerivedData/"
|
19
|
+
`rm -rf #{xcache_path}`
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Clean < Command
|
4
|
+
class Ci < Clean
|
5
|
+
|
6
|
+
self.summary = '清除ci缓存'
|
7
|
+
self.description = <<-DESC
|
8
|
+
清除ci缓存,默认清除所有
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('POD_NAME', false),
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(argv)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Clean < Command
|
4
|
+
class Lint < Clean
|
5
|
+
|
6
|
+
self.summary = '清除lint缓存'
|
7
|
+
self.description = <<-DESC
|
8
|
+
清除lint缓存,默认清除所有
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('POD_NAME', false),
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(argv)
|
16
|
+
@pod_name = argv.shift_argument
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
home_path = Generator::GctFile.get_system_home_path().rstrip
|
22
|
+
lintcahce_path = "#{home_path}/Library/Caches/CocoaPods/Pods/External/#{@pod_name}"
|
23
|
+
`rm -rf #{lintcahce_path}`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -7,9 +7,13 @@ push_pod:
|
|
7
7
|
script:
|
8
8
|
- gct robot start
|
9
9
|
- echo "开始lint 和 push podspec"
|
10
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "deploying"
|
11
|
+
- gct clean lint $CI_PROJECT_NAME
|
10
12
|
- gct repo update
|
11
13
|
- gct repo push
|
12
14
|
- gct robot finish true
|
15
|
+
- gct update dependency $CI_PROJECT_NAME "tag_version" $CI_COMMIT_REF_NAME
|
16
|
+
- gct update next
|
13
17
|
only:
|
14
18
|
- tags
|
15
19
|
tags:
|
@@ -19,6 +23,9 @@ on_failure:
|
|
19
23
|
stage: failure
|
20
24
|
script:
|
21
25
|
- gct robot finish false
|
26
|
+
- gct update dependency $CI_PROJECT_NAME "tag_status" "failed"
|
22
27
|
when: on_failure
|
28
|
+
only:
|
29
|
+
- tags
|
23
30
|
tags:
|
24
31
|
- iOS
|