-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
executable file
·77 lines (63 loc) · 2.41 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
require 'yaml'
require 'open3'
require 'find'
require 'fileutils'
require 'pathname'
def get_env_variable(key)
return (ENV[key] == nil || ENV[key] == "") ? nil : ENV[key]
end
ac_variants = get_env_variable("AC_VARIANTS") || abort('Missing variants.')
ac_repo_path = get_env_variable("AC_REPOSITORY_DIR") || abort('Missing AC_REPOSITORY_DIR variable.')
temp_folder = get_env_variable("AC_TEMP_DIR") || abort('Missing AC_TEMP_DIR variable.')
ac_project_path = get_env_variable("AC_PROJECT_PATH") || "."
ac_module = get_env_variable("AC_MODULE") || abort('Missing module.')
ac_output_folder = get_env_variable("AC_OUTPUT_DIR") || abort('Missing output folder.')
ac_coverage_report_enabled = get_env_variable("AC_ENABLE_JACOCO_COVERAGE_REPORTS") || "false"
def capitalize_first_char(str)
str[0] = str[0].capitalize
return str
end
$exit_status_code = 0
def run_command(command, skip_abort)
puts "@@[command] #{command}"
status = nil
stdout_str = nil
stderr_str = nil
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stdout.each_line do |line|
puts line
end
stdout_str = stdout.read
stderr_str = stderr.read
status = wait_thr.value
end
unless status.success?
puts stderr_str
unless skip_abort
exit -1
end
$exit_status_code = -1
end
end
gradlew_folder_path = ""
if Pathname.new("#{ac_project_path}").absolute?
gradlew_folder_path = ac_project_path
else
gradlew_folder_path = File.expand_path(File.join(ac_repo_path, ac_project_path))
end
gradle_task = ""
ac_variants.split('|').each {
| variant | gradle_task << " :#{ac_module}:test#{capitalize_first_char(variant)}UnitTest"
}
File.open(ENV['AC_ENV_FILE_PATH'], 'a') { |f|
f.puts "AC_TEST_RESULT_PATH=#{ac_output_folder}/test-results"
}
run_command("cd #{gradlew_folder_path} && chmod +x ./gradlew && ./gradlew#{gradle_task}", true)
build_folder_path = "#{gradlew_folder_path}/#{ac_module}/build"
puts "Copying test results to the output directory"
puts "#{build_folder_path}/test-results => $AC_OUTPUT_DIR/test-results"
run_command("cp -R #{build_folder_path}/test-results #{ac_output_folder}/test-results", false)
puts "Copying reports to the output directory"
puts "#{build_folder_path}/reports/tests => $AC_OUTPUT_DIR/tests"
run_command("cp -R #{build_folder_path}/reports/tests #{ac_output_folder}/tests", false)
exit $exit_status_code