Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
#116. Add SonarCloud integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Jan 17, 2020
1 parent 98c0fc6 commit fa75e02
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
- dotnet pack .\src\MMALSharp.FFmpeg\MMALSharp.FFmpeg.csproj -c %CONFIGURATION% --version-suffix %APPVEYOR_BUILD_NUMBER%
- dotnet pack .\src\MMALSharp.Processing\MMALSharp.Processing.csproj -c %CONFIGURATION% --version-suffix %APPVEYOR_BUILD_NUMBER%

test_script:
- ps: .\run-sonar.ps1

deploy:
# MyGet Deployment for builds & releases
- provider: NuGet
Expand Down Expand Up @@ -86,6 +89,9 @@
- dotnet pack .\src\MMALSharp.FFmpeg\MMALSharp.FFmpeg.csproj -c %CONFIGURATION%
- dotnet pack .\src\MMALSharp.Processing\MMALSharp.Processing.csproj -c %CONFIGURATION%

test_script:
- ps: .\run-sonar.ps1

deploy:
# NuGet deployment
- provider: NuGet
Expand Down
62 changes: 62 additions & 0 deletions run-sonar.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Adapted from: https://github.com/NLog/NLog.Extensions.Logging/blob/master/run-sonar.ps1

$projectFile = "src\MMALSharp\MMALSharp.csproj"
$sonarQubeId = "MMALSharp"
$github = "techyian/MMALSharp"
$baseBranch = "master"
$framework = "netstandard2.0"


if ($env:APPVEYOR_REPO_NAME -eq $github) {

if (-not $env:SONAR_TOKEN) {
Write-warning "Sonar: not running SonarQube, no SONAR_KEY"
return;
}

$prMode = $false;
$branchMode = $false;

if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
# first check PR as that is on the base branch
$prMode = $true;
Write-Output "Sonar: on PR $env:APPVEYOR_PULL_REQUEST_NUMBER"
}
elseif ($env:APPVEYOR_REPO_BRANCH -eq $baseBranch) {
Write-Output "Sonar: on base branch ($baseBranch)"
}
else {
$branchMode = $true;
Write-Output "Sonar: on branch $env:APPVEYOR_REPO_BRANCH"
}

choco install "msbuild-sonarqube-runner" -y

$sonarUrl = "https://sonarcloud.io"
$sonarKey = $env:SONAR_KEY
$sonarToken = $env:SONAR_TOKEN
$buildVersion = $env:APPVEYOR_BUILD_VERSION


if ($prMode) {
$pr = $env:APPVEYOR_PULL_REQUEST_NUMBER
Write-Output "Sonar: Running Sonar for PR $pr"
SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.analysis.mode=preview" /d:"sonar.github.pullRequest=$pr" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:GITHUB_AUTH"
}
elseif ($branchMode) {
$branch = $env:APPVEYOR_REPO_BRANCH;
Write-Output "Sonar: Running Sonar in branch mode for branch $branch"
SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.branch.name=$branch"
}
else {
Write-Output "Sonar: Running Sonar in non-preview mode, on branch $env:APPVEYOR_REPO_BRANCH"
SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion"
}

msbuild /t:Rebuild $projectFile /p:targetFrameworks=$framework /verbosity:minimal

SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonar_token"
}
else {
Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'"
}

0 comments on commit fa75e02

Please sign in to comment.