class Fastlane::Actions::KuhverijAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb, line 78
def self.authors
  ["mbogh"]
end
available_options() click to toggle source
# 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
category() click to toggle source
# File lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb, line 106
def self.category
  :testing
end
code_coverage_message(json_string) click to toggle source
# 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
description() click to toggle source
# File lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb, line 74
def self.description
  "Simplified Code Coverage"
end
details() click to toggle source
# 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) click to toggle source
# File lib/fastlane/plugin/kuhverij/actions/kuhverij_action.rb, line 102
def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end
return_value() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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