Skip to content

Commit 819ca36

Browse files
committed
Migrate from Codacy to SonarCloud, fix CI build warnings
1 parent f00f633 commit 819ca36

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
DEVICE: 'iPhone 15 Pro'
1515
steps:
1616
- uses: actions/checkout@v4
17+
with:
18+
# Disable shallow clone for SonarCloud analysis
19+
# https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/ci-based-analysis/github-actions-for-sonarcloud
20+
fetch-depth: 0
1721
- uses: actions/cache@v4
1822
with:
1923
path: .build
@@ -28,13 +32,14 @@ jobs:
2832
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild clean build-for-testing -scheme 'CryptomatorCloudAccess' -destination "name=$DEVICE" -derivedDataPath $DERIVED_DATA_PATH -enableCodeCoverage YES | xcbeautify
2933
- name: Test
3034
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild test-without-building -xctestrun $(find . -type f -name "*.xctestrun") -destination "name=$DEVICE" -derivedDataPath $DERIVED_DATA_PATH | xcbeautify
31-
- name: Upload code coverage report
35+
- name: Generate coverage report
3236
run: |
33-
gem install slather
34-
slather coverage -x --build-directory $DERIVED_DATA_PATH --ignore "$DERIVED_DATA_PATH/SourcePackages/*" --scheme CryptomatorCloudAccess CryptomatorCloudAccess.xcodeproj
35-
bash <(curl -Ls https://coverage.codacy.com/get.sh)
37+
xcresult_path=$(find $DERIVED_DATA_PATH/Logs/Test -name "*.xcresult" | head -n 1)
38+
bash Scripts/xccov-to-sonarqube-generic.sh "$xcresult_path" > sonarqube-generic-coverage.xml
39+
- name: SonarCloud Scan
40+
uses: SonarSource/sonarqube-scan-action@v6.0.0
3641
env:
37-
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
42+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3843
continue-on-error: true
3944

4045
integration-tests:

.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

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%2Fcloud-access-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/cryptomator/cloud-access-swift)
22
[![Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcryptomator%2Fcloud-access-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/cryptomator/cloud-access-swift)
3-
[![Codacy Code Quality](https://app.codacy.com/project/badge/Grade/35951085e6604f9aaab998fc65dd2467)](https://www.codacy.com/gh/cryptomator/cloud-access-swift/dashboard)
4-
[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/35951085e6604f9aaab998fc65dd2467)](https://www.codacy.com/gh/cryptomator/cloud-access-swift/dashboard)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_cloud-access-swift&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cryptomator_cloud-access-swift)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_cloud-access-swift&metric=coverage)](https://sonarcloud.io/summary/new_code?id=cryptomator_cloud-access-swift)
55

66
# Cloud Access 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Organization and project keys are defined in SonarCloud UI
2+
sonar.organization=cryptomator
3+
sonar.projectKey=cryptomator_cloud-access-swift
4+
5+
# Source and test directories
6+
sonar.sources=Sources
7+
sonar.tests=Tests
8+
9+
# Disable C/C++/Objective-C analysis
10+
sonar.c.file.suffixes=-
11+
sonar.cpp.file.suffixes=-
12+
sonar.objc.file.suffixes=-
13+
14+
# Coverage report path (generated by xccov)
15+
sonar.coverageReportPaths=sonarqube-generic-coverage.xml

0 commit comments

Comments
 (0)