/
main.rb
78 lines (66 loc) · 2.1 KB
/
main.rb
1
2
3
4
5
6
7
8
9
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
require 'yaml'
require 'open3'
require 'find'
require 'fileutils'
require 'json'
def get_env_variable(key)
return (ENV[key] == nil || ENV[key] == "") ? nil : ENV[key]
end
android_home = get_env_variable("ANDROID_HOME") || abort('Missing ANDROID_HOME variable.')
ac_build_output_path = get_env_variable("AC_OUTPUT_DIR") || abort('Missing AC_OUTPUT_DIR variable.')
$latest_build_tools = Dir.glob("#{android_home}/build-tools/*").sort.last
apks = Dir.glob("#{ac_build_output_path}/**/*.apk")
aabs = Dir.glob("#{ac_build_output_path}/**/*.aab")
def run_command(command)
puts "@@[command] #{command}"
status = nil
stdout_str = nil
stderr_str = nil
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stdout_str = stdout.read
stderr_str = stderr.read
status = wait_thr.value
puts stdout_str
end
unless status.success?
puts stderr_str
raise stderr_str
end
return stdout_str
end
def is_signed(meta_files, path)
v2_signed = false
begin
v2_signed = run_command("#{$latest_build_tools}/apksigner verify --verbose \"#{path}\" | head -1").include?('Verifies')
rescue StandardError
v2_signed = false
end
return true if v2_signed
meta_files.each do |file|
if file.downcase.include?(".dsa") || file.downcase.include?(".rsa")
return true
end
end
return false
end
def filter_meta_files(path)
return run_command("#{$latest_build_tools}/aapt ls \"#{path}\" | grep META-INF").split("\n")
end
datas = []
apks.concat(aabs).each do |artifact_path|
base_name = File.basename(artifact_path)
meta_files = filter_meta_files(artifact_path)
datas.push({
"signed": is_signed(meta_files,artifact_path),
"app_name": base_name
})
end
post_process_output_file_path = "#{ac_build_output_path}/ac_post_process_output.json"
File.open(post_process_output_file_path, "w") do |f|
f.write(datas.to_json)
end
# Write Environment Variable
open(ENV['AC_ENV_FILE_PATH'], 'a') { |f|
f.puts "AC_ANDROID_POST_PROCESS_OUTPUT_PATH=#{post_process_output_file_path}"
}
exit 0