Skip to content

Commit f2e3254

Browse files
committed
Migrate from Codacy to SonarCloud, fix CI build warnings
1 parent 216fbf7 commit f2e3254

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ jobs:
2626
exit $?
2727
- name: Build and test
2828
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -scheme 'CryptomatorCryptoLib' -destination "name=$DEVICE" -derivedDataPath $DERIVED_DATA_PATH -enableCodeCoverage YES clean test | xcbeautify
29-
- name: Upload code coverage report
29+
- name: Generate coverage report
3030
run: |
31-
gem install slather
32-
slather coverage -x --build-directory $DERIVED_DATA_PATH --ignore "$DERIVED_DATA_PATH/SourcePackages/*" --scheme CryptomatorCryptoLib CryptomatorCryptoLib.xcodeproj
33-
bash <(curl -Ls https://coverage.codacy.com/get.sh)
31+
xcresult_path=$(find $DERIVED_DATA_PATH/Logs/Test -name "*.xcresult" | head -n 1)
32+
bash Scripts/xccov-to-sonarqube-generic.sh "$xcresult_path" > sonarqube-generic-coverage.xml
33+
- name: SonarCloud Scan
34+
uses: SonarSource/[email protected]
3435
env:
35-
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3637
continue-on-error: true
3738

3839
release:

.swiftformat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
--minversion 0.49.2
1+
--minversion 0.58.3
2+
--exclude DerivedData
23

34
# format options
45

CryptomatorCryptoLib.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -391,6 +391,7 @@
391391
/* Begin PBXShellScriptBuildPhase section */
392392
74862A712469A6B2003D81CB /* Lint With SwiftFormat */ = {
393393
isa = PBXShellScriptBuildPhase;
394+
alwaysOutOfDate = 1;
394395
buildActionMask = 2147483647;
395396
files = (
396397
);
@@ -409,6 +410,7 @@
409410
};
410411
749441272616051400435B0B /* Lint With SwiftLint */ = {
411412
isa = PBXShellScriptBuildPhase;
413+
alwaysOutOfDate = 1;
412414
buildActionMask = 2147483647;
413415
files = (
414416
);

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Swift Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcryptomator%2Fcryptolib-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/cryptomator/cryptolib-swift)
22
[![Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcryptomator%2Fcryptolib-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/cryptomator/cryptolib-swift)
3-
[![Codacy Code Quality](https://app.codacy.com/project/badge/Grade/dba85991a19942bab0d3d587522397ef)](https://www.codacy.com/gh/cryptomator/cryptolib-swift/dashboard)
4-
[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/dba85991a19942bab0d3d587522397ef)](https://www.codacy.com/gh/cryptomator/cryptolib-swift/dashboard)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_cryptolib-swift&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cryptomator_cryptolib-swift)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_cryptolib-swift&metric=coverage)](https://sonarcloud.io/summary/new_code?id=cryptomator_cryptolib-swift)
55

66
# CryptoLib Swift
77

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Source: https://github.com/SonarSource/sonar-scanning-examples/blob/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh
3+
set -euo pipefail
4+
5+
function convert_xccov_to_xml {
6+
sed -n \
7+
-e '/:$/s/&/\&amp;/g;s/^\(.*\):$/ <file path="\1">/p' \
8+
-e 's/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p' \
9+
-e 's/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p' \
10+
-e 's/^$/ <\/file>/p'
11+
}
12+
13+
function xccov_to_generic {
14+
local xcresult="$1"
15+
16+
echo '<coverage version="1">'
17+
xcrun xccov view --archive "$xcresult" | convert_xccov_to_xml
18+
echo '</coverage>'
19+
}
20+
21+
function check_xcode_version() {
22+
local major=${1:-0} minor=${2:-0}
23+
return $(( (major >= 14) || (major == 13 && minor >= 3) ))
24+
}
25+
26+
if ! xcode_version="$(xcodebuild -version | sed -n '1s/^Xcode \([0-9.]*\)$/\1/p')"; then
27+
echo 'Failed to get Xcode version' 1>&2
28+
exit 1
29+
elif check_xcode_version ${xcode_version//./ }; then
30+
echo "Xcode version '$xcode_version' not supported, version 13.3 or above is required" 1>&2;
31+
exit 1
32+
fi
33+
34+
xcresult="$1"
35+
if [[ $# -ne 1 ]]; then
36+
echo "Invalid number of arguments. Expecting 1 path matching '*.xcresult'"
37+
exit 1
38+
elif [[ ! -d $xcresult ]]; then
39+
echo "Path not found: $xcresult" 1>&2;
40+
exit 1
41+
elif [[ $xcresult != *".xcresult"* ]]; then
42+
echo "Expecting input to match '*.xcresult', got: $xcresult" 1>&2;
43+
exit 1
44+
fi
45+
46+
xccov_to_generic "$xcresult"

sonar-project.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Organization and project keys are defined in SonarCloud UI
2+
sonar.organization=cryptomator
3+
sonar.projectKey=cryptomator_cryptolib-swift
4+
5+
# Source and test directories
6+
sonar.sources=Sources
7+
sonar.tests=Tests
8+
9+
# Exclude external dependencies
10+
sonar.exclusions=DerivedData/**,**/.build/**
11+
12+
# Swift-specific settings
13+
sonar.swift.file.suffixes=.swift
14+
15+
# Coverage report path (generated by xccov)
16+
sonar.coverageReportPaths=sonarqube-generic-coverage.xml

0 commit comments

Comments
 (0)