gct 0.2.7 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gct.rb +11 -2
- data/lib/gct/command.rb +53 -3
- data/lib/gct/command/analyze.rb +98 -1
- data/lib/gct/command/build/r.rb +2 -13
- data/lib/gct/command/config.rb +29 -1
- data/lib/gct/command/config/get.rb +4 -8
- data/lib/gct/command/config/set.rb +9 -10
- data/lib/gct/command/init/ci.rb +3 -8
- data/lib/gct/command/init/gitlab-ci.rb +13 -0
- data/lib/gct/command/op.rb +2 -0
- data/lib/gct/command/op/root.rb +33 -0
- data/lib/gct/command/repo/add.rb +1 -1
- data/lib/gct/command/repo/push.rb +2 -1
- data/lib/gct/command/repo/update.rb +1 -1
- data/lib/gct/command/setup.rb +46 -0
- data/lib/gct/command/update.rb +14 -0
- data/lib/gct/command/update/tag.rb +51 -0
- data/lib/gct/command/update/version.rb +62 -0
- data/lib/gct/constant.rb +16 -0
- data/lib/gct/file_base.rb +30 -0
- data/lib/gct/{version.rb → gct_version.rb} +1 -1
- data/lib/gct/generator/gct_file.rb +32 -0
- data/lib/gct/specification.rb +39 -0
- data/lib/gct/temp_local_file.rb +42 -0
- data/lib/gct/temp_remote_file.rb +44 -0
- metadata +46 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f7fd4929009c39da92495a65340bad50a94efb0fb82fae4e2e3414a77f296c
|
4
|
+
data.tar.gz: d8aeb513fefded8048dd91087d716518f00d620dc2e7db0ef8f02164422110d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baac27cf9bf1de60ac52f4edf41ca0fb42f3ac7807e004bdb43670d3eab3afede65f18d74d966be1c16e00a28ee13be455d60ebd9d0b01fe051590f294777c45
|
7
|
+
data.tar.gz: 8a6953a83ec3191fce0f93e8a8ca865c0f4f7eb5ed2557a5937c125ca67f4a4d70656063849fd6b22520aa43bd7152c018b2edca9d596b0bbaa4444786cb73b7
|
data/lib/gct.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
|
2
2
|
module Gct
|
3
|
-
require "gct/
|
3
|
+
require "gct/gct_version"
|
4
4
|
require "gct/constant"
|
5
|
-
|
5
|
+
require "gct/specification"
|
6
|
+
require "gct/temp_local_file"
|
7
|
+
require "gct/temp_remote_file"
|
8
|
+
require "gct/file_base"
|
9
|
+
|
10
|
+
autoload :Command, 'gct/command'
|
11
|
+
|
12
|
+
module Generator
|
13
|
+
require "gct/generator/gct_file"
|
14
|
+
end
|
6
15
|
|
7
16
|
end
|
data/lib/gct/command.rb
CHANGED
@@ -2,6 +2,7 @@ require 'colored2'
|
|
2
2
|
require 'claide'
|
3
3
|
require 'molinillo/errors'
|
4
4
|
require 'xcodeproj'
|
5
|
+
require 'gitlab'
|
5
6
|
|
6
7
|
module Molinillo
|
7
8
|
class ResolverError
|
@@ -16,13 +17,15 @@ module Gct
|
|
16
17
|
|
17
18
|
class Command < CLAide::Command
|
18
19
|
require 'gct/command/create'
|
19
|
-
|
20
|
-
|
21
|
-
require 'gct/command/analyze'
|
20
|
+
require 'gct/command/init'
|
21
|
+
require 'gct/command/config'
|
22
|
+
# require 'gct/command/analyze'
|
22
23
|
require 'gct/command/op'
|
23
24
|
require 'gct/command/build'
|
24
25
|
require 'gct/command/spec'
|
25
26
|
require 'gct/command/repo'
|
27
|
+
require 'gct/command/setup'
|
28
|
+
require 'gct/command/update'
|
26
29
|
|
27
30
|
self.abstract_command = true
|
28
31
|
self.command = 'gct'
|
@@ -47,6 +50,53 @@ module Gct
|
|
47
50
|
Colored2.disable!
|
48
51
|
String.send(:define_method, :colorize) { |string, _| string }
|
49
52
|
end
|
53
|
+
|
54
|
+
config_gitlab
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_contents(project_id, file, branch)
|
58
|
+
file_contents ||= Gitlab.file_contents(project_id, file, branch)
|
59
|
+
rescue Gitlab::Error::NotFound => error
|
60
|
+
raise error.message
|
61
|
+
end
|
62
|
+
|
63
|
+
def config_gitlab
|
64
|
+
token = Config.get_config("token")
|
65
|
+
raise "请先配置token!gct config set token GITLAB_PERSON_TOKEN".red if token.nil?
|
66
|
+
Gitlab.configure do |config|
|
67
|
+
config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
|
68
|
+
config.private_token = token
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_project
|
73
|
+
proj = nil
|
74
|
+
Dir.entries(Dir.pwd).each do |subfile|
|
75
|
+
if subfile.include? '.xcodeproj'
|
76
|
+
proj = subfile
|
77
|
+
end
|
78
|
+
end
|
79
|
+
if proj.nil?
|
80
|
+
puts '没有找到.xcodeproj文件'.red if proj.nil?
|
81
|
+
nil
|
82
|
+
else
|
83
|
+
project_path = File.join(Dir.pwd, "./" + proj)
|
84
|
+
project = Xcodeproj::Project.open(project_path)
|
85
|
+
project
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def auto_add_tag(tag)
|
90
|
+
tag_points = tag.to_s.split('.')
|
91
|
+
index = tag_points.length - 1
|
92
|
+
need_add_point = tag_points[index].to_i + 1
|
93
|
+
tag_points[index] = need_add_point == 10 ? 0 : need_add_point
|
94
|
+
while need_add_point == 10 && index > 0
|
95
|
+
index = index - 1
|
96
|
+
need_add_point = tag_points[index].to_i + 1
|
97
|
+
tag_points[index] = need_add_point == 10 && index != 0 ? 0 : need_add_point
|
98
|
+
end
|
99
|
+
tag_points.join('.')
|
50
100
|
end
|
51
101
|
end
|
52
102
|
end
|
data/lib/gct/command/analyze.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'tmpdir'
|
3
|
+
require 'parallel'
|
3
4
|
|
4
5
|
module Gct
|
5
6
|
class Command
|
@@ -9,7 +10,16 @@ module Gct
|
|
9
10
|
分析podfile完整依赖链,并输出json文件.
|
10
11
|
DESC
|
11
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
|
+
|
12
19
|
def initialize(argv)
|
20
|
+
@project_id = argv.shift_argument
|
21
|
+
@file = argv.shift_argument
|
22
|
+
@branch = argv.shift_argument
|
13
23
|
super
|
14
24
|
end
|
15
25
|
|
@@ -19,11 +29,98 @@ module Gct
|
|
19
29
|
end
|
20
30
|
|
21
31
|
def validate!
|
32
|
+
help! '必须输入项目名.' unless @project_id
|
33
|
+
help! '必须输入读取文件的相对路径.' unless @file
|
34
|
+
help! '必须输入读取文件的项目分支.' unless @branch
|
22
35
|
super
|
23
36
|
end
|
24
37
|
|
25
38
|
def run
|
26
|
-
|
39
|
+
analyze_dependencies
|
40
|
+
# update_podspec_version()
|
41
|
+
end
|
42
|
+
|
43
|
+
def podfile
|
44
|
+
contents = file_contents(@project_id, @file, @branch)
|
45
|
+
contents.force_encoding('UTF-8')
|
46
|
+
|
47
|
+
temp_local_file = TempLocalFile.new(contents, @file)
|
48
|
+
temp_local_file.write
|
49
|
+
full_path = temp_local_file.full_path
|
50
|
+
|
51
|
+
@podfile ||= begin
|
52
|
+
podfile = Pod::Podfile.from_ruby(full_path, contents)
|
53
|
+
podfile
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def analyze_dependencies
|
58
|
+
untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
|
59
|
+
puts untagged_git_dependencies
|
60
|
+
# untagged_specs = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
|
61
|
+
# require 'json'
|
62
|
+
# puts "#{Constant.NameSpace}#{dep.name}"
|
63
|
+
# puts "#{dep.name}.podspec"
|
64
|
+
# puts Constant.DefaultTagBranch
|
65
|
+
|
66
|
+
# contents_json = file_contents("#{Constant.NameSpace}#{dep.name}", "#{dep.name}.podspec", Constant.DefaultTagBranch)
|
67
|
+
# podspec = system contents_json
|
68
|
+
# puts podspec.class
|
69
|
+
# puts podspec
|
70
|
+
# podspec = from_string("", contents_json)
|
71
|
+
# podspec = Pod::Spec.new do |spec|
|
72
|
+
|
73
|
+
# end
|
74
|
+
|
75
|
+
|
76
|
+
# puts podspec.class.to_s
|
77
|
+
# puts podspec.to_s
|
78
|
+
# gct_spec = Specification.new()
|
79
|
+
# gct_spec.specification = podspec
|
80
|
+
# gct_spec.priority = 1000
|
81
|
+
# gct_spec.status = SpecPublishStatus::CREATED
|
82
|
+
# gct_spec.tag = "0"
|
83
|
+
|
84
|
+
# update_podspec_version(spec)
|
85
|
+
# gct_spec
|
86
|
+
# end
|
87
|
+
end
|
88
|
+
|
89
|
+
def update_podspec_version(spec)
|
90
|
+
content = file_contents("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch)
|
91
|
+
now_version = spec.version
|
92
|
+
version = auto_add_tag(now_version)
|
93
|
+
require_variable_prefix = true
|
94
|
+
version_var_name = 'version'
|
95
|
+
variable_prefix = require_variable_prefix ? /\w\./ : //
|
96
|
+
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
|
97
|
+
version_match = version_regex.match(content)
|
98
|
+
updated_podspec_content = content.gsub(version_regex, "#{version_match[:begin]}#{version}#{version_match[:end]}")
|
99
|
+
updated_podspec_content
|
100
|
+
|
101
|
+
edit_file(spec, updated_podspec_content, version)
|
102
|
+
mr_to_master(spec)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def edit_file(spec, content, version)
|
108
|
+
Gitlab.edit_file("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch, content, "@config 升级版本号:#{version}")
|
109
|
+
end
|
110
|
+
|
111
|
+
def mr_to_master(spec)
|
112
|
+
mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{dep.name}", "podpesc修改", { source_branch: 'develop', target_branch: 'master' })
|
113
|
+
id = mr.iid
|
114
|
+
puts mr.to_hash
|
115
|
+
if mr.merge_status == 'cannot_be_merged'
|
116
|
+
raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{spec.name}/merge_requests/#{id} 解决".red
|
117
|
+
end
|
118
|
+
|
119
|
+
accept_merge_request(spec, id)
|
120
|
+
end
|
121
|
+
|
122
|
+
def accept_merge_request(spec, id)
|
123
|
+
Gitlab.accept_merge_request("#{Constant.NameSpace}#{dep.name}", id)
|
27
124
|
end
|
28
125
|
end
|
29
126
|
end
|
data/lib/gct/command/build/r.rb
CHANGED
@@ -24,19 +24,8 @@ module Gct
|
|
24
24
|
|
25
25
|
def buildR
|
26
26
|
puts "starting search R script ...".green
|
27
|
-
|
28
|
-
|
29
|
-
if subfile.include? '.xcodeproj'
|
30
|
-
proj = subfile
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
if proj == ''
|
35
|
-
puts '没有找到.xcodeproj文件'.red
|
36
|
-
else
|
37
|
-
project_path = File.join(Dir.pwd, "./" + proj)
|
38
|
-
project = Xcodeproj::Project.open(project_path)
|
39
|
-
|
27
|
+
project = get_project
|
28
|
+
if project
|
40
29
|
objects = project.objects
|
41
30
|
findR = false
|
42
31
|
objects.each do |obj|
|
data/lib/gct/command/config.rb
CHANGED
@@ -4,11 +4,39 @@ require 'gct/command/config/get'
|
|
4
4
|
module Gct
|
5
5
|
class Command
|
6
6
|
class Config < Command
|
7
|
-
self.abstract_command = true
|
8
7
|
self.summary = 'gct 配置'
|
9
8
|
self.description = <<-DESC
|
10
9
|
配置全局链接等
|
11
10
|
DESC
|
11
|
+
|
12
|
+
def initialize(argv)
|
13
|
+
@list = argv.flag?('list', false)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
# get_all_config if @list
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.options
|
22
|
+
[
|
23
|
+
['--list', '打印config所有信息'],
|
24
|
+
].concat(super)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_config(key)
|
28
|
+
file_base = FileBase.new(config_path)
|
29
|
+
file_base.yaml_read(key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.set_config(key, value)
|
33
|
+
file_base = FileBase.new(config_path)
|
34
|
+
file_base.yaml_write(key, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.config_path
|
38
|
+
"#{Generator::GctFile.config_file_path}"
|
39
|
+
end
|
12
40
|
end
|
13
41
|
end
|
14
42
|
end
|
@@ -9,25 +9,21 @@ module Gct
|
|
9
9
|
DESC
|
10
10
|
|
11
11
|
self.arguments = [
|
12
|
-
CLAide::Argument.new('
|
12
|
+
CLAide::Argument.new('KEY', true),
|
13
13
|
]
|
14
14
|
|
15
15
|
def initialize(argv)
|
16
|
-
@
|
16
|
+
@key = argv.shift_argument
|
17
17
|
super
|
18
|
-
@additional_args = argv.remainder!
|
19
18
|
end
|
20
19
|
|
21
20
|
def validate!
|
22
21
|
super
|
23
|
-
help! '
|
24
|
-
help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
|
25
|
-
help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
|
26
|
-
help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
|
22
|
+
help! '请输入key.' unless @key
|
27
23
|
end
|
28
24
|
|
29
25
|
def run
|
30
|
-
puts "
|
26
|
+
puts "#{@key}: #{get_config(@key)}"
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -8,26 +8,25 @@ module Gct
|
|
8
8
|
设置gct全局配置.
|
9
9
|
DESC
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('KEY', true),
|
13
|
+
CLAide::Argument.new('VALUE', true),
|
14
|
+
]
|
14
15
|
|
15
16
|
def initialize(argv)
|
16
|
-
@
|
17
|
+
@key = argv.shift_argument
|
18
|
+
@value = argv.shift_argument
|
17
19
|
super
|
18
|
-
# @additional_args = argv.remainder!
|
19
20
|
end
|
20
21
|
|
21
22
|
def validate!
|
22
23
|
super
|
23
|
-
|
24
|
-
|
25
|
-
# help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
|
26
|
-
# help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
|
24
|
+
help! '请输入key.' unless @key
|
25
|
+
help! '请输入value.' unless @value
|
27
26
|
end
|
28
27
|
|
29
28
|
def run
|
30
|
-
|
29
|
+
set_config(@key, @value)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
data/lib/gct/command/init/ci.rb
CHANGED
@@ -9,25 +9,20 @@ module Gct
|
|
9
9
|
DESC
|
10
10
|
|
11
11
|
self.arguments = [
|
12
|
-
CLAide::Argument.new('NAME', true),
|
13
12
|
]
|
14
13
|
|
15
14
|
def initialize(argv)
|
16
|
-
@name = argv.shift_argument
|
17
15
|
super
|
18
|
-
@additional_args = argv.remainder!
|
19
16
|
end
|
20
17
|
|
21
18
|
def validate!
|
22
19
|
super
|
23
|
-
help! 'A name for the Pod is required.' unless @name
|
24
|
-
help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
|
25
|
-
help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
|
26
|
-
help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
|
27
20
|
end
|
28
21
|
|
29
22
|
def run
|
30
|
-
puts "
|
23
|
+
puts "init ci".green
|
24
|
+
cp_path = Pathname.new(__FILE__).parent + 'gitlab-ci.rb'
|
25
|
+
system "cp #{cp_path} .gitlab-ci.yml"
|
31
26
|
end
|
32
27
|
end
|
33
28
|
end
|
data/lib/gct/command/op.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'gct/command/op/gems'
|
2
2
|
require 'gct/command/op/gitconf'
|
3
3
|
require 'gct/command/op/xcache'
|
4
|
+
require 'gct/command/op/root'
|
4
5
|
|
5
6
|
module Gct
|
6
7
|
class Command
|
@@ -10,6 +11,7 @@ module Gct
|
|
10
11
|
self.description = <<-DESC
|
11
12
|
打开常用文件夹,并输出路径
|
12
13
|
DESC
|
14
|
+
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Op < Command
|
4
|
+
class Root < Op
|
5
|
+
|
6
|
+
self.summary = '打开gct文件夹'
|
7
|
+
self.description = <<-DESC
|
8
|
+
打开gct文件夹
|
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
|
+
openGct
|
24
|
+
end
|
25
|
+
|
26
|
+
def openGct
|
27
|
+
root_path = Generator::GctFile.root_folder_path
|
28
|
+
system "open #{root_path}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/gct/command/repo/add.rb
CHANGED
@@ -25,7 +25,7 @@ module Gct
|
|
25
25
|
|
26
26
|
def addRepo
|
27
27
|
puts "pod命令为:pod repo add iOSCRGTPodSource https://gi-dev.ccrgt.com/ios/iOSCRGTPodSource.git".green
|
28
|
-
system "pod repo add iOSCRGTPodSource https://gi-dev.ccrgt.com/ios/iOSCRGTPodSource.git
|
28
|
+
system "pod repo add iOSCRGTPodSource https://gi-dev.ccrgt.com/ios/iOSCRGTPodSource.git", exception: true
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -25,7 +25,8 @@ module Gct
|
|
25
25
|
|
26
26
|
def pushRepo
|
27
27
|
puts "pod 命令为:pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings".green
|
28
|
-
|
28
|
+
# exception: ruby 2.6 以上生效
|
29
|
+
system "pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --verbose --skip-import-validation --use-libraries --allow-warnings", exception: true
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -25,7 +25,7 @@ module Gct
|
|
25
25
|
|
26
26
|
def updateRepo
|
27
27
|
puts "pod命令为:pod repo update iOSCRGTPodSource".green
|
28
|
-
system "pod repo update iOSCRGTPodSource
|
28
|
+
system "pod repo update iOSCRGTPodSource", exception: true
|
29
29
|
puts "如果找不到 iOSCRGTPodSource 文件,先执行gct repo add".green
|
30
30
|
end
|
31
31
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Setup < Command
|
4
|
+
|
5
|
+
self.summary = '设置Gct'
|
6
|
+
self.description = <<-DESC
|
7
|
+
创建gct的全局隐藏文件,配置全局参数,缓存文件等
|
8
|
+
DESC
|
9
|
+
|
10
|
+
def initialize(argv)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
create_root_folder
|
16
|
+
create_temp_folder
|
17
|
+
create_config_file
|
18
|
+
puts "setup success!".green
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_root_folder
|
22
|
+
gct_path = Generator::GctFile.root_folder_path
|
23
|
+
if !File.exist?(gct_path)
|
24
|
+
system "mkdir #{gct_path}", exception: true
|
25
|
+
puts "#{gct_path} 创建成功!".green
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_temp_folder
|
30
|
+
temp_path = Generator::GctFile.temp_folder_path
|
31
|
+
if !File.exist?(temp_path)
|
32
|
+
system "mkdir #{temp_path}", exception: true
|
33
|
+
puts "#{temp_path} 创建成功!".green
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_config_file
|
38
|
+
config_path = Generator::GctFile.config_file_path
|
39
|
+
if !File.exist?(config_path)
|
40
|
+
system "touch #{config_path}", exception: true
|
41
|
+
puts "#{config_path} 创建成功!".green
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'gct/command/update/tag'
|
2
|
+
require 'gct/command/update/version'
|
3
|
+
|
4
|
+
module Gct
|
5
|
+
class Command
|
6
|
+
class Update < Command
|
7
|
+
self.abstract_command = true
|
8
|
+
self.summary = '更新操作'
|
9
|
+
self.description = <<-DESC
|
10
|
+
更新组件tag、主工程版本号等
|
11
|
+
DESC
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Tag < Update
|
5
|
+
|
6
|
+
self.summary = '添加tag'
|
7
|
+
self.description = <<-DESC
|
8
|
+
十进制增加tag版本
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('TAG', false),
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize(argv)
|
16
|
+
@tag = argv.shift_argument
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate!
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
get_now_tag
|
26
|
+
add_push_new_tag
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_tag_podspec
|
30
|
+
# 更新podspec的版本号 @new_tag 创建MR推送到远端
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_now_tag
|
35
|
+
spec_file = Pathname.glob('*.podspec').first
|
36
|
+
raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
|
37
|
+
|
38
|
+
spec = Pod::Specification.from_file(spec_file)
|
39
|
+
@now_tag = spec.version
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_push_new_tag
|
43
|
+
@new_tag = @tag || auto_add_tag(@now_tag.to_s)
|
44
|
+
update_tag_podspec
|
45
|
+
`git tag #{@new_tag}`
|
46
|
+
`git push origin #{@new_tag} || { exit 1; }`
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Gct
|
2
|
+
class Command
|
3
|
+
class Update < Command
|
4
|
+
class Version < Update
|
5
|
+
|
6
|
+
self.summary = '更新版本号'
|
7
|
+
self.description = <<-DESC
|
8
|
+
更新release分支的版本号
|
9
|
+
DESC
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('NAME', false),
|
13
|
+
CLAide::Argument.new('VERSION', false),
|
14
|
+
]
|
15
|
+
|
16
|
+
def initialize(argv)
|
17
|
+
@name = argv.shift_argument
|
18
|
+
@version = argv.shift_argument
|
19
|
+
name = @name ||= "iLife"
|
20
|
+
@project_id = "#{Constant.NameSpace}#{name}"
|
21
|
+
@file = "#{name}.xcodeproj/project.pbxproj"
|
22
|
+
@branch = current_branch.rstrip
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate!
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
update_version
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_version
|
35
|
+
if check_branch_can_be_update
|
36
|
+
content = file_contents(@project_id, @file, @branch)
|
37
|
+
version_var_name = 'MARKETING_VERSION = '
|
38
|
+
version_regex = /(?<=#{version_var_name})\w.*(?=;)/
|
39
|
+
version_match = version_regex.match(content)
|
40
|
+
version = @version ||= auto_add_tag(version_match)
|
41
|
+
updated_content = content.gsub(version_regex, version)
|
42
|
+
edit_file(updated_content, version)
|
43
|
+
else
|
44
|
+
puts "当前不是release分支".red
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def edit_file(content, version)
|
49
|
+
Gitlab.edit_file(@project_id, @file, @branch, content, "@config 更新版本号:#{version}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_branch_can_be_update
|
53
|
+
current_branch.include?('release')
|
54
|
+
end
|
55
|
+
|
56
|
+
def current_branch
|
57
|
+
"#{`git branch | awk '$1 == "*" {print $2}'`}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/gct/constant.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Gct
|
2
2
|
module Constant
|
3
3
|
class << self
|
4
|
+
def GitBaseURL
|
5
|
+
"https://gi-dev.ccrgt.com/"
|
6
|
+
end
|
7
|
+
|
4
8
|
def GitThirdURL
|
5
9
|
"https://gi-dev.ccrgt.com/ios-thirdpart/"
|
6
10
|
end
|
@@ -8,6 +12,18 @@ module Gct
|
|
8
12
|
def GitURL
|
9
13
|
"https://gi-dev.ccrgt.com/ios/"
|
10
14
|
end
|
15
|
+
|
16
|
+
def NameSpace
|
17
|
+
"ios/"
|
18
|
+
end
|
19
|
+
|
20
|
+
def ThirdNameSpace
|
21
|
+
"ios-third/"
|
22
|
+
end
|
23
|
+
|
24
|
+
def DefaultTagBranch
|
25
|
+
"develop"
|
26
|
+
end
|
11
27
|
end
|
12
28
|
end
|
13
29
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Gct
|
2
|
+
class FileBase
|
3
|
+
|
4
|
+
attr_reader :path
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def yaml_write(key, value)
|
11
|
+
begin
|
12
|
+
yaml_file = File.open(@path, "w")
|
13
|
+
YAML::dump({key => value}, yaml_file)
|
14
|
+
rescue IOError => e
|
15
|
+
raise e.message
|
16
|
+
ensure
|
17
|
+
yaml_file.close unless yaml_file.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def yaml_read(key)
|
22
|
+
begin
|
23
|
+
yaml_file = YAML.load(File.open(@path, "r"))
|
24
|
+
yaml_file[key]
|
25
|
+
rescue IOError => e
|
26
|
+
raise e.message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Gct
|
2
|
+
module Generator
|
3
|
+
class GctFile
|
4
|
+
|
5
|
+
def self.root_folder_path
|
6
|
+
"/Users/#{get_system_user_name.rstrip}/.gct"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.temp_folder_path
|
10
|
+
"/Users/#{get_system_user_name.rstrip}/.gct/tmp"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.config_file_path
|
14
|
+
"/Users/#{get_system_user_name.rstrip}/.gct/config"
|
15
|
+
end
|
16
|
+
|
17
|
+
# 获取系统用户名
|
18
|
+
def self.get_system_user_name
|
19
|
+
# windows
|
20
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
21
|
+
query = `reg query HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer /v "Logon User Name"`
|
22
|
+
/Logon\ User\ Name\s+REG_SZ\s+(\S+)/ =~ query
|
23
|
+
"#{$1}"
|
24
|
+
# unix, cygwin, mac
|
25
|
+
else
|
26
|
+
"#{`whoami`}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gct
|
2
|
+
# attr_accessor get and set
|
3
|
+
# attr_reader only get
|
4
|
+
# attr_writer only set
|
5
|
+
class Specification
|
6
|
+
# Pod::Dependency
|
7
|
+
attr_accessor :specification
|
8
|
+
|
9
|
+
# 优先级
|
10
|
+
attr_accessor :priority
|
11
|
+
|
12
|
+
# tag版本
|
13
|
+
attr_accessor :tag
|
14
|
+
|
15
|
+
# 发布状态
|
16
|
+
attr_accessor :status
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
@specification = specification
|
20
|
+
@priority = priority
|
21
|
+
@status = status
|
22
|
+
@tag = tag
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module SpecPublishStatus
|
28
|
+
CREATED = '待分析'
|
29
|
+
ANALYZING = '分析中'
|
30
|
+
PREPARING = '准备中'
|
31
|
+
PENDING = '等待中'
|
32
|
+
WAITING = '待发布'
|
33
|
+
SKIPPED = '已忽略'
|
34
|
+
MERGED = '已合并'
|
35
|
+
DEPLOYING = '发布中'
|
36
|
+
SUCCESS = '发布成功'
|
37
|
+
FAILED = '发布失败'
|
38
|
+
CANCELED = '已取消'
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Gct
|
2
|
+
class TempLocalFile
|
3
|
+
attr_reader :content
|
4
|
+
|
5
|
+
attr_reader :file_name
|
6
|
+
|
7
|
+
def initialize(content, file_name)
|
8
|
+
@content = content
|
9
|
+
@file_name = file_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def write
|
13
|
+
begin
|
14
|
+
file = File.open(tmp_folder, "w")
|
15
|
+
file.write(@content)
|
16
|
+
rescue IOError => e
|
17
|
+
raise e.message
|
18
|
+
ensure
|
19
|
+
file.close unless file.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def read
|
24
|
+
begin
|
25
|
+
file = File.open(tmp_folder, "r")
|
26
|
+
file.read
|
27
|
+
rescue IOError => e
|
28
|
+
raise e.message
|
29
|
+
ensure
|
30
|
+
file.close unless file.nil?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def full_path
|
35
|
+
tmp_folder
|
36
|
+
end
|
37
|
+
|
38
|
+
def tmp_folder
|
39
|
+
"#{Generator::GctFile.temp_folder_path}/#{file_name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Gct
|
2
|
+
class TempRemoteFile
|
3
|
+
attr_reader :uri
|
4
|
+
|
5
|
+
def initialize(url, content)
|
6
|
+
@uri = URI.parse(url)
|
7
|
+
@content = content
|
8
|
+
end
|
9
|
+
|
10
|
+
def file
|
11
|
+
@file ||= Tempfile.open(tmp_filename, tmp_folder, encoding: encoding) do |f|
|
12
|
+
puts f
|
13
|
+
io.rewind
|
14
|
+
f.write(io.read)
|
15
|
+
f.close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
@file.close
|
21
|
+
@file.unlink
|
22
|
+
end
|
23
|
+
|
24
|
+
def io
|
25
|
+
@io ||= uri.open
|
26
|
+
end
|
27
|
+
|
28
|
+
def encoding
|
29
|
+
io.rewind
|
30
|
+
io.read.encoding
|
31
|
+
end
|
32
|
+
|
33
|
+
def tmp_filename
|
34
|
+
[
|
35
|
+
Pathname.new(uri.path).basename,
|
36
|
+
Pathname.new(uri.path).extname
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def tmp_folder
|
41
|
+
Generator::GctFile.temp_folder_path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jieming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,34 @@ dependencies:
|
|
106
106
|
- - "<"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '2.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: gitlab
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :runtime
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: parallel
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
109
137
|
description: '"gct ios 自动化脚本工具"'
|
110
138
|
email:
|
111
139
|
- 307113345@qq.com
|
@@ -130,19 +158,30 @@ files:
|
|
130
158
|
- lib/gct/command/create/third.rb
|
131
159
|
- lib/gct/command/init.rb
|
132
160
|
- lib/gct/command/init/ci.rb
|
161
|
+
- lib/gct/command/init/gitlab-ci.rb
|
133
162
|
- lib/gct/command/init/unit.rb
|
134
163
|
- lib/gct/command/op.rb
|
135
164
|
- lib/gct/command/op/gems.rb
|
136
165
|
- lib/gct/command/op/gitconf.rb
|
166
|
+
- lib/gct/command/op/root.rb
|
137
167
|
- lib/gct/command/op/xcache.rb
|
138
168
|
- lib/gct/command/repo.rb
|
139
169
|
- lib/gct/command/repo/add.rb
|
140
170
|
- lib/gct/command/repo/push.rb
|
141
171
|
- lib/gct/command/repo/update.rb
|
172
|
+
- lib/gct/command/setup.rb
|
142
173
|
- lib/gct/command/spec.rb
|
143
174
|
- lib/gct/command/spec/lint.rb
|
175
|
+
- lib/gct/command/update.rb
|
176
|
+
- lib/gct/command/update/tag.rb
|
177
|
+
- lib/gct/command/update/version.rb
|
144
178
|
- lib/gct/constant.rb
|
145
|
-
- lib/gct/
|
179
|
+
- lib/gct/file_base.rb
|
180
|
+
- lib/gct/gct_version.rb
|
181
|
+
- lib/gct/generator/gct_file.rb
|
182
|
+
- lib/gct/specification.rb
|
183
|
+
- lib/gct/temp_local_file.rb
|
184
|
+
- lib/gct/temp_remote_file.rb
|
146
185
|
homepage: https://gi-dev.ccrgt.com/ios-thirdpart/gct
|
147
186
|
licenses: []
|
148
187
|
metadata:
|
@@ -155,15 +194,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
194
|
requirements:
|
156
195
|
- - ">="
|
157
196
|
- !ruby/object:Gem::Version
|
158
|
-
version: '
|
197
|
+
version: '2.6'
|
159
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
199
|
requirements:
|
161
200
|
- - ">="
|
162
201
|
- !ruby/object:Gem::Version
|
163
202
|
version: '0'
|
164
203
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.7.7
|
204
|
+
rubygems_version: 3.0.3
|
167
205
|
signing_key:
|
168
206
|
specification_version: 4
|
169
207
|
summary: '"gct ios 自动化脚本工具"'
|