class PodsOrz::BinaryRepo

Attributes

binary_server[RW]
repo_name[RW]
repo_url[RW]

Public Class Methods

new(main_path) click to toggle source
# File lib/podsorz/core/Binary/binary_repo.rb, line 11
def initialize(main_path)
        @repo_name = "kuxiu_binary_specs"
        @repo_url = "git@gitlab.91banban.com:ios_pods/binary-specs.git"
        @orzconfig_parse = PodsOrz::PodOrzconfigParse.new(main_path)
        # 替换成config配置参数
        # @source_code_repo_url = "git@gitlab.91banban.com:ios_pods/Specs.git"
        @source_code_repo_url = @orzconfig_parse.remote_url_codespec
        @binary_server = PodsOrz::BinaryServer.new()
end

Public Instance Methods

check_binary_pod_exist(pod, pod_version) click to toggle source
# 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_exist() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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