From d51f841e9bc50361d73cb5d55b749d2b809c6433 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Wed, 24 Mar 2021 22:00:14 +0100 Subject: [PATCH 1/9] Upgrade sonarscanner --- run-sonar.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index ecf2cc0d..c4030cf2 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -29,7 +29,7 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { Write-Output "Sonar: on branch $env:APPVEYOR_REPO_BRANCH" } - choco install "msbuild-sonarqube-runner" -y + choco install "sonarscanner-msbuild-netcoreapp2.0" -y $sonarUrl = "https://sonarcloud.io" $sonarToken = $env:sonar_token @@ -56,4 +56,4 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { } else { Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" -} \ No newline at end of file +} From 77da5fdcd0feb6a600520efbc68ae53535c52a3a Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Wed, 24 Mar 2021 22:26:00 +0100 Subject: [PATCH 2/9] dotnet-sonarscanner --- run-sonar.ps1 | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index c4030cf2..43e6ecde 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -29,30 +29,17 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { Write-Output "Sonar: on branch $env:APPVEYOR_REPO_BRANCH" } - choco install "sonarscanner-msbuild-netcoreapp2.0" -y + dotnet tool install --global dotnet-sonarscanner $sonarUrl = "https://sonarcloud.io" $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:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.analysis.mode=preview" /d:"sonar.github.pullRequest=$pr" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" - } - elseif ($branchMode) { - $branch = $env:APPVEYOR_REPO_BRANCH; - Write-Output "Sonar: Running Sonar in branch mode for branch $branch" - SonarScanner.MSBuild.exe begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /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:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" - } + dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" msbuild /t:Rebuild $projectFile /p:targetFrameworks=$framework /verbosity:minimal - SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonar_token" + dotnet-sonarscanner end /d:"sonar.login=$env:sonar_token" } else { Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" From 73b35f1595929e3c06f3d1468cdb23c47af316a3 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Wed, 24 Mar 2021 22:27:06 +0100 Subject: [PATCH 3/9] check $LastExitCode --- run-sonar.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 43e6ecde..6c9c0e11 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -30,16 +30,28 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { } dotnet tool install --global dotnet-sonarscanner + if (-Not $LastExitCode -eq 0) { + exit $LastExitCode + } $sonarUrl = "https://sonarcloud.io" $sonarToken = $env:sonar_token $buildVersion = $env:APPVEYOR_BUILD_VERSION dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" + if (-Not $LastExitCode -eq 0) { + exit $LastExitCode + } msbuild /t:Rebuild $projectFile /p:targetFrameworks=$framework /verbosity:minimal + if (-Not $LastExitCode -eq 0) { + exit $LastExitCode + } dotnet-sonarscanner end /d:"sonar.login=$env:sonar_token" + if (-Not $LastExitCode -eq 0) { + exit $LastExitCode + } } else { Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" From a82c92183812d67d3fc3686888fd66e68f6d5465 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Wed, 24 Mar 2021 23:32:15 +0100 Subject: [PATCH 4/9] Java 11 --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0a37ef01..fbc0ddb0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,8 +29,9 @@ test_script: - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp3.1 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f net5.0 -c debug NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - pip install codecov - - pip install codecov - codecov -f "coverage.xml" + - set JAVA_HOME=C:\Program Files\Java\jdk11 + - set PATH=%JAVA_HOME%\bin;%PATH% - ps: .\run-sonar.ps1 - ps: .\run-tests.ps1 From 8f8f2aa4dd6c60b1eac6b1da6a7ad2e0f9ba816b Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:02:02 +0100 Subject: [PATCH 5/9] Update run-sonar.ps1 --- run-sonar.ps1 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 6c9c0e11..3a13f7b2 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -38,7 +38,22 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { $sonarToken = $env:sonar_token $buildVersion = $env:APPVEYOR_BUILD_VERSION - dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" + + if ($prMode) { + $pr = $env:APPVEYOR_PULL_REQUEST_NUMBER + Write-Output "Sonar: Running Sonar for PR $pr" + dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.github.pullRequest=$pr" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" + } + elseif ($branchMode) { + $branch = $env:APPVEYOR_REPO_BRANCH; + Write-Output "Sonar: Running Sonar in branch mode for branch $branch" + dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.branch.name=$branch" + } + else { + Write-Output "Sonar: Running Sonar in non-preview mode, on branch $env:APPVEYOR_REPO_BRANCH" + dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" + } + if (-Not $LastExitCode -eq 0) { exit $LastExitCode } From 7ebcb63aaa3d948fc8d3c285bd802d7dc50b70c1 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:30:22 +0100 Subject: [PATCH 6/9] pullrequest.key / pullrequest.base --- run-sonar.ps1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 3a13f7b2..12ed0903 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -19,14 +19,12 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { 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" } dotnet tool install --global dotnet-sonarscanner @@ -40,17 +38,24 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { if ($prMode) { + $branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH + $prBaseBranch = $env:APPVEYOR_REPO_BRANCH; $pr = $env:APPVEYOR_PULL_REQUEST_NUMBER + + Write-Output "Sonar: on PR $pr from $branch to $prBaseBranch" + Write-Output "Sonar: Running Sonar for PR $pr" - dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.github.pullRequest=$pr" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" + dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.pullrequest.key=$pr" /d:"sonar.pullrequest.branch=$branch" /d:"sonar.pullrequest.base=$prBaseBranch" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" } elseif ($branchMode) { $branch = $env:APPVEYOR_REPO_BRANCH; + + Write-Output "Sonar: on branch $branch" Write-Output "Sonar: Running Sonar in branch mode for branch $branch" dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.branch.name=$branch" } else { - Write-Output "Sonar: Running Sonar in non-preview mode, on branch $env:APPVEYOR_REPO_BRANCH" + Write-Output "Sonar: Running Sonar on base branch" dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" } From 41d737d4c61006a9cf03e1fb341e499b72fb8bb3 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:31:47 +0100 Subject: [PATCH 7/9] cleanup, remove special base branch mode --- run-sonar.ps1 | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 12ed0903..2eb7d670 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -14,18 +14,11 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { } $prMode = $false; - $branchMode = $false; if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { # first check PR as that is on the base branch $prMode = $true; } - elseif ($env:APPVEYOR_REPO_BRANCH -eq $baseBranch) { - Write-Output "Sonar: on base branch ($baseBranch)" - } - else { - $branchMode = $true; - } dotnet tool install --global dotnet-sonarscanner if (-Not $LastExitCode -eq 0) { @@ -36,7 +29,6 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { $sonarToken = $env:sonar_token $buildVersion = $env:APPVEYOR_BUILD_VERSION - if ($prMode) { $branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH $prBaseBranch = $env:APPVEYOR_REPO_BRANCH; @@ -47,17 +39,13 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { Write-Output "Sonar: Running Sonar for PR $pr" dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.pullrequest.key=$pr" /d:"sonar.pullrequest.branch=$branch" /d:"sonar.pullrequest.base=$prBaseBranch" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" } - elseif ($branchMode) { + else $branch = $env:APPVEYOR_REPO_BRANCH; Write-Output "Sonar: on branch $branch" Write-Output "Sonar: Running Sonar in branch mode for branch $branch" dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.branch.name=$branch" } - else { - Write-Output "Sonar: Running Sonar on base branch" - dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" - } if (-Not $LastExitCode -eq 0) { exit $LastExitCode From 9f9bc0f9ffd12fba91de5bb540242ba4a0dbb9f8 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:45:09 +0100 Subject: [PATCH 8/9] fixup --- run-sonar.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 2eb7d670..30fcf0f8 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -39,7 +39,7 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { Write-Output "Sonar: Running Sonar for PR $pr" dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.pullrequest.key=$pr" /d:"sonar.pullrequest.branch=$branch" /d:"sonar.pullrequest.base=$prBaseBranch" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" } - else + else { $branch = $env:APPVEYOR_REPO_BRANCH; Write-Output "Sonar: on branch $branch" From 935406bc4e6d8edbf1811b978fdb3248fb2c8490 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Fri, 26 Mar 2021 23:00:01 +0100 Subject: [PATCH 9/9] cleanup output, write-host --- run-sonar.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 30fcf0f8..51a5ed36 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -34,16 +34,13 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { $prBaseBranch = $env:APPVEYOR_REPO_BRANCH; $pr = $env:APPVEYOR_PULL_REQUEST_NUMBER - Write-Output "Sonar: on PR $pr from $branch to $prBaseBranch" - - Write-Output "Sonar: Running Sonar for PR $pr" + Write-Host "Sonar: on PR $pr from $branch to $prBaseBranch" -ForegroundColor DarkGreen -BackgroundColor White dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.pullrequest.key=$pr" /d:"sonar.pullrequest.branch=$branch" /d:"sonar.pullrequest.base=$prBaseBranch" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:github_auth_token" } else { $branch = $env:APPVEYOR_REPO_BRANCH; - Write-Output "Sonar: on branch $branch" - Write-Output "Sonar: Running Sonar in branch mode for branch $branch" + Write-Host "Sonar: on branch $branch" -ForegroundColor DarkGreen -BackgroundColor White dotnet-sonarscanner begin /o:"$sonarOrg" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.cs.opencover.reportsPaths=coverage.xml" /d:"sonar.branch.name=$branch" } @@ -62,5 +59,5 @@ if ($env:APPVEYOR_REPO_NAME -eq $github) { } } else { - Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" + Write-Host "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" }