Last active
March 28, 2021 14:11
-
-
Save z-turk3/4e263fc285f6e171f92d6acc9d69455e to your computer and use it in GitHub Desktop.
Extension to the sonarqube script for converting xcode code coverage to generic report found at: https://github.com/SonarSource/sonar-scanning-examples/tree/master/swift-coverage
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
#!/usr/bin/env bash | |
set -euo pipefail | |
function convert_file { | |
local xccovarchive_file="$1" | |
local file_name="$2" | |
local xccov_options="$3" | |
echo " <file path=\"$file_name\">" | |
xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \ | |
sed -n ' | |
s/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p; | |
s/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p | |
' | |
echo ' </file>' | |
} | |
function xccov_to_generic { | |
echo '<coverage version="1">' | |
for xccovarchive_file in "$@"; do | |
local xccov_options="" | |
if [[ $xccovarchive_file == *".xcresult/" ]]; then | |
xccov_options="--archive" | |
fi | |
xcrun xccov view $xccov_options --file-list "$xccovarchive_file" | while read -r file_name; do | |
if [[ $file_name == *" "* ]]; then | |
continue | |
fi | |
if [[ $file_name == *"/Pods/"* ]]; then | |
continue | |
fi | |
if [[ $file_name == *".m" ]] || [[ $file_name == *".h" ]]; then | |
continue | |
fi | |
convert_file "$xccovarchive_file" "$file_name" "$xccov_options" | |
done | |
done | |
echo '</coverage>' | |
} | |
xccov_to_generic "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment