Skip to content

Commit 7a49b77

Browse files
Merge pull request #215 from NLog/sonar
Added Sonar
2 parents c9ceb0b + 0208a2c commit 7a49b77

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

appveyor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ version: 1.0.{build}
22
image: Visual Studio 2017
33
configuration: Release
44

5+
environment:
6+
github_auth_token:
7+
secure: WYvd/k1xGCsDS+4iOhjzxA5/e36RjkxnuVOHpBR+eDtZNNjpYydCyNfd1COME9jI
8+
sonar_token:
9+
secure: OUI/jCbBF75TwKMPT+IfewdgwCgx9nQkRg3cYOEQNJeX5J2++oWS3dmpwO51XduP
10+
511
install:
612
- '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"'
713

814
build_script:
915
- ps: .\build.ps1
16+
- ps: .\run-sonar.ps1
1017

1118
artifacts:
1219
- path: 'artifacts\*.nupkg'

run-sonar.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
$projectFile = "src\NLog.Extensions.Logging\NLog.Extensions.Logging.csproj"
2+
$sonarQubeId = "nlog.extensions.logging"
3+
$github = "nlog/NLog.Extensions.Logging"
4+
$baseBranch = "master"
5+
$framework = "netstandard2.0"
6+
$sonarOrg = "nlog"
7+
8+
9+
if ($env:APPVEYOR_REPO_NAME -eq $github) {
10+
11+
if (-not $env:sonar_token) {
12+
Write-warning "Sonar: not running SonarQube, no sonar_token"
13+
return;
14+
}
15+
16+
$prMode = $false;
17+
$branchMode = $false;
18+
19+
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
20+
# first check PR as that is on the base branch
21+
$prMode = $true;
22+
Write-Output "Sonar: on PR $env:APPVEYOR_PULL_REQUEST_NUMBER"
23+
}
24+
elseif ($env:APPVEYOR_REPO_BRANCH -eq $baseBranch) {
25+
Write-Output "Sonar: on base branch ($baseBranch)"
26+
}
27+
else {
28+
$branchMode = $true;
29+
Write-Output "Sonar: on branch $env:APPVEYOR_REPO_BRANCH"
30+
}
31+
32+
choco install "msbuild-sonarqube-runner" -y
33+
34+
$sonarUrl = "https://sonarcloud.io"
35+
$sonarToken = $env:sonar_token
36+
$buildVersion = $env:APPVEYOR_BUILD_VERSION
37+
38+
if ($prMode) {
39+
$pr = $env:APPVEYOR_PULL_REQUEST_NUMBER
40+
Write-Output "Sonar: Running Sonar for PR $pr"
41+
SonarScanner.MSBuild.exe begin /o:"$sonarOrg" /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_token"
42+
}
43+
elseif ($branchMode) {
44+
$branch = $env:APPVEYOR_REPO_BRANCH;
45+
Write-Output "Sonar: Running Sonar in branch mode for branch $branch"
46+
SonarScanner.MSBuild.exe begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.branch.name=$branch"
47+
}
48+
else {
49+
Write-Output "Sonar: Running Sonar in non-preview mode, on branch $env:APPVEYOR_REPO_BRANCH"
50+
SonarScanner.MSBuild.exe begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion"
51+
}
52+
53+
msbuild /t:Rebuild $projectFile /p:targetFrameworks=$framework /verbosity:minimal
54+
55+
SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonar_token"
56+
}
57+
else {
58+
Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'"
59+
}

src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.W
2222
<PackageLicenseUrl>https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE</PackageLicenseUrl>
2323
<RepositoryType>git</RepositoryType>
2424
<RepositoryUrl>git://github.com/NLog/NLog.Extensions.Logging</RepositoryUrl>
25-
25+
<ProjectGuid>{6A236D76-C9D9-4B1D-8DDE-F6978D110288}</ProjectGuid> <!--Project guid for Sonar-->
2626
<SignAssembly>true</SignAssembly>
2727
<AssemblyVersion>1.0.0.0</AssemblyVersion>
2828
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>

0 commit comments

Comments
 (0)