Class: Fastlane::Actions::MergeJunitReportAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb

Constant Summary collapse

UI =
FastlaneCore::UI

Class Method Summary collapse

Class Method Details

.authorsObject



28
29
30
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 28

def self.authors
  ['Derek Yang']
end

.available_optionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 32

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :input_files,
                                 env_name: 'MERGE_JUNIT_REPORT_INPUT_FILES',
                                 description: 'A list of junit report files to merge from',
                                 optional: false,
                                 type: Array,
                                 verify_block: proc do |input_files|
                                                 UI.user_error!('No input files!') if input_files.empty?
                                                 input_files.each do |input_file|
                                                   UI.user_error!("File not found: #{input_file}") unless File.file?(input_file)
                                                 end
                                               end),
    FastlaneCore::ConfigItem.new(key: :output_file,
                                 env_name: 'MERGE_JUNIT_REPORT_OUTPUT_FILE',
                                 description: 'The output file where all input files will be merged into',
                                 optional: true,
                                 default_value: 'result.xml',
                                 type: String)
  ]
end

.descriptionObject



24
25
26
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 24

def self.description
  'Provides the ability to merge multiple junit reports into one'
end

.example_codeObject



54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 54

def self.example_code
  [
    'merge_junit_report(
      input_files: ["report1.xml", "report2.xml"],
      output_file: "output/merged_report.xml"
    )'
  ]
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 63

def self.is_supported?(_platform)
  true
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/plugin/merge_junit_report/actions/merge_junit_report_action.rb', line 6

def self.run(params)
  FastlaneCore::PrintTable.print_values(
    config: params,
    title: 'Summary for merge_junit_report Action'
  )
  input_files = params[:input_files]

  xml_docs = input_files.map { |file| REXML::Document.new(File.new(file)) }
  merger = Fastlane::Plugin::MergeJunitReport::Merger.new(xml_docs)
  merged = merger.merge

  # write to output_file
  output_file = File.absolute_path(params[:output_file])
  FileUtils.mkdir_p(File.dirname(output_file))
  File.open(output_file, 'w') { |f| merged.write(f, 2) }
  UI.success("Reports merged to #{output_file} successfully")
end