Class: TestCenter::Helper::MultiScanManager::ReportCollator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb

Constant Summary collapse

CollateJunitReportsAction =
Fastlane::Actions::CollateJunitReportsAction
CollateHtmlReportsAction =
Fastlane::Actions::CollateHtmlReportsAction
CollateJsonReportsAction =
Fastlane::Actions::CollateJsonReportsAction
CollateTestResultBundlesAction =
Fastlane::Actions::CollateTestResultBundlesAction

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ReportCollator



10
11
12
13
14
15
16
17
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 10

def initialize(params)
  @source_reports_directory_glob = params[:source_reports_directory_glob]
  @output_directory = params[:output_directory]
  @reportnamer = params[:reportnamer]
  @scheme = params[:scheme]
  @result_bundle = params[:result_bundle]
  @suffix = params[:suffix] || ''
end

Instance Method Details

#collateObject



19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 19

def collate
  FastlaneCore::UI.verbose("ReportCollator collating")
  collate_junit_reports
  collate_html_reports
  collate_json_reports
  collate_test_result_bundles
end

#collate_html_reportsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 67

def collate_html_reports
  return unless @reportnamer.includes_html?

  report_files = sort_globbed_files("#{@source_reports_directory_glob}/#{@reportnamer.html_fileglob}")
  collated_file = File.absolute_path(File.join(@output_directory, @reportnamer.html_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating html report files #{report_files}")
    config = create_config(
      CollateJunitReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateHtmlReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying html report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_json_reportsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 90

def collate_json_reports
  return unless @reportnamer.includes_json?

  report_files = sort_globbed_files("#{@source_reports_directory_glob}/#{@reportnamer.json_fileglob}")
  collated_file = File.absolute_path(File.join(@output_directory, @reportnamer.json_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating json report files #{report_files}")
    config = create_config(
      CollateJsonReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateJsonReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying json report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_junit_reportsObject

:nocov:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 45

def collate_junit_reports
  glob = "#{@source_reports_directory_glob}/#{@reportnamer.junit_fileglob}"
  report_files = sort_globbed_files(glob)
  collated_file =  File.absolute_path(File.join(@output_directory, @reportnamer.junit_reportname(@suffix)))
  if report_files.size > 1
    FastlaneCore::UI.verbose("Collating junit report files #{report_files}")
    config = create_config(
      CollateJunitReportsAction,
      {
        reports: report_files,
        collated_report: collated_file
      }
    )
    CollateJunitReportsAction.run(config)
    FileUtils.rm_rf(report_files - [collated_file])
  elsif report_files.size == 1 && ! File.identical?(report_files.first, collated_file)
    FastlaneCore::UI.verbose("Copying junit report file #{report_files.first}")
    FileUtils.mkdir_p(File.dirname(collated_file))
    FileUtils.mv(report_files.first, collated_file)
  end
end

#collate_test_result_bundlesObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 113

def collate_test_result_bundles
  return unless @result_bundle

  test_result_bundlepaths = sort_globbed_files("#{@source_reports_directory_glob}/#{@scheme}*.test_result")
  collated_test_result_bundlepath = File.absolute_path("#{File.join(@output_directory, @scheme)}.test_result")
  if test_result_bundlepaths.size > 1
    FastlaneCore::UI.verbose("Collating test_result bundles #{test_result_bundlepaths}")
    config = create_config(
      CollateTestResultBundlesAction,
      {
        bundles: test_result_bundlepaths,
        collated_bundle: collated_test_result_bundlepath
      }
    )
    CollateTestResultBundlesAction.run(config)
    FileUtils.rm_rf(test_result_bundlepaths - [collated_test_result_bundlepath])
  elsif test_result_bundlepaths.size == 1 && File.realdirpath(test_result_bundlepaths.first) != File.realdirpath(collated_test_result_bundlepath)
    FastlaneCore::UI.verbose("Copying test_result bundle #{test_result_bundlepaths.first}")
    FileUtils.mkdir_p(File.dirname(collated_test_result_bundlepath))
    FileUtils.mv(test_result_bundlepaths.first, collated_test_result_bundlepath)
  end
end

#create_config(klass, options) ⇒ Object

:nocov:



40
41
42
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 40

def create_config(klass, options)
  FastlaneCore::Configuration.create(klass.available_options, options)
end

#delete_globbed_intermediatefiles(glob) ⇒ Object



34
35
36
37
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 34

def delete_globbed_intermediatefiles(glob)
  retried_reportfiles = Dir.glob(glob)
  FileUtils.rm_f(retried_reportfiles)
end

#sort_globbed_files(glob) ⇒ Object



27
28
29
30
31
32
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/report_collator.rb', line 27

def sort_globbed_files(glob)
  files = Dir.glob(glob).map do |relative_filepath|
    File.absolute_path(relative_filepath)
  end
  files.sort! { |f1, f2| File.mtime(f1) <=> File.mtime(f2) }
end