Class: Fastlane::Actions::CollateXcresultsAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



108
109
110
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 108

def self.authors
  ["lyndsey-ferguson/@lyndseydf"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 62

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :xcresults,
      env_name: 'COLLATE_XCRESULTS',
      description: 'An array of xcresult bundles to collate',
      optional: false,
      type: Array,
      verify_block: proc do |xcresult_bundles|
        UI.user_error!('No xcresult bundles found') if xcresult_bundles.empty?
        xcresult_bundles.each do |xcresult_bundle|
          UI.user_error!("Error: xcresult bundle not found: '#{xcresult_bundle}'") unless Dir.exist?(xcresult_bundle)
        end
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :collated_xcresult,
      env_name: 'COLLATE_XCRESULTS',
      description: 'The merged xcresult bundle',
      optional: true,
      default_value: 'result.xcresult',
      type: String
    )
  ]
end

.descriptionObject



48
49
50
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 48

def self.description
  "🔸 Combines multiple xcresult bundles into one xcresult bundle"
end

.detailsObject



52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 52

def self.details
  "The first xcresult bundle is used as the base bundle. " \
  "Testcases that failed in previous bundles that no longer appear in " \
  "later bundles are assumed to have passed in a re-run, thus not appearing " \
  "in the collated xcresult bundle. " \
  "This is done because it is assumed that fragile tests, when " \
  "re-run will often succeed due to less interference from other " \
  "tests and the subsequent xcresult bundles will have fewer failing tests."
end

.example_codeObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 88

def self.example_code
  [
    "
    require 'tmpdir'

    UI.important(
      'example: ' \\
      'collate the xcresult bundles to a temporary xcresult bundle \"result.xcresult\"'
    )
    xcresults = Dir['../spec/fixtures/AtomicBoyUITests-batch-{3,4}/result.xcresult'].map { |relpath| File.absolute_path(relpath) }
    Dir.mktmpdir('test_output') do |dir|
      collate_xcresults(
        xcresults: xcresults,
        collated_xcresult: File.join(dir, 'result.xcresult')
      )
    end
    "
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 112

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/test_center/actions/collate_xcresults.rb', line 6

def self.run(params)
  unless FastlaneCore::Helper.xcode_at_least?(11)
    FastlaneCore::UI.error("Error: Xcode 11 is required to run this action")
    return
  end
  commands_run = ''
  
  xcresult_bundlepaths = params[:xcresults]
  base_xcresult_path = xcresult_bundlepaths[0]
  
  tmp_collated_xcresult_bundle = Tempfile.new(['collated_result_', '.xcresult'])
  tmp_collated_xcresult_bundlepath = tmp_collated_xcresult_bundle.path
  tmp_collated_xcresult_bundle.unlink

  if xcresult_bundlepaths.size > 1
    command = [
      'xcrun',
      'xcresulttool',
      'merge',
      xcresult_bundlepaths,
      '--output-path',
      tmp_collated_xcresult_bundlepath
    ].flatten
    commands_run = sh(*command)

    FileUtils.rm_rf(params[:collated_xcresult])
    FileUtils.cp_r(tmp_collated_xcresult_bundlepath, params[:collated_xcresult])
  elsif File.realdirpath(xcresult_bundlepaths.first) != File.realdirpath(params[:collated_xcresult])
    FileUtils.rm_rf(params[:collated_xcresult])
    FileUtils.cp_r(base_xcresult_path, params[:collated_xcresult])
  end

  UI.message("Finished collating xcresults to '#{params[:collated_xcresult]}'")
  UI.verbose("  final xcresults: #{other_action.tests_from_xcresult(xcresult: params[:collated_xcresult])}")

  commands_run
end