gct 0.3.91 → 0.4.0
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/command.rb +1 -0
- data/lib/gct/command/autotag.rb +90 -18
- 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 +10 -3
- data/lib/gct/command/op.rb +1 -0
- data/lib/gct/command/op/lint.rb +35 -0
- data/lib/gct/command/robot.rb +39 -0
- data/lib/gct/command/robot/finish.rb +18 -22
- data/lib/gct/command/robot/start.rb +9 -19
- data/lib/gct/command/setup.rb +9 -0
- data/lib/gct/command/tag.rb +13 -0
- data/lib/gct/command/update.rb +4 -1
- data/lib/gct/command/update/analyze.rb +22 -0
- data/lib/gct/command/update/dependency.rb +36 -0
- data/lib/gct/command/update/next.rb +72 -0
- data/lib/gct/command/update/podfile.rb +41 -0
- data/lib/gct/command/update/tag.rb +44 -15
- data/lib/gct/constant.rb +4 -0
- data/lib/gct/file_base.rb +67 -1
- data/lib/gct/gct_version.rb +1 -1
- data/lib/gct/generator/gct_file.rb +4 -0
- data/lib/gct/specification.rb +1 -4
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eacd230eb51e7c03f69df817172a1684c61a016b476ee9bede1a4490751084c
|
4
|
+
data.tar.gz: 4f9525f907f827cbe90806a0fc11b42c64bc4cdefda2f6982da2e2ce6d117e1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d93d45b1ffee87733b11bc2f70fc4c35fb510c99bece66196d87b49dadb98f7a9648bb2a407cc78e98223ffbeafb1523f120ff8fec7b4ca127e9eb461a6dad24
|
7
|
+
data.tar.gz: 606a302705d5305cb8d5260d489d551794ffedabea91b7da81bc7ea66cc31042d2dad835a6fd6edccc82369b45d7e4ba5de55a35fceb3b520d29468a73a36115
|
data/lib/gct/command.rb
CHANGED
data/lib/gct/command/autotag.rb
CHANGED
@@ -38,7 +38,19 @@ module Gct
|
|
38
38
|
|
39
39
|
def run
|
40
40
|
FileBase.root_err
|
41
|
-
|
41
|
+
puts "开始分析podfile文件".green
|
42
|
+
puts ""
|
43
|
+
exist_dep = FileBase.exist_dependency
|
44
|
+
if exist_dep
|
45
|
+
tmp_podspecs
|
46
|
+
priority_map = FileBase.yaml_dependency_read
|
47
|
+
create_tag_by_priority(priority_map)
|
48
|
+
else
|
49
|
+
untagged_specs = analyze_dependencies
|
50
|
+
priority_map = priority_rank(untagged_specs)
|
51
|
+
generate_dependency_file(priority_map)
|
52
|
+
create_tag_by_priority(priority_map)
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
def check_branch(branch)
|
@@ -48,10 +60,9 @@ module Gct
|
|
48
60
|
|
49
61
|
def podfile
|
50
62
|
# if check_branch_can_be_update('zeus')
|
51
|
-
if check_branch('ft/tag') # TODO: Test branch
|
63
|
+
# if check_branch('ft/tag') # TODO: Test branch
|
52
64
|
contents = file_contents(@project_id, @file, @branch)
|
53
65
|
contents.force_encoding('UTF-8')
|
54
|
-
puts contents
|
55
66
|
temp_local_file = TempLocalFile.new(contents, @file)
|
56
67
|
temp_local_file.write
|
57
68
|
full_path = temp_local_file.full_path
|
@@ -60,25 +71,30 @@ module Gct
|
|
60
71
|
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
61
72
|
podfile
|
62
73
|
end
|
63
|
-
end
|
74
|
+
# end
|
64
75
|
end
|
65
76
|
|
66
|
-
def
|
77
|
+
def tmp_podspecs
|
67
78
|
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
|
68
79
|
|
69
|
-
|
80
|
+
spec_files = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
|
70
81
|
file_name = "#{dep.name}.podspec"
|
71
82
|
podspec_contents = file_contents("#{Constant.NameSpace}#{dep.name}", file_name, Constant.DefaultTagBranch)
|
72
83
|
temp_local_spec_file = TempLocalFile.new(podspec_contents, file_name)
|
73
84
|
temp_local_spec_file.write
|
74
|
-
|
85
|
+
temp_local_spec_file.full_path
|
86
|
+
end
|
87
|
+
spec_files
|
88
|
+
end
|
75
89
|
|
90
|
+
def analyze_dependencies
|
91
|
+
untagged_specs = tmp_podspecs.map do |spec_file|
|
76
92
|
# 创建podspec对象
|
77
93
|
spec = Pod::Specification.from_file(spec_file)
|
78
94
|
gct_spec = Specification.new()
|
79
95
|
gct_spec.name = spec.name
|
80
96
|
gct_spec.priority = 1000
|
81
|
-
gct_spec.status = SpecPublishStatus::
|
97
|
+
gct_spec.status = SpecPublishStatus::WAITING
|
82
98
|
gct_spec.tag = "0"
|
83
99
|
dependencySpecs = Array.new()
|
84
100
|
if spec.subspecs.length == 0
|
@@ -86,7 +102,7 @@ module Gct
|
|
86
102
|
sub_spec = Specification.new()
|
87
103
|
sub_spec.name = dep.root_name
|
88
104
|
sub_spec.priority = 1000
|
89
|
-
sub_spec.status = SpecPublishStatus::
|
105
|
+
sub_spec.status = SpecPublishStatus::WAITING
|
90
106
|
sub_spec.tag = "0"
|
91
107
|
sub_spec
|
92
108
|
end
|
@@ -97,7 +113,7 @@ module Gct
|
|
97
113
|
sub_spec = Specification.new()
|
98
114
|
sub_spec.name = dep.root_name
|
99
115
|
sub_spec.priority = 1000
|
100
|
-
sub_spec.status = SpecPublishStatus::
|
116
|
+
sub_spec.status = SpecPublishStatus::WAITING
|
101
117
|
sub_spec.tag = "0"
|
102
118
|
sub_spec
|
103
119
|
end
|
@@ -108,8 +124,7 @@ module Gct
|
|
108
124
|
gct_spec.dependencySpecs = dependencySpecs
|
109
125
|
gct_spec
|
110
126
|
end
|
111
|
-
|
112
|
-
priority_rank(untagged_specs)
|
127
|
+
untagged_specs
|
113
128
|
end
|
114
129
|
|
115
130
|
def eqlBetweenHash(hash1, hash2)
|
@@ -133,12 +148,10 @@ module Gct
|
|
133
148
|
temp_spec_map[spec.name] = spec
|
134
149
|
end
|
135
150
|
temp_spec_map_copy = Hash.new()
|
136
|
-
count = 1
|
137
151
|
|
138
152
|
while !(eqlBetweenHash(temp_spec_map, temp_spec_map_copy)) do
|
139
153
|
# 深拷贝
|
140
154
|
temp_spec_map_copy = Marshal.load(Marshal.dump(temp_spec_map))
|
141
|
-
puts "--- times == #{count} ---"
|
142
155
|
specs.map do |spec|
|
143
156
|
temp_spec = temp_spec_map[spec.name]
|
144
157
|
spec.dependencySpecs.map do |subspec|
|
@@ -150,11 +163,70 @@ module Gct
|
|
150
163
|
end
|
151
164
|
end
|
152
165
|
end
|
153
|
-
count += 1
|
154
|
-
temp_spec_map.each { |key, value|
|
155
|
-
puts "#{key} => #{value.priority}"
|
156
|
-
}
|
157
166
|
end
|
167
|
+
dependency_map = Hash.new()
|
168
|
+
priority_map = Hash.new()
|
169
|
+
temp_spec_map.each do |key, value|
|
170
|
+
dependency_map[key] = {"priority" => value.priority, "tag" => value.tag, "status" => value.status}
|
171
|
+
end
|
172
|
+
priority = 1000
|
173
|
+
while priority <= 1000 do
|
174
|
+
tmp_hash = Hash.new()
|
175
|
+
dependency_map.each do |key, value|
|
176
|
+
if (value["priority"] == priority)
|
177
|
+
tmp_hash.store(key, {"tag" => value["tag"], "status" => value["status"]})
|
178
|
+
dependency_map.delete(value)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
if (tmp_hash.keys.count == 0)
|
182
|
+
priority = 1001
|
183
|
+
else
|
184
|
+
priority_map[priority.to_s] = tmp_hash
|
185
|
+
priority -= 1
|
186
|
+
end
|
187
|
+
end
|
188
|
+
priority_map
|
189
|
+
end
|
190
|
+
|
191
|
+
def generate_dependency_file(priority_map)
|
192
|
+
yaml_path = "#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
|
193
|
+
FileBase.yaml_write_map(yaml_path, priority_map)
|
194
|
+
end
|
195
|
+
|
196
|
+
# 按优先级打tag, 触发第一个优先级,其他的上一优先级打完之后自动触发
|
197
|
+
def create_tag_by_priority(priority_map)
|
198
|
+
priority = get_current_need_tag_priority
|
199
|
+
value = priority_map[priority.to_s]
|
200
|
+
raise "没有需要打tag的库".red if value.keys.count == 0
|
201
|
+
value.each do |key, val|
|
202
|
+
if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
|
203
|
+
status = SpecPublishStatus::PENDING
|
204
|
+
val["status"] = status
|
205
|
+
system "gct update dependency #{key} status #{status}"
|
206
|
+
system "gct update tag #{key} --auto-tag"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# 当前优先级是否已打完
|
212
|
+
def get_current_need_tag_priority
|
213
|
+
priority = 1000
|
214
|
+
content_map = FileBase.yaml_dependency_read
|
215
|
+
priority_map = content_map[priority.to_s]
|
216
|
+
is_all_done = true
|
217
|
+
while is_all_done do
|
218
|
+
priority_map.each do |k, v|
|
219
|
+
if !v["status"].eql?(SpecPublishStatus::SUCCESS)
|
220
|
+
is_all_done = false
|
221
|
+
break
|
222
|
+
end
|
223
|
+
end
|
224
|
+
if is_all_done
|
225
|
+
priority -= 1
|
226
|
+
priority_map = content_map[priority.to_s]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
priority
|
158
230
|
end
|
159
231
|
end
|
160
232
|
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
|
@@ -5,11 +5,15 @@ stages:
|
|
5
5
|
push_pod:
|
6
6
|
stage: push
|
7
7
|
script:
|
8
|
-
- gct robot start
|
8
|
+
- gct robot start --test
|
9
9
|
- echo "开始lint 和 push podspec"
|
10
|
+
- gct update dependency $CI_PROJECT_NAME "status" "发布中"
|
11
|
+
- gct clean lint $CI_PROJECT_NAME
|
10
12
|
- gct repo update
|
11
13
|
- gct repo push
|
12
|
-
- gct robot finish true
|
14
|
+
- gct robot finish true --test
|
15
|
+
- gct update dependency $CI_PROJECT_NAME "tag" $CI_COMMIT_REF_NAME
|
16
|
+
- gct update next
|
13
17
|
only:
|
14
18
|
- tags
|
15
19
|
tags:
|
@@ -18,7 +22,10 @@ push_pod:
|
|
18
22
|
on_failure:
|
19
23
|
stage: failure
|
20
24
|
script:
|
21
|
-
- gct robot finish false
|
25
|
+
- gct robot finish false --test
|
26
|
+
- gct update dependency $CI_PROJECT_NAME "status" "发布失败"
|
22
27
|
when: on_failure
|
28
|
+
only:
|
29
|
+
- tags
|
23
30
|
tags:
|
24
31
|
- iOS
|
data/lib/gct/command/op.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Op < Command
|
4
|
+
class Lint < Op
|
5
|
+
|
6
|
+
self.summary = '打开lint 缓存文件夹'
|
7
|
+
self.description = <<-DESC
|
8
|
+
打开lint 缓存文件夹
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
]
|
13
|
+
|
14
|
+
def initialize(argv)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
openLintCache
|
24
|
+
end
|
25
|
+
|
26
|
+
def openLintCache
|
27
|
+
lintCache = '~/Library/Caches/CocoaPods/Pods/External/'
|
28
|
+
puts "Xcode缓存路径为:#{lintCache}".green
|
29
|
+
system "open #{lintCache}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/gct/command/robot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'gct/command/robot/start'
|
2
2
|
require 'gct/command/robot/finish'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module Gct
|
5
7
|
class Command
|
@@ -9,6 +11,43 @@ module Gct
|
|
9
11
|
self.description = <<-DESC
|
10
12
|
发送jenkins和gitlab机器人消息
|
11
13
|
DESC
|
14
|
+
|
15
|
+
def self.options
|
16
|
+
[
|
17
|
+
['--test', '测试机器人,测试webhook'],
|
18
|
+
].concat(super)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(argv)
|
22
|
+
@test = argv.flag?('test', false)
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def robot_send(content)
|
27
|
+
if @test
|
28
|
+
webhook = FileBase.get_config("gitlab-robot-webhook-test")
|
29
|
+
else
|
30
|
+
webhook = FileBase.get_config("gitlab-robot-webhook")
|
31
|
+
end
|
32
|
+
raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty?
|
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": "#{content}"
|
45
|
+
}
|
46
|
+
}.to_json
|
47
|
+
|
48
|
+
header = {'content-type':'application/json'}
|
49
|
+
response = http.post(url, data, header)
|
50
|
+
end
|
12
51
|
end
|
13
52
|
end
|
14
53
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'json'
|
1
|
+
|
3
2
|
|
4
3
|
module Gct
|
5
4
|
class Command
|
@@ -15,6 +14,12 @@ module Gct
|
|
15
14
|
CLAide::Argument.new('BUILD_STATUS', true),
|
16
15
|
]
|
17
16
|
|
17
|
+
def self.options
|
18
|
+
[
|
19
|
+
['--test', '测试机器人,测试webhook'],
|
20
|
+
].concat(super)
|
21
|
+
end
|
22
|
+
|
18
23
|
def initialize(argv)
|
19
24
|
@project_name = ENV['CI_PROJECT_NAME']
|
20
25
|
@user_name = ENV['GITLAB_USER_NAME']
|
@@ -22,31 +27,22 @@ module Gct
|
|
22
27
|
@build_status = argv.shift_argument
|
23
28
|
@commit_sha = ENV['CI_COMMIT_SHA']
|
24
29
|
@ci_url = ENV['CI_PIPELINE_URL']
|
30
|
+
@test = argv.flag?('test', false)
|
25
31
|
super
|
26
32
|
end
|
27
33
|
|
28
34
|
def run
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
35
|
+
puts @build_status.class
|
36
|
+
puts "build_status == #{@build_status}"
|
37
|
+
if @build_status.eql?("false")
|
38
|
+
build_text = "<font color=\"comment\">CI运行失败</font>,请相关人员注意"
|
39
|
+
elsif @build_status.eql?("true")
|
40
|
+
build_text = "<font color=\"info\">CI运行成功</font>"
|
39
41
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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)
|
42
|
+
ci_text = "[点击跳转](#{@ci_url})"
|
43
|
+
|
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
|
+
robot_send(content)
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
@@ -14,33 +14,23 @@ module Gct
|
|
14
14
|
self.arguments = [
|
15
15
|
]
|
16
16
|
|
17
|
+
def self.options
|
18
|
+
[
|
19
|
+
['--test', '测试机器人,测试webhook'],
|
20
|
+
].concat(super)
|
21
|
+
end
|
22
|
+
|
17
23
|
def initialize(argv)
|
18
24
|
@project_name = ENV['CI_PROJECT_NAME']
|
19
25
|
@tag = ENV['CI_COMMIT_REF_NAME']
|
26
|
+
@test = argv.flag?('test', false)
|
20
27
|
super
|
21
28
|
end
|
22
29
|
|
23
30
|
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
31
|
message = " <font color=\"info\">#{@tag}</font> 开始打tag"
|
35
|
-
|
36
|
-
|
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)
|
32
|
+
content = "**#{@project_name}** #{message}"
|
33
|
+
robot_send(content)
|
44
34
|
end
|
45
35
|
end
|
46
36
|
end
|
data/lib/gct/command/setup.rb
CHANGED
@@ -15,9 +15,18 @@ module Gct
|
|
15
15
|
create_root_folder
|
16
16
|
create_temp_folder
|
17
17
|
create_config_file
|
18
|
+
create_backup_folder
|
18
19
|
puts "setup success!".green
|
19
20
|
end
|
20
21
|
|
22
|
+
def create_backup_folder
|
23
|
+
backup_path = Generator::GctFile.backup_folder_path
|
24
|
+
if !File.exist?(backup_path)
|
25
|
+
system "mkdir #{backup_path}", exception: true
|
26
|
+
puts "#{backup_path} 创建成功!".green
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
def create_root_folder
|
22
31
|
gct_path = Generator::GctFile.root_folder_path
|
23
32
|
if !File.exist?(gct_path)
|
data/lib/gct/command/update.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Analyze < Update
|
5
|
+
self.summary = '编译'
|
6
|
+
self.description = <<-DESC
|
7
|
+
下一个优先级打tag
|
8
|
+
DESC
|
9
|
+
|
10
|
+
def initialize(argv)
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Dependency < Update
|
5
|
+
|
6
|
+
self.summary = '更新依赖文件'
|
7
|
+
self.description = <<-DESC
|
8
|
+
更新依赖文件
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
# CLAide::Argument.new('PRIORITY', false),
|
13
|
+
CLAide::Argument.new('POD_NAME', false),
|
14
|
+
CLAide::Argument.new('KEY', false),
|
15
|
+
CLAide::Argument.new('VALUE', false),
|
16
|
+
]
|
17
|
+
|
18
|
+
def initialize(argv)
|
19
|
+
# @priority = argv.shift_argument
|
20
|
+
@pod_name = argv.shift_argument
|
21
|
+
@key = argv.shift_argument
|
22
|
+
@value = argv.shift_argument
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate!
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
FileBase.yaml_dependency_update(@pod_name, @key, @value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Next < Update
|
5
|
+
self.summary = '编译'
|
6
|
+
self.description = <<-DESC
|
7
|
+
下一个优先级打tag
|
8
|
+
DESC
|
9
|
+
|
10
|
+
def initialize(argv)
|
11
|
+
@project_name = ENV['CI_PROJECT_NAME']
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
batch_tag
|
17
|
+
end
|
18
|
+
|
19
|
+
def batch_tag
|
20
|
+
value = next_specs
|
21
|
+
if val.nil?
|
22
|
+
return
|
23
|
+
end
|
24
|
+
if value.keys.count == 0
|
25
|
+
puts "tag已全部打完!!!".green
|
26
|
+
# 执行更新podfile的操作
|
27
|
+
# system "gct update podfile"
|
28
|
+
else
|
29
|
+
value.each do |key, val|
|
30
|
+
if val["status"].eql?(SpecPublishStatus::WAITING) || val["status"].eql?(SpecPublishStatus::CANCELED) || val["status"].eql?(SpecPublishStatus::FAILED)
|
31
|
+
status = SpecPublishStatus::PENDING
|
32
|
+
val["status"] = status
|
33
|
+
system "gct update dependency #{key} status #{status}"
|
34
|
+
system "gct update tag #{key} --auto-tag --update-ci"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def next_specs
|
41
|
+
priority = get_current_project_priority
|
42
|
+
content_map = FileBase.yaml_dependency_read
|
43
|
+
priority_map = content_map[priority.to_s]
|
44
|
+
is_all_done = true
|
45
|
+
priority_map.each do |k, v|
|
46
|
+
if !v["status"].eql?("发布成功")
|
47
|
+
is_all_done = false
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if is_all_done
|
52
|
+
content_map[(priority - 1).to_s]
|
53
|
+
else
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
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
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Podfile < Update
|
5
|
+
|
6
|
+
self.summary = '更新podfile文件'
|
7
|
+
self.description = <<-DESC
|
8
|
+
更新podfile文件
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('VERSION', true),
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(argv)
|
16
|
+
@version = argv.shift_argument
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate!
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# 删除和备份
|
29
|
+
def remove_and_backup
|
30
|
+
d_name = Constant.DependencyName
|
31
|
+
Dir.chdir(FileBase.tmp_path) do
|
32
|
+
# 备份dependency文件到backup文件夹下
|
33
|
+
system "cp #{d_name} ../backup/#{d_name}-#{@version}"
|
34
|
+
# 删除tmp文件夹下所有文件
|
35
|
+
system "rm -rf *"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -17,6 +17,7 @@ module Gct
|
|
17
17
|
[
|
18
18
|
['--skip-tag', '是否忽略tag,直接触发ci'],
|
19
19
|
['--update-ci', '是否更新CI'],
|
20
|
+
['--auto-tag', '自动化'],
|
20
21
|
].concat(super)
|
21
22
|
end
|
22
23
|
|
@@ -24,14 +25,17 @@ module Gct
|
|
24
25
|
@update_version_branch = 'develop'
|
25
26
|
@skip_tag = argv.flag?('skip-tag', false)
|
26
27
|
@update_ci = argv.flag?('update-ci', false)
|
27
|
-
@
|
28
|
-
name = argv.shift_argument
|
29
|
-
@name = name.nil? ? @spec.name : name
|
28
|
+
@auto_tag = argv.flag?('auto-tag', false)
|
29
|
+
@name = argv.shift_argument
|
30
30
|
@tag = argv.shift_argument
|
31
|
+
@file = get_spec_file
|
32
|
+
if @name.nil?
|
33
|
+
@name = @spec.name
|
34
|
+
end
|
31
35
|
@project_id = "#{Constant.NameSpace}#{@name}"
|
32
36
|
super
|
33
37
|
end
|
34
|
-
|
38
|
+
|
35
39
|
def run
|
36
40
|
update_ci_method if @update_ci
|
37
41
|
if @skip_tag
|
@@ -44,8 +48,17 @@ module Gct
|
|
44
48
|
def skip_tag_method
|
45
49
|
@new_tag = @spec.version
|
46
50
|
puts "tag == #{@new_tag}"
|
47
|
-
|
48
|
-
|
51
|
+
if !@update_ci
|
52
|
+
isEmptyMR = mr_to_master
|
53
|
+
if !isEmptyMR
|
54
|
+
accept_merge_request
|
55
|
+
end
|
56
|
+
end
|
57
|
+
# remove tag
|
58
|
+
`git tag -d #{@new_tag}`
|
59
|
+
`git push origin :refs/tags/#{@new_tag}`
|
60
|
+
# create tag
|
61
|
+
create_tag
|
49
62
|
end
|
50
63
|
|
51
64
|
def update_ci_method
|
@@ -54,16 +67,26 @@ module Gct
|
|
54
67
|
path = File.expand_path("../../init", __FILE__)
|
55
68
|
ci_content = temp_local_file.read_path_file(path, "gitlab-ci.rb")
|
56
69
|
edit_file('.gitlab-ci.yml', ci_content, 'update ci')
|
57
|
-
mr_to_master
|
58
|
-
|
70
|
+
isEmptyMR = mr_to_master
|
71
|
+
if !isEmptyMR
|
72
|
+
accept_merge_request
|
73
|
+
end
|
59
74
|
end
|
60
75
|
|
61
76
|
def get_spec_file
|
77
|
+
spec_file = nil
|
78
|
+
if @auto_tag
|
79
|
+
raise "podspec名不能为空!!!".red if spec_file.nil? if @name.nil?
|
80
|
+
Dir.chdir(FileBase.tmp_path) do
|
81
|
+
spec_file = Pathname.glob("#{@name}.podspec").first
|
82
|
+
raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
|
83
|
+
end
|
84
|
+
else
|
62
85
|
spec_file = Pathname.glob('*.podspec').first
|
63
86
|
raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
|
64
|
-
|
65
|
-
|
66
|
-
|
87
|
+
end
|
88
|
+
@spec = Pod::Specification.from_file(spec_file)
|
89
|
+
spec_file
|
67
90
|
end
|
68
91
|
|
69
92
|
def update_podspec_version
|
@@ -90,12 +113,18 @@ module Gct
|
|
90
113
|
|
91
114
|
def mr_to_master
|
92
115
|
puts "正在创建MR请求将develop分支合并到master!".green
|
93
|
-
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "
|
116
|
+
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "mr", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
|
117
|
+
# puts mr.to_hash
|
94
118
|
@id = mr.iid
|
95
119
|
puts mr.merge_status
|
96
|
-
|
120
|
+
isEmptyMR = mr.diff_refs.base_sha.eql?(mr.diff_refs.head_sha)
|
121
|
+
# puts mr.diff_refs.base_sha
|
122
|
+
# puts mr.diff_refs.head_sha
|
123
|
+
close_mr if isEmptyMR
|
124
|
+
if mr.merge_status == 'cannot_be_merged' && !isEmptyMR
|
97
125
|
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
|
98
126
|
end
|
127
|
+
isEmptyMR
|
99
128
|
end
|
100
129
|
|
101
130
|
def accept_merge_request
|
@@ -105,8 +134,8 @@ module Gct
|
|
105
134
|
end
|
106
135
|
end
|
107
136
|
|
108
|
-
def
|
109
|
-
Gitlab.
|
137
|
+
def close_mr
|
138
|
+
Gitlab.update_merge_request("#{@project_id}", @id, {state_event: 'close'})
|
110
139
|
end
|
111
140
|
|
112
141
|
def create_tag
|
data/lib/gct/constant.rb
CHANGED
data/lib/gct/file_base.rb
CHANGED
@@ -7,10 +7,41 @@ module Gct
|
|
7
7
|
@path = path
|
8
8
|
end
|
9
9
|
|
10
|
+
def yaml_dependency_read
|
11
|
+
path = dependency_path
|
12
|
+
config_map = YAML.load(File.open(path, "r"))
|
13
|
+
config_map
|
14
|
+
end
|
15
|
+
|
16
|
+
def yaml_dependency_update(pod_name, key, value)
|
17
|
+
begin
|
18
|
+
path = dependency_path
|
19
|
+
config_map = YAML.load(File.open(path, "r"))
|
20
|
+
puts config_map
|
21
|
+
config_map = Hash.new() if !config_map
|
22
|
+
config_map.each do |k, v|
|
23
|
+
v.each do |sk, sv|
|
24
|
+
if sk.eql?(pod_name)
|
25
|
+
sv[key] = value
|
26
|
+
if key.eql?("tag")
|
27
|
+
sv["status"] = SpecPublishStatus::SUCCESS
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
yaml_file = File.open(path, "w")
|
33
|
+
YAML::dump(config_map, yaml_file)
|
34
|
+
rescue IOError => e
|
35
|
+
raise e.message
|
36
|
+
ensure
|
37
|
+
yaml_file.close unless yaml_file.nil?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
10
41
|
def yaml_write(key, value)
|
11
42
|
begin
|
12
43
|
config_map = YAML.load(File.open(@path, "r"))
|
13
|
-
config_map = Hash.new() if config_map
|
44
|
+
config_map = Hash.new() if !config_map
|
14
45
|
config_map[key] = value
|
15
46
|
yaml_file = File.open(@path, "w")
|
16
47
|
YAML::dump(config_map, yaml_file)
|
@@ -21,6 +52,28 @@ module Gct
|
|
21
52
|
end
|
22
53
|
end
|
23
54
|
|
55
|
+
def yaml_write_map(path, content)
|
56
|
+
begin
|
57
|
+
yaml_file = File.open(path, "w")
|
58
|
+
YAML::dump(content, yaml_file)
|
59
|
+
rescue IOError => e
|
60
|
+
raise e.message
|
61
|
+
ensure
|
62
|
+
yaml_file.close unless yaml_file.nil?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def yaml_read_map(path, key)
|
67
|
+
begin
|
68
|
+
yaml_file = YAML.load(File.open(path, "r"))
|
69
|
+
if yaml_file
|
70
|
+
yaml_file[key]
|
71
|
+
end
|
72
|
+
rescue IOError => e
|
73
|
+
raise e.message
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
24
77
|
def yaml_read(key)
|
25
78
|
begin
|
26
79
|
yaml_file = YAML.load(File.open(@path, "r"))
|
@@ -48,11 +101,24 @@ module Gct
|
|
48
101
|
"#{Generator::GctFile.config_file_path}"
|
49
102
|
end
|
50
103
|
|
104
|
+
def dependency_path
|
105
|
+
"#{Generator::GctFile.temp_folder_path}/#{Constant.DependencyName}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def tmp_path
|
109
|
+
"#{Generator::GctFile.temp_folder_path}"
|
110
|
+
end
|
111
|
+
|
51
112
|
def exist_root
|
52
113
|
root_exist = File.exist?(Generator::GctFile.root_folder_path)
|
53
114
|
root_exist
|
54
115
|
end
|
55
116
|
|
117
|
+
def exist_dependency
|
118
|
+
root_exist = File.exist?(dependency_path)
|
119
|
+
root_exist
|
120
|
+
end
|
121
|
+
|
56
122
|
def root_err
|
57
123
|
raise "请先运行命令:gct setup".red if !exist_root
|
58
124
|
end
|
data/lib/gct/gct_version.rb
CHANGED
data/lib/gct/specification.rb
CHANGED
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jieming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,6 +149,10 @@ files:
|
|
149
149
|
- lib/gct/command/autotag.rb
|
150
150
|
- lib/gct/command/build.rb
|
151
151
|
- lib/gct/command/build/r.rb
|
152
|
+
- lib/gct/command/clean.rb
|
153
|
+
- lib/gct/command/clean/cache.rb
|
154
|
+
- lib/gct/command/clean/ci.rb
|
155
|
+
- lib/gct/command/clean/lint.rb
|
152
156
|
- lib/gct/command/config.rb
|
153
157
|
- lib/gct/command/config/get.rb
|
154
158
|
- lib/gct/command/config/set.rb
|
@@ -163,6 +167,7 @@ files:
|
|
163
167
|
- lib/gct/command/op.rb
|
164
168
|
- lib/gct/command/op/gems.rb
|
165
169
|
- lib/gct/command/op/gitconf.rb
|
170
|
+
- lib/gct/command/op/lint.rb
|
166
171
|
- lib/gct/command/op/root.rb
|
167
172
|
- lib/gct/command/op/xcache.rb
|
168
173
|
- lib/gct/command/repo.rb
|
@@ -175,7 +180,12 @@ files:
|
|
175
180
|
- lib/gct/command/setup.rb
|
176
181
|
- lib/gct/command/spec.rb
|
177
182
|
- lib/gct/command/spec/lint.rb
|
183
|
+
- lib/gct/command/tag.rb
|
178
184
|
- lib/gct/command/update.rb
|
185
|
+
- lib/gct/command/update/analyze.rb
|
186
|
+
- lib/gct/command/update/dependency.rb
|
187
|
+
- lib/gct/command/update/next.rb
|
188
|
+
- lib/gct/command/update/podfile.rb
|
179
189
|
- lib/gct/command/update/tag.rb
|
180
190
|
- lib/gct/command/update/version.rb
|
181
191
|
- lib/gct/constant.rb
|