Class: Fastlane::Actions::KuhverijAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



78
79
80
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 78

def self.authors
  ["mbogh"]
end

.available_optionsObject



91
92
93
94
95
96
97
98
99
100
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 91

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :derived_data_path,
                            env_name: "KUHVERIJ_DERIVED_DATA_PATH",
                         description: "Path to derived data",
                       default_value: Actions.lane_context[Actions::SharedValues::SCAN_DERIVED_DATA_PATH],
                            optional: false,
                                type: String)
  ]
end

.categoryObject



106
107
108
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 106

def self.category
  :testing
end

.code_coverage_message(json_string) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 39

def self.code_coverage_message(json_string)
  code_coverage = JSON.parse(strip_debug(json_string))
  covered_lines = 0
  executable_lines = 0

  code_coverage.each do |target|
    next if should_skip_target(target["name"])

    covered_lines += target["coveredLines"].to_f
    executable_lines += target["executableLines"].to_f
  end

  percentage = covered_lines / (executable_lines.nonzero? || 1) * 100
  message = format("Code Coverage: %.2f%%", percentage)

  message
end

.descriptionObject



74
75
76
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 74

def self.description
  "Simplified Code Coverage"
end

.detailsObject



86
87
88
89
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 86

def self.details
  # Optional:
  "Simplified Code Coverage, which e.g. can be used together with GitLab"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 102

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

.return_valueObject



82
83
84
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 82

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 9

def self.run(params)
  derived_data_path = params[:derived_data_path]

  commands = []

  coverage_report_path = Dir["#{derived_data_path}/**/*.xccovreport"].first
  result_bundle_path = Dir["#{derived_data_path}/**/*.xcresult"].first

  if !coverage_report_path.nil?
    command = "xcrun xccov view --only-targets --json"
    command << " #{coverage_report_path.shellescape}"
  elsif !result_bundle_path.nil?
    UI.important("No '.xccovreport' could be found at #{derived_data_path} will look for '.xcresult'")

    command = "xcrun xccov view --report --only-targets --json"
    command << " #{result_bundle_path.shellescape}"
  else
    UI.user_error!("No '.xccovreport' or '.xcresult' could be found at #{derived_data_path}")
  end

  commands << command

  code_coverage_json = Fastlane::Actions.sh(command, log: false)

  code_coverage = code_coverage_message(code_coverage_json)
  UI.message(code_coverage)

  commands
end

.should_skip_target(name) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 66

def self.should_skip_target(name)
  return true if name.nil?

  extension = name.split(".").last

  @excluded_target_extensions.include?(extension)
end

.strip_debug(json_string) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb', line 57

def self.strip_debug(json_string)
  result = ""
  json_string.each_line do |line|
    result << line unless line.include?('xccov[')
  end

  result
end