Class: PodsOrz::BinaryRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/podsorz/core/Binary/binary_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(main_path) ⇒ BinaryRepo

Returns a new instance of BinaryRepo.



11
12
13
14
15
16
17
18
19
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 11

def initialize(main_path)
	@repo_name = "kuxiu_binary_specs"
	@repo_url = "[email protected]:ios_pods/binary-specs.git"
	@orzconfig_parse = PodsOrz::PodOrzconfigParse.new(main_path)
	# 替换成config配置参数
	# @source_code_repo_url = "[email protected]:ios_pods/Specs.git"
	@source_code_repo_url = @orzconfig_parse.remote_url_codespec
	@binary_server = PodsOrz::BinaryServer.new()
end

Instance Attribute Details

#binary_serverObject

Returns the value of attribute binary_server.



9
10
11
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 9

def binary_server
  @binary_server
end

#repo_nameObject

Returns the value of attribute repo_name.



9
10
11
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 9

def repo_name
  @repo_name
end

#repo_urlObject

Returns the value of attribute repo_url.



9
10
11
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 9

def repo_url
  @repo_url
end

Instance Method Details

#check_binary_pod_exist(pod, pod_version) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 50

def check_binary_pod_exist(pod, pod_version)
	result = false

	remote_version_list = fetch_remote_binary_pod_version(pod)

	remote_version_list.each do |version|
		if version.include? pod_version
			result = true
		end
		
	end

	result
end

#check_binary_repo_existObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 21

def check_binary_repo_exist()
	command = Thread.new do 
		has_repo = false
		Open3.popen3("pod repo list") do |stdin , stdout , stderr, wait_thr|
	        while line = stdout.gets
	          has_repo = true if line.include? @repo_name
	        end
	    end

		unless has_repo
			Open3.popen3("pod repo add #{@repo_name} #{@repo_url}") do |stdin , stdout , stderr, wait_thr|
		        while line = stdout.gets
			          puts line
			    end
		    end
		end

		Open3.popen3("pod repo update #{@repo_name}") do |stdin , stdout , stderr, wait_thr|
	        while line = stdout.gets
		          puts line
		    end
	    end

		Logger.default("#{@repo_name} is update to latest.")
	end

	command.join
end

#compare_version(pod_version, git_tag) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 93

def compare_version(pod_version, git_tag)
	#0 => same , -1 => less , 1 => more
	result = 0

	pod_version = pod_version.strip.chomp
	git_tag = git_tag.strip.chomp

	version_parts = pod_version.split('.')
	tag_parts = git_tag.split('.')

	loop_count = 0
	if version_parts.size >= tag_parts.size
		loop_count = version_parts.size - tag_parts.size
		while loop_count > 0 do
			tag_parts << "0"
			loop_count = loop_count - 1
		end
	else
		loop_count = tag_parts.size - version_parts.size
		while loop_count > 0 do
			version_parts << "0"
			loop_count = loop_count - 1
		end
	end

	loop_count = tag_parts.size
	while loop_count > 0 do
		v = version_parts.shift
		t = tag_parts.shift

		if v.to_i > t.to_i
			result = 1
			return result
		elsif v.to_i < t.to_i
			result = -1
			return result
		else
			loop_count = loop_count -1
		end
	end

	return result
	
end

#fetch_remote_binary_pod_version(pod) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 65

def fetch_remote_binary_pod_version(pod)
	version_list = []

	dir_kuxiu_specs = "#{Dir.home}/.cocoapods/repos/#{@repo_name}"
	dir_pod_path = File.expand_path("#{pod}", dir_kuxiu_specs)
	is_dir_exit = File.directory?(dir_pod_path)

	unless is_dir_exit
		version_list << "0.0.0"
		return version_list
	end

	filter_list = []
	files_list = Dir.entries(dir_pod_path)
	files_list.each { |e|
		if /^\d{1,3}\.\d{1,3}/ =~ e.to_s
			filter_list << e
		end
	}

	if filter_list.empty?
		version_list << "0.0.0"
		return version_list
	end

	return filter_list
end

#push_binary_remote(pod, file_path, pod_version, is_swift) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 139

def push_binary_remote(pod, file_path, pod_version, is_swift)
	is_push_success = false

	#1.上传文件到服务器
	is_push_success = @binary_server.upload_pod_file(pod, file_path, pod_version)
	return is_push_success unless is_push_success

	#2.发布到binary_repo
	is_push_success = start_publish_binary(pod, file_path, pod_version, is_swift)
	
        	is_push_success
end

#start_publish_binary(pod, file_path, pod_version, is_swift) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/podsorz/core/Binary/binary_repo.rb', line 152

def start_publish_binary(pod, file_path, pod_version, is_swift)
	is_push_success = false

	command = Thread.new do 
		repo_push_cmd = []
		repo_push_cmd << "cd #{file_path}"
		if is_swift
			repo_push_cmd << "pod repo push #{@repo_name} #{pod}.podspec --sources=#{@source_code_repo_url} --allow-warnings --use-libraries --skip-import-validation  --use-modular-headers --swift-version=5.0 --skip-tests"
		else
			repo_push_cmd << "pod repo push #{@repo_name} #{pod}.podspec --sources=#{@source_code_repo_url} --allow-warnings --use-libraries --skip-import-validation --skip-tests"	
		end
		

		error_info = []

		Logger.separator()
		Logger.default("#{pod}】:#{pod_version} start push binary repo remote...")
		Logger.separator()

		IO.popen(repo_push_cmd.join(";")) do |io|	
			io.each do |line|
	            error_info.push(line)
	            is_push_success = true if line.include? "Pushing the `#{@repo_name}' repo"
         	end
        end

        unless is_push_success
            puts error_info
            Logger.error("Fail: \'#{pod}\':#{pod_version} push binary repo remote fail")
        else 
        	Logger.highlight(%Q(#{pod}:#{pod_version} push repo success))
         	end
	end

	command.join

        	is_push_success
end