Skip to content

Commit

Permalink
Add SonarCloud code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszielinski committed Nov 28, 2018
1 parent 84868c7 commit d2fedc8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
Empty file removed .scannerwork/.sonar_lock
Empty file.
7 changes: 0 additions & 7 deletions .scannerwork/report-task.txt

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addons:
organization: chriszielinski-github
script:
- make
- make test
- make travis-test
- swiftlint
- sonar-scanner
after_success:
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ carthage:
build:
xcodebuild $(XCODEFLAGS) -configuration Release | xcpretty

test:
xcodebuild test $(XCODEFLAGS) -configuration Debug | xcpretty
test: clean-test
xcodebuild test $(XCODEFLAGS) -configuration Debug -resultBundlePath testResults | xcpretty

travis-test: test
./xccov-to-sonarqube-generic.sh testResults/1_Test/action.xccovarchive/ > testResults/sonarqube-generic-coverage.xml

archive:
cd $(BUILT_PRODUCT_DIR); \
zip -FSr -1 $(FULL_PRODUCT_NAME).zip $(FULL_PRODUCT_NAME);
echo "Built distribution zip file: $(BUILT_PRODUCT_DIR)$(FULL_PRODUCT_NAME).zip"

clean-test:
rm -rf ./testResults
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ sonar.login= 63079da560acf5e7a12244bd3b0f5068c5c9beda

sonar.sources=Source
sonar.tests=Tests
sonar.coverageReportPaths=testResults/sonarqube-generic-coverage.xml

sonar.cfamily.build-wrapper-output.bypass=true
26 changes: 26 additions & 0 deletions xccov-to-sonarqube-generic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail

function convert_file {
local xccovarchive_file="$1"
local file_name="$2"
echo " <file path=\"$file_name\">"
xcrun xccov view --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
xcrun xccov view --file-list "$xccovarchive_file" | while read -r file_name; do
convert_file "$xccovarchive_file" "$file_name"
done
done
echo '</coverage>'
}

xccov_to_generic "$@"

0 comments on commit d2fedc8

Please sign in to comment.