Top Level Namespace
Defined Under Namespace
Modules: CBin, Pod Classes: PodUpdateConfig
Instance Method Summary collapse
- #get_branch_name ⇒ Object
-
#get_checksum(file_path) ⇒ Object
过滤出来podfile中实际有效每行内容,拼接成字符串在SHA1 后UTF-8编码下 用来当做依赖缓存文件的key.
-
#get_podfile_lock ⇒ Object
获取服务端podfile.lock文件.
- #upload_branch_podfile_lock ⇒ Object
- #upload_mbox_podfile_lock ⇒ Object
-
#upload_podfile_lock(checksum, upload = false) ⇒ Object
上传podfile.lock文件到服务端.
Instance Method Details
#get_branch_name ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 156 def get_branch_name branch_value = ENV['branch'] if !branch_value mtxx_path = Pod::Config.instance.installation_root + 'mtxx/MTXX' #判读podfile文件是否存在 if File.exist?(mtxx_path) Dir.chdir(mtxx_path) do branch_value = `git symbolic-ref --short -q HEAD` if branch_value == 'develop' branch_value = "" end end else branch_value = `git symbolic-ref --short -q HEAD` end end branch_value = branch_value.gsub("\n", "") branch_value end |
#get_checksum(file_path) ⇒ Object
过滤出来podfile中实际有效每行内容,拼接成字符串在SHA1 后UTF-8编码下 用来当做依赖缓存文件的key
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 176 def get_checksum(file_path) return nil unless File.exist?(file_path) content = "" lines = [] #过滤出实际使用pod File.open(file_path, 'r') do |file| file.each_line do |line| new_line = line.strip if new_line.start_with?("pod") lines << new_line end end end #给获取的pod list 排序,排除因组件顺序调整导致获取SHA1值不一样 lines = lines.sort lines.each do |line| content << line end checksum = Digest::SHA1.hexdigest(content) checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode) return checksum end |
#get_podfile_lock ⇒ Object
获取服务端podfile.lock文件
11 12 13 14 15 16 17 18 19 20 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 11 def get_podfile_lock begin # 默认是获取要获取服务端podfile.lock文件 is_load_podfile_lock = true #目前只支持MTXX target "MTXX" 项目 #想要支持其他项目可以添加对应 target "xxx" content = File.read(Pod::Config.instance.podfile_path) if content if content.include?("target \"MTXX\"") is_load_podfile_lock = true PodUpdateConfig.set_is_mtxx(true) else is_load_podfile_lock = false PodUpdateConfig.set_is_mtxx(false) end end # MEITU_LOAD_CACHE_PODFILE_LOCK 为false时不获取服务端podfile.lock文件 if ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] && ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] == 'false' is_load_podfile_lock = false end # 判断是否有update参数 时不获取服务端podfile.lock文件 ARGV.each do |arg| if arg == 'update' || arg == '--no-cloud' is_load_podfile_lock = false end end # podfile.lock文件下载和使用逻辑 if is_load_podfile_lock #获取 PODFILE CHECKSUM 用来判断服务端是否存在该podfile.lock checksum = get_checksum(Pod::Config.instance.podfile_path) PodUpdateConfig.set_checksum(checksum) Pod::UI.puts "当前podfile文件的checksum:#{checksum}".green # zip下载地址 curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{checksum}/podfile.lock.zip" # 判断服务端是否存在该podfile.lock is_load_podfile_lock = false if system("curl -o /dev/null -s -w %{http_code} #{curl} | grep 200 > /dev/null 2>&1") Pod::UI.puts "匹配到精准podfile.lock文件,使用当前podfile文件的checksum:#{checksum}获取对应的podfile.lock文件".green is_load_podfile_lock = true end if !is_load_podfile_lock branch_value = get_branch_name curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{branch_value}/podfile.lock.zip" if system("curl -o /dev/null -s -w %{http_code} #{curl} | grep 200 > /dev/null 2>&1") Pod::UI.puts "无法匹配到精准podfile.lock文件,使用当前分支:#{branch_value} 对应的podfile.lock文件".green is_load_podfile_lock = true end #兜底使用develop的podfile.lock if !is_load_podfile_lock Pod::UI.puts "服务端不存在该podfile.lock文件,使用develop分支的podfile.lock文件兜底".green curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/develop/podfile.lock.zip" is_load_podfile_lock = true end end # 判断是否需要下载podfile.lock文件 if is_load_podfile_lock Pod::UI.puts "获取服务端存储的podfile.lcok文件".green #下载并解压的podfile.zip文件 if system("curl -O #{curl} > /dev/null 2>&1") && system("unzip -o podfile.lock.zip > /dev/null 2>&1") Pod::UI.puts "下载并解压podfile.lcok文件成功".green `rm -rf podfile.lock.zip` # 设置获取到的podfile.lock对象 PodUpdateConfig.set_lockfile(Pod::Config.instance.installation_root + 'Podfile.lock') #获取analyzer Pod::UI.puts "提前根据checksum命中podfile.lcok进行依赖分析".green analyzer = Pod::Installer::Analyzer.new( Pod::Config.instance.sandbox, Pod::Config.instance.podfile, PodUpdateConfig.lockfile ) analyzer.update_repositories PodUpdateConfig.set_repo_update analyzer.analyze(true) #获取analyzer中所有git 且branch 指向的pod Pod::Config.instance.podfile.dependencies.map do |dependency| if dependency.external_source && dependency.external_source[:git] && (dependency.external_source[:branch] || (dependency.external_source.size == 1)) #brash 指定的组件添加到全局PodUpdateConfig配置中,执行pod install 需要更新的分支最新提交 PodUpdateConfig.add_value(dependency.name) end end else puts "获取podfile.lcok文件失败" `rm -rf podfile.lock.zip` end end end rescue => error puts "podfile.lcok相关处理发生异常,报错原因:#{error}" PodUpdateConfig.clear `rm -rf podfile.lock.zip` `rm -rf podfile.lock` end end |
#upload_branch_podfile_lock ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 140 def upload_branch_podfile_lock begin branch_value = get_branch_name if branch_value && branch_value.is_a?(String) && branch_value.length > 0 if system("zip podfile.lock.zip Podfile.lock > /dev/null 2>&1") && system("curl -F \"name=MTXX\" -F \"version=#{branch_value}\" -F \"file=@#{Pathname.pwd}/podfile.lock.zip\" http://nezha.community.cloud.meitu.com/file/upload.json > /dev/null 2>&1") Pod::UI.puts "根据开发分支名:#{branch_value}上报podfile.lcok文件到服务端成功".green `rm -rf podfile.lock.zip` else Pod::UI.puts "根据开发分支名:#{branch_value}上报podfile.lcok文件到服务端失败".red `rm -rf podfile.lock.zip` end end rescue => error end end |
#upload_mbox_podfile_lock ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 129 def upload_mbox_podfile_lock begin podfile_path = Pod::Config.instance.installation_root + 'mtxx/MTXX' + 'Podfile' checksum = get_checksum(podfile_path) if checksum && checksum.is_a?(String) && checksum.length > 0 upload_podfile_lock(checksum,true ) end rescue => error puts "mbox podfile.lcok文件兼容处理失败,失败原因:#{error}" end end |
#upload_podfile_lock(checksum, upload = false) ⇒ Object
上传podfile.lock文件到服务端
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 107 def upload_podfile_lock(checksum,upload = false) begin curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{checksum}/podfile.lock.zip" # 服务端不存在该podfiel.lock文件才上传,避免频繁上报同一个文件 if upload || !system("curl -o /dev/null -s -w %{http_code} #{curl} | grep 200 > /dev/null 2>&1") Pod::UI.puts "根据checksum:#{checksum}上报podfile.lcok文件到服务端".green if upload puts "mbox工作目录/mtxx/MTXX/podfile 对应的checksum = #{checksum}" end if system("zip podfile.lock.zip Podfile.lock > /dev/null 2>&1") && system("curl -F \"name=MTXX\" -F \"version=#{checksum}\" -F \"file=@#{Pathname.pwd}/podfile.lock.zip\" http://nezha.community.cloud.meitu.com/file/upload.json > /dev/null 2>&1") Pod::UI.puts "上报podfile.lcok文件到服务端成功".green `rm -rf podfile.lock.zip` else Pod::UI.puts "上报podfile.lcok文件到服务端失败".red `rm -rf podfile.lock.zip` end end rescue => error puts "上传podfile.lcok文件失败,失败原因:#{error}" `rm -rf podfile.zip` end end |