Created
June 3, 2016 19:16
-
-
Save vinnybad/efe32d7594ac7c1fe07bacffdb68b4ed to your computer and use it in GitHub Desktop.
Shows one way to fail a build in fastlane when code coverage does not meet a minimum threshold.
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
# | |
# Shows one way to fail a build in fastlane when code | |
# coverage does not meet a minimum threshold. | |
# | |
# there are other ways to check the coverage of the commit, | |
# but I couldn't find an existing tool that makes this easier | |
# that will run on bitrise. I would have normally used diff-cover | |
# to do this because you can compare branches and only check the diffs. | |
# Unfortunately that means you have to find a way to install it on bitrise | |
# at the time of writing and that can be tricky. | |
# | |
# Still, this is a pretty good approach for most cases. | |
# | |
# somewhere towards the top | |
require 'open3' | |
# | |
# where app constants live | |
# minimum coverage % for the project as a whole | |
# | |
coverage_limit = 80 | |
# wherever you want, below that require | |
desc "Runs the CI job" | |
lane :ci do | |
cocoapods # will run a pod install automatically | |
unit # assumes you have a lane called unit that runs unit tests for you. I used fastlane's scan tool to do this. | |
stdout, stderr, status = Open3.capture3('slather coverage --ignore="Pods/*" --ignore="../*" --workspace ../MyWorkspace.xcworkspace --scheme MyScheme ../MyProject.xcodeproj') | |
matches = /Test Coverage: (\d+(\.\d+)?)/.match(stdout) | |
full_coverage = (matches && matches.captures.length > 0) ? matches.captures[0] : nil | |
if full_coverage != nil && full_coverage.length > 0 && full_coverage.to_i < coverage_limit | |
puts stderr | |
puts red("ERROR: You are under the code coverage limit (is: #{full_coverage}%, should be at least: #{coverage_limit}%). Please raise code coverage and try again.") | |
abort() | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot!!!