Skip to content

Commit c5afa2a

Browse files
author
Daniel
authoredNov 26, 2019
Update sonarqube lane to work with Xcode11 coverage report format (airsidemobile#193)
* Use xcresult files and update conversion script * Add newline
1 parent 66420d9 commit c5afa2a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
 

‎fastlane/Fastfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ lane :sonarqube do |options|
132132
sq_coverage_report = "#{TEST_OUTPUT}/sonarqube-coverage.xml"
133133
Dir.chdir("..") do
134134
sh "rm #{sq_coverage_report}"
135-
xccov_reports = Dir["#{DERIVED_DATA_PATH}/Logs/Test/**/*.xccovarchive"].join(" ")
136-
sh "scripts/xccov-to-sonarqube.sh #{xccov_reports} > #{sq_coverage_report}"
135+
cov_reports = Dir["#{DERIVED_DATA_PATH}/Logs/Test/**/*.xcresult"].join(" ")
136+
sh "scripts/xccov-to-sonarqube.sh #{cov_reports} > #{sq_coverage_report}"
137137
end
138138

139139
# Run Sonarqube analysis

‎scripts/xccov-to-sonarqube.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# See
4+
# Adapted from
55
# https://docs.sonarqube.org/display/PLUG/Swift+Coverage+Results+Import
66
# https://github.com/SonarSource/sonar-scanning-examples/blob/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh
77

88
function convert_file {
9-
local xccovarchive_file="$1"
9+
local xcresult_bundle="$1"
1010
local file_name="$2"
1111
echo " <file path=\"$file_name\">"
12-
xcrun xccov view --file "$file_name" "$xccovarchive_file" | \
12+
xcrun xccov view --archive --file "$file_name" "$xcresult_bundle" | \
1313
sed -n '
1414
s/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p;
1515
s/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p
@@ -19,9 +19,9 @@ function convert_file {
1919

2020
function xccov_to_generic {
2121
echo '<coverage version="1">'
22-
for xccovarchive_file in "$@"; do
23-
xcrun xccov view --file-list "$xccovarchive_file" | while read -r file_name; do
24-
convert_file "$xccovarchive_file" "$file_name"
22+
for xcresult_bundle in "$@"; do
23+
xcrun xccov view --archive --file-list "$xcresult_bundle" | while read -r file_name; do
24+
convert_file "$xcresult_bundle" "$file_name"
2525
done
2626
done
2727
echo '</coverage>'

0 commit comments

Comments
 (0)
Please sign in to comment.