Skip to content

Commit edd7df7

Browse files
committed
Migrate from Codacy to SonarCloud, fix CI build warnings
1 parent d03eba2 commit edd7df7

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
config: ['freemium', 'premium']
1818
steps:
1919
- uses: actions/checkout@v4
20+
with:
21+
# Disable shallow clone for SonarCloud analysis
22+
# https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/ci-based-analysis/github-actions-for-sonarcloud
23+
fetch-depth: 0
2024
- uses: actions/cache@v4
2125
with:
2226
path: .build
@@ -43,12 +47,14 @@ jobs:
4347
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild clean build-for-testing -scheme 'AllTests' -destination "name=$DEVICE" -derivedDataPath $DERIVED_DATA_PATH ${{ env.BUILD_CMD }} | xcbeautify
4448
- name: Test
4549
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
46-
- name: Upload code coverage report
50+
- name: Generate coverage report
4751
if: ${{ matrix.config == 'freemium' }}
4852
run: |
49-
gem install slather
50-
slather coverage -x --build-directory $DERIVED_DATA_PATH --ignore "$DERIVED_DATA_PATH/SourcePackages/*" --scheme AllTests Cryptomator.xcodeproj
51-
bash <(curl -Ls https://coverage.codacy.com/get.sh)
53+
xcresult_path=$(find $DERIVED_DATA_PATH/Logs/Test -name "*.xcresult" | head -n 1)
54+
bash Scripts/xccov-to-sonarqube-generic.sh "$xcresult_path" > sonarqube-generic-coverage.xml
55+
- name: SonarCloud Scan
56+
if: ${{ matrix.config == 'freemium' }}
57+
uses: SonarSource/sonarqube-scan-action@v6.0.0
5258
env:
53-
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
59+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5460
continue-on-error: true

.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Cryptomator for iOS
22

33
[![Build](https://github.com/cryptomator/ios/actions/workflows/build.yml/badge.svg)](https://github.com/cryptomator/ios/actions/workflows/build.yml)
4-
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/efc080db52a5449fac50ffde8d8fd6bc)](https://www.codacy.com/gh/cryptomator/ios/dashboard)
4+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_ios&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cryptomator_ios)
5+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=cryptomator_ios&metric=coverage)](https://sonarcloud.io/summary/new_code?id=cryptomator_ios)
56
[![Mastodon](https://img.shields.io/mastodon/follow/176112?domain=mastodon.online&style=flat)](https://mastodon.online/@cryptomator)
67
[![Crowdin](https://badges.crowdin.net/cryptomator/localized.svg)](https://translate.cryptomator.org/)
78
[![Community](https://img.shields.io/badge/help-Community-orange.svg)](https://community.cryptomator.org)
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_ios
4+
5+
# Source and test directories
6+
sonar.sources=Cryptomator,CryptomatorCommon/Sources,CryptomatorFileProvider,FileProviderExtension,FileProviderExtensionUI,CryptomatorIntents,SharedResources
7+
sonar.tests=CryptomatorTests,CryptomatorCommon/Tests,CryptomatorFileProviderTests
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)