Top Level Namespace
Defined Under Namespace
Modules: CBin, Pod
Classes: PodUpdateConfig
Instance Method Summary
collapse
Instance Method Details
#get_branch_name ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 143
def get_branch_name
branch_value = ENV['branch']
if !branch_value
mtxx_path = Pod::Config.instance.installation_root + 'mtxx/MTXX'
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
163
164
165
166
167
168
169
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 163
def get_checksum(file_path)
return nil unless File.exist?(file_path)
content = File.read(file_path)
checksum = Digest::SHA1.hexdigest(content)
checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode)
return checksum
end
|
#get_podfile_lock ⇒ Object
10
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
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 10
def get_podfile_lock
begin
is_load_podfile_lock = true
if ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] && ENV['MEITU_LOAD_CACHE_PODFILE_LOCK'] == 'false'
is_load_podfile_lock = false
end
ARGV.each do |arg|
if arg == 'update'
is_load_podfile_lock = false
end
end
if is_load_podfile_lock
checksum = Pod::Config.instance.podfile.checksum
Pod::UI.puts "当前podfile文件的checksum:#{checksum}".green
curl = "https://xiuxiu-dl-meitu-com.obs.cn-north-4.myhuaweicloud.com/ios/binary/MTXX/#{checksum}/podfile.lock.zip"
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
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
if is_load_podfile_lock
Pod::UI.puts "获取服务端存储的podfile.lcok文件".green
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`
PodUpdateConfig.set_lockfile(Pod::Config.instance.installation_root + 'Podfile.lock')
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)
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))
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 127
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
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 116
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/cocoapods-meitu-bin/source_provider_hook.rb', line 94
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"
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
|