gct 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gct/command.rb +36 -11
- data/lib/gct/command/autotag.rb +161 -0
- data/lib/gct/command/create/third.rb +1 -1
- data/lib/gct/command/init/gitlab-ci.rb +12 -1
- data/lib/gct/command/robot.rb +14 -0
- data/lib/gct/command/robot/finish.rb +54 -0
- data/lib/gct/command/robot/start.rb +48 -0
- data/lib/gct/command/spec/lint.rb +2 -1
- data/lib/gct/command/update.rb +3 -13
- data/lib/gct/command/update/tag.rb +51 -18
- data/lib/gct/file_base.rb +10 -9
- data/lib/gct/gct_version.rb +1 -1
- data/lib/gct/specification.rb +8 -3
- data/lib/gct/temp_local_file.rb +14 -3
- metadata +7 -4
- data/lib/gct/command/analyze.rb +0 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e11a0e8f6fd269b8140df2ad74d54bdd6a49ecf5d3eabea57c34ecd2e9ab6ad5
|
4
|
+
data.tar.gz: 478a642ec91c9d3c6af390af83860bc9da92d7ea2bbfdf74c451430c2495717e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07a78b2eadf6986cfe53fe7eb6c714bd69debace24b84e261143d3723df74d63a02e106b63f5e6754a5723201574d617f552849bcb9d804d5409f7b39db0c0c
|
7
|
+
data.tar.gz: 0356c696a37c07ef54d5ef99f9d6af1df366c852179051820912295a5af5495a7873adca27cf61ad56d3cb54f67b2d5275563508c890543b9fbef577c8f361f4
|
data/lib/gct/command.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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 config set token GITLAB_TOKEN,参考文档: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.
|
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
|
-
-
|
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
|
-
|
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)
|
data/lib/gct/command/update.rb
CHANGED
@@ -11,22 +11,12 @@ module Gct
|
|
11
11
|
DESC
|
12
12
|
|
13
13
|
def initialize(argv)
|
14
|
+
gitlab_error
|
14
15
|
super
|
15
|
-
config_gitlab
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
raise "该文件夹不是一个git仓库".red if branch.empty?
|
21
|
-
branch
|
22
|
-
end
|
23
|
-
|
24
|
-
def check_branch_can_be_update(branch)
|
25
|
-
can_be_update = current_branch.include?(branch)
|
26
|
-
|
27
|
-
puts "当前不是#{branch}分支".red if !can_be_update
|
28
|
-
|
29
|
-
can_be_update
|
18
|
+
def run
|
19
|
+
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
@@ -9,23 +9,53 @@ 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)
|
16
|
-
@tag = argv.shift_argument
|
17
24
|
@update_version_branch = 'develop'
|
25
|
+
@skip_tag = argv.flag?('skip-tag', false)
|
26
|
+
@update_ci = argv.flag?('update-ci', false)
|
18
27
|
@file = get_spec_file
|
19
|
-
|
28
|
+
name = argv.shift_argument
|
29
|
+
@name = name.nil? ? @spec.name : name
|
30
|
+
@tag = argv.shift_argument
|
31
|
+
@project_id = "#{Constant.NameSpace}#{@name}"
|
20
32
|
super
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
24
|
-
|
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
|
25
42
|
end
|
26
43
|
|
27
|
-
def
|
28
|
-
|
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
|
49
|
+
end
|
50
|
+
|
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
|
29
59
|
end
|
30
60
|
|
31
61
|
def get_spec_file
|
@@ -46,34 +76,37 @@ module Gct
|
|
46
76
|
@now_tag = tag
|
47
77
|
@new_tag = @tag || auto_add_tag(tag.to_s)
|
48
78
|
replace_string = version_match.gsub(tag_regex, @new_tag)
|
49
|
-
|
79
|
+
updated_podspec_content = podspec_content.gsub(version_match, replace_string)
|
50
80
|
puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
|
51
|
-
edit_file
|
81
|
+
edit_file(@file, updated_podspec_content, "@config 更新版本号:#{@new_tag}")
|
52
82
|
mr_to_master
|
83
|
+
accept_merge_request
|
84
|
+
create_tag
|
53
85
|
end
|
54
86
|
|
55
|
-
def edit_file
|
56
|
-
Gitlab.edit_file(@project_id,
|
87
|
+
def edit_file(file, content, commit_message)
|
88
|
+
Gitlab.edit_file(@project_id, file, @update_version_branch, content, commit_message)
|
57
89
|
end
|
58
90
|
|
59
91
|
def mr_to_master
|
60
92
|
puts "正在创建MR请求将develop分支合并到master!".green
|
61
|
-
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@
|
93
|
+
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@name}", "更新版本podpesc版本号", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
|
62
94
|
@id = mr.iid
|
63
95
|
puts mr.merge_status
|
64
96
|
if mr.merge_status == 'cannot_be_merged'
|
65
|
-
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@
|
97
|
+
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@name}/merge_requests/#{@id} 解决".red
|
66
98
|
end
|
67
|
-
|
68
|
-
|
99
|
+
end
|
100
|
+
|
101
|
+
def accept_merge_request
|
102
|
+
mr_result = Gitlab.accept_merge_request("#{@project_id}", @id)
|
69
103
|
if mr_result.state == 'merged'
|
70
104
|
puts "成功合并到master分支".green
|
71
|
-
create_tag
|
72
105
|
end
|
73
106
|
end
|
74
|
-
|
75
|
-
def
|
76
|
-
Gitlab.
|
107
|
+
|
108
|
+
def delete_tag
|
109
|
+
Gitlab.delete_tag("#{@project_id}", "#{@new_tag}")
|
77
110
|
end
|
78
111
|
|
79
112
|
def create_tag
|
data/lib/gct/file_base.rb
CHANGED
@@ -30,17 +30,15 @@ module Gct
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def get_config(key)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
33
|
+
root_err
|
34
|
+
@path = config_path
|
35
|
+
yaml_read(key)
|
37
36
|
end
|
38
37
|
|
39
38
|
def set_config(key, value)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
39
|
+
root_err
|
40
|
+
@path = config_path
|
41
|
+
yaml_write(key, value)
|
44
42
|
end
|
45
43
|
|
46
44
|
def config_path
|
@@ -49,9 +47,12 @@ module Gct
|
|
49
47
|
|
50
48
|
def exist_root
|
51
49
|
root_exist = File.exist?(Generator::GctFile.root_folder_path)
|
52
|
-
raise "请先运行命令:gct setup".red if !root_exist
|
53
50
|
root_exist
|
54
51
|
end
|
52
|
+
|
53
|
+
def root_err
|
54
|
+
raise "请先运行命令:gct setup".red if !exist_root
|
55
|
+
end
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/lib/gct/gct_version.rb
CHANGED
data/lib/gct/specification.rb
CHANGED
@@ -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
|
data/lib/gct/temp_local_file.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Gct
|
2
2
|
class TempLocalFile
|
3
|
-
|
3
|
+
attr_accessor :content
|
4
4
|
|
5
|
-
|
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.
|
4
|
+
version: 0.3.8
|
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-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/
|
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
|
@@ -201,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
204
|
- !ruby/object:Gem::Version
|
202
205
|
version: '0'
|
203
206
|
requirements: []
|
204
|
-
rubygems_version: 3.0.
|
207
|
+
rubygems_version: 3.0.3
|
205
208
|
signing_key:
|
206
209
|
specification_version: 4
|
207
210
|
summary: '"gct ios 自动化脚本工具"'
|
data/lib/gct/command/analyze.rb
DELETED
@@ -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
|