Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,44 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened]

jobs:
build:

name: Build
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Build
run: swift build -v
- name: Run tests
- name: Test
run: |
xcrun xcodebuild -list; \
xcrun xcodebuild -scheme DataStructures-Package test; \
echo done;
xcodebuild -list
xcodebuild -scheme DataStructures test -resultBundlePath "${GITHUB_WORKSPACE}/testResults.xcresult" -enableCodeCoverage YES -quiet
./xccov-to-sonarqube-generic.sh testResults.xcresult > generic-coverage.xml
echo done
- name: Upload code coverage results
uses: actions/upload-artifact@v2
with:
name: generic-code-coverage-report
path: generic-coverage.xml

sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Download code coverage report
uses: actions/download-artifact@v2
with:
name: generic-code-coverage-report
- name: Check xml exists
run: head generic-coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

# Jazzy generated folders
/docs/
/build/
/build/

# SonarQube
.scannerwork/
21 changes: 21 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sonar.projectKey=nacho4d_DataStructures
sonar.organization=nacho4d
# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=DataStructures
#sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=Sources/
#sonar.exclusions=
#sonar.inclusions=
sonar.tests=Tests/
#sonar.test.exclusions=
#sonar.test.inclusions=

# Source encoding
sonar.sourceEncoding=UTF-8

# Exclusions for copy-paste detection
#sonar.cpd.exclusions=
sonar.coverageReportPaths=generic-coverage.xml
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.1
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
9 changes: 9 additions & 0 deletions sonar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash
GIT_BRANCH=$(git branch | grep '\*' | awk '{print $2}')
echo GIT_BRANCH $GIT_BRANCH
sonar-scanner \
-X \
-Dsonar.projectKey=DataStructuresKey \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=ee4b2751f7ecbf413cd2e67ab8372419fadb2a79
41 changes: 41 additions & 0 deletions xccov-to-sonarqube-generic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# Swift Coverage Results Import
# https://docs.sonarqube.org/pages/viewpage.action?pageId=6963001
#
# Original source
# https://github.com/SonarSource/sonar-scanning-examples/blob/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh

set -euo pipefail

function convert_file {
local xccovarchive_file="$1"
local file_name="$2"
local xccov_options="$3"
echo " <file path=\"$file_name\">"
# Ignore errors (2> /dev/null) because sometimes xcode output pollutes input of the next command
xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" 2> /dev/null | \
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
local xccov_options=""
if [[ $xccovarchive_file == *".xcresult"* ]]; then
xccov_options="--archive"
fi
# Ignore errors (2> /dev/null) because sometimes xcode output pollutes input of the next command.
# Filter m files since they are not analized by sonar project yet.
xcrun xccov view $xccov_options --file-list "$xccovarchive_file" 2> /dev/null | grep -v '.m$' | while read -r file_name; do
convert_file "$xccovarchive_file" "$file_name" "$xccov_options"
done
done
echo '</coverage>'
}

xccov_to_generic "$@"