-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from a7ex/feature/48-support-multiple-configur…
…ations-in-test-planxcresult 48 - Add 'configuration' property to test export
- Loading branch information
Showing
10 changed files
with
283 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Tests/XcresultparserTests/TestAssets/sonarTestExecutionWithProjectRootAbsolute.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Tests/XcresultparserTests/TestAssets/sonarTestExecutionWithProjectRootRelative.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/bin/sh | ||
|
||
usage() | ||
{ | ||
echo "" | ||
echo "NAME: $0" | ||
echo "" | ||
echo "SYNOPSIS:" | ||
echo "$0 [-t <teamId>] [-n <productName>] [-p profileName]" | ||
echo "" | ||
echo "DESCRIPTION:" | ||
echo " -- Script to create a SonarQube run and publish results" | ||
echo "" | ||
echo " The options are as follows:" | ||
echo " -s | --sonarqube-host Host of the sonarqube instance." | ||
echo " -p | --sonarqube-login-token The credentials to access the sonarqube instance." | ||
echo " -k | --sonarqube-project-key The key which identifies the project in sonar." | ||
echo " -n | --sonarqube-project-name The key of the project in sonar." | ||
echo " -v | --app-version The version of the project." | ||
echo " -r | --path-to-xcresult The xcresult bundle with data about tests and coverage." | ||
echo " -h | --help This help." | ||
echo "" | ||
} | ||
|
||
sourcesPath=Sources | ||
testsPath=Tests | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-s | --sonarqube-host ) shift | ||
sonarqube_host_url="$1" | ||
;; | ||
-p | --sonarqube-login-token ) shift | ||
sonarqube_login_token="$1" | ||
;; | ||
-k | --sonarqube-project-key ) shift | ||
sonarqube_project_key="$1" | ||
;; | ||
-n | --sonarqube-project-name ) shift | ||
sonarqube_project_name="$1" | ||
;; | ||
-o | --sonarqube-organization ) shift | ||
sonarqube_organization="$1" | ||
;; | ||
-v | --app-version ) shift | ||
app_project_version="$1" | ||
;; | ||
-r | --path-to-xcresult ) shift | ||
xcresultPath="$1" | ||
;; | ||
-h | --help ) usage | ||
exit | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
root_path=`git rev-parse --show-toplevel` | ||
if [ ! -z "$root_path" ] | ||
then | ||
cd "$root_path" | ||
else | ||
root_path="$(pwd)" | ||
fi | ||
|
||
|
||
sonarPath=$(which sonar-scanner) | ||
if [ ! -x "$sonarPath" ] | ||
then | ||
sonarPath="/opt/homebrew/bin/sonar-scanner" | ||
if [ ! -x "$sonarPath" ] | ||
then | ||
brewPath=$(which brew) | ||
if [ ! -x "$brewPath" ] | ||
then | ||
brewPath="/usr/local/bin/brew" | ||
if [ ! -x "$brewPath" ] | ||
then | ||
echo -e "Need brew to install the 'sonar-scanner' binary" | ||
exit 1 | ||
fi | ||
fi | ||
echo "Installing 'sonar-scanner' binary" | ||
"$brewPath" update && "$brewPath" install sonar-scanner | ||
sonarPath=$(which sonar-scanner) | ||
fi | ||
fi | ||
|
||
if [ ! -x "$sonarPath" ] | ||
then | ||
echo -e "The 'sonar-scanner' binary is not executble at: $sonarPath" | ||
exit 1 | ||
fi | ||
|
||
# We can either provide 'xcresultparser' as tool in the project's repository, | ||
resultparserPath=xcresultparser | ||
if [ ! -x "$resultparserPath" ] | ||
then | ||
# ...or we have installed it for all jobs on the agent: | ||
resultparserPath=$(which xcresultparser) | ||
if [ ! -x "$resultparserPath" ] | ||
then | ||
resultparserPath="/opt/homebrew/bin/xcresultparser" | ||
fi | ||
fi | ||
|
||
echo "-------------------\nStarting sonar scan for app_project_version (Build): $app_project_version\n-------------------" | ||
|
||
if [ ! -z "$xcresultPath" -a -d "$xcresultPath" -a -x "$resultparserPath" ] | ||
then | ||
echo "Convert xcresult to sonarqube compatible coverage xml. Path to xcresult file: $xcresultPath" | ||
"$resultparserPath" -cq -o xml "$xcresultPath" > sonarqube-coverage.xml | ||
|
||
echo "Convert xcresult to sonarqube compatible Junit xml." | ||
"$resultparserPath" -q -o xml -p "$root_path" "$xcresultPath" > sonarqube-testresults.xml | ||
fi | ||
|
||
if [ -s sonarqube-coverage.xml ] | ||
then | ||
echo "Run sonar scanner with coverage now for (sonarqube_project_name) ${sonarqube_project_name} with $sonarPath" | ||
# "$sonarPath" -X // with DEBUG messages | ||
"$sonarPath" \ | ||
-Dsonar.host.url="${sonarqube_host_url}" \ | ||
-Dsonar.token="${sonarqube_login_token}" \ | ||
-Dsonar.projectKey="${sonarqube_project_key}" \ | ||
-Dsonar.projectName="${sonarqube_project_name}" \ | ||
-Dsonar.projectVersion="${app_project_version}" \ | ||
-Dsonar.organization="${sonarqube_organization}" \ | ||
-Dsonar.sources="$(pwd)/${sourcesPath}" \ | ||
-Dsonar.exclusions=**/*.html \ | ||
-Dsonar.coverageReportPaths="sonarqube-coverage.xml" \ | ||
-Dsonar.testExecutionReportPaths="sonarqube-testresults.xml" \ | ||
-Dsonar.tests="${testsPath}" \ | ||
-Dsonar.c.file.suffixes=- \ | ||
-Dsonar.cpp.file.suffixes=- \ | ||
-Dsonar.objc.file.suffixes=- | ||
else | ||
echo "Run sonar scanner without coverage for (sonarqube_project_name) ${sonarqube_project_name} with $sonarPath" | ||
"$sonarPath" \ | ||
-Dsonar.host.url="${sonarqube_host_url}" \ | ||
-Dsonar.token="${sonarqube_login_token}" \ | ||
-Dsonar.projectKey="${sonarqube_project_key}" \ | ||
-Dsonar.projectName="${sonarqube_project_name}" \ | ||
-Dsonar.projectVersion="${app_project_version}" \ | ||
-Dsonar.organization="${sonarqube_organization}" \ | ||
-Dsonar.sources="$sourcesPath" \ | ||
-Dsonar.exclusions=**/*.html | ||
fi | ||
if [ $? -ne 0 ] | ||
then | ||
echo "-------------------\nSonar scan completed with error!\n-------------------" | ||
exit 1 | ||
else | ||
echo "-------------------\nSonar scan completed!\n-------------------" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/sh | ||
|
||
usage() | ||
{ | ||
echo "" | ||
echo "NAME: $0" | ||
echo "" | ||
echo "SYNOPSIS:" | ||
echo "$0 [-t <access token>]" | ||
echo "" | ||
echo "DESCRIPTION:" | ||
echo " -- Run the tests and send the results to sonar." | ||
echo " Here we define the project specific variables, which are required for the runSonar.sh script." | ||
echo " Note that one single value, which is required is not hard coded into this file for obvious reasons:" | ||
echo " The sonar API key needs to be sent to this script as parameter." | ||
echo "" | ||
echo " The options are as follows:" | ||
echo " -t | --sonarqube-login-token Access token to connect to the sonar server." | ||
echo " -h | --help This help" | ||
echo "" | ||
} | ||
|
||
## Default values for this app, so I can invoke this script with only one parameter for the token, which shall not be stored in the public repository. | ||
sonarqube_host_url="https://sonarcloud.io" | ||
sonarqube_project_key="a7ex_xcresultparser" | ||
sonarqube_project_name="xcresultparser" | ||
sonarqube_organization="a7ex" | ||
skip_build=false | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-t | --sonarqube-login-token ) shift | ||
sonarqube_login_token="$1" | ||
;; | ||
-s | --skip-build ) skip_build=true | ||
;; | ||
-h | --help ) usage | ||
exit | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ -z "$sonarqube_login_token" ] | ||
then | ||
echo "Error: Please provide the api key (access token) for the sonar account!" | ||
exit 1 | ||
fi | ||
|
||
# build the project for M1 and Intel: | ||
|
||
path_to_xcresults="$(pwd)/product/xcresultparser.xcresult" | ||
if [ -d "$path_to_xcresults" ]; then | ||
if [ "$skip_build" != true ]; then | ||
rm -r "$path_to_xcresults" | ||
fi | ||
fi | ||
|
||
if [ ! -d "$path_to_xcresults" ]; then | ||
/usr/bin/xcrun xcodebuild clean test -workspace .swiftpm/xcode/package.xcworkspace -scheme xcresultparser -destination "platform=macOS" -resultBundlePath "$path_to_xcresults" | ||
fi | ||
|
||
app_project_version=$(grep 'marketingVersion =' CommandlineTool/main.swift | cut -d "=" -f2 | xargs) | ||
|
||
if [ -d "$path_to_xcresults" ] | ||
then | ||
sh runSonar.sh \ | ||
-s $sonarqube_host_url \ | ||
-p $sonarqube_login_token \ | ||
-k $sonarqube_project_key \ | ||
-n "$sonarqube_project_name" \ | ||
-o "$sonarqube_organization" \ | ||
-v "$app_project_version" \ | ||
-r "$path_to_xcresults" | ||
fi |