Skip to content

Instantly share code, notes, and snippets.

@teriiehina
Created June 7, 2016 10:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teriiehina/3a93d74e7323428b47c8c5fab267b4e7 to your computer and use it in GitHub Desktop.
Save teriiehina/3a93d74e7323428b47c8c5fab267b4e7 to your computer and use it in GitHub Desktop.
Hacky way to get code coverage from xcov in a Fastlane lane
module Fastlane
module Actions
module SharedValues
SUPER_XCOV_CODE_COVERAGE = :SUPER_XCOV_CODE_COVERAGE
end
class SuperXcovAction < Action
def self.run(options)
Actions.verify_gem!('xcov')
require 'xcov'
# Xcov::Manager.new.work(values)
Xcov.config = options
FastlaneCore::Project.detect_projects(options)
Xcov.project = FastlaneCore::Project.new(options)
Xcov.ignore_handler = Xcov::IgnoreHandler.new
FastlaneCore::PrintTable.print_values(config: options, hide_keys: [:slack_url], title: "Summary for xcov #{Xcov::VERSION}")
runner = Xcov::Runner.new
report_json = runner.parse_xccoverage
report = runner.generate_xcov_report(report_json)
coverage = "#{"%.2f%" % (report.coverage*100)}"
Actions.lane_context[SharedValues::SUPER_XCOV_CODE_COVERAGE] = coverage
runner.validate_report(report)
end
def self.description
"Nice code coverage reports without hassle"
end
def self.details
"More information: https://github.com/nakiostudio/xcov"
end
def self.author
"nakiostudio"
end
def self.available_options
# We call Gem::Specification.find_by_name in many more places than this, but for right now
# this is the only place we're having trouble. If there are other reports about RubyGems
# 2.6.2 causing problems, we may need to move this code and require it someplace better,
# like fastlane_core
require 'fastlane/core_ext/bundler_monkey_patch'
begin
Gem::Specification.find_by_name('xcov')
rescue Gem::LoadError
# Catched missing gem exception and returned empty array
# to avoid unused_options_spec failure
return []
end
require 'xcov'
Xcov::Options.available_options
end
def self.output
[
['SUPER_XCOV_CODE_COVERAGE', 'The code coverage computed by xcov'],
]
end
def self.is_supported?(platform)
[:ios, :mac].include? platform
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment