Created
June 7, 2016 10:28
-
-
Save teriiehina/3a93d74e7323428b47c8c5fab267b4e7 to your computer and use it in GitHub Desktop.
Hacky way to get code coverage from xcov in a Fastlane lane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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