@@ -26,6 +26,7 @@ $projectPath = ".\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFramework
2626$libraryOnlySolutionPath = " .\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFrameworkDiffLog.Library.sln"
2727
2828if (Test-Path .\artifacts) { Remove-Item .\artifacts - Force - Recurse }
29+ if (Test-Path .\testresults) { Remove-Item .\testresults - Force - Recurse }
2930
3031# Version Configuration
3132$csprojContent = Get-Content $projectPath
@@ -55,14 +56,40 @@ echo "Build entire solution"
5556exec { & dotnet build - c Release }
5657
5758echo " Tests Core version"
58- exec { & dotnet test - c Release }
59+ dotnet test - c Release -- test-adapter - path:. -- logger:" nunit;LogFilePath=$ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\core-results.xml"
60+
61+ $corePassed = $lastexitcode
5962
6063echo " Adjust Configuration for Tests 4.5"
6164Remove-Item - Path " .\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll.config"
6265Rename-Item - Path " .\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\App.Release.config" - NewName " HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll.config"
6366
6467echo " Tests 4.5 version"
65- exec { & " .\packages\NUnit.ConsoleRunner.3.10.0\tools\nunit3-console.exe" " .\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll" }
68+ .\packages\NUnit.ConsoleRunner.3.10 .0 \tools\nunit3-console.exe .\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll -- result= " $ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\net45-results.xml"
69+
70+ $net45Passed = $lastexitcode
71+
72+ echo " Upload results to AppVeyor"
73+ $wc = New-Object ' System.Net.WebClient'
74+ $wc.UploadFile (" https://ci.appveyor.com/api/testresults/nunit3/$ ( $env: APPVEYOR_JOB_ID ) " , (Resolve-Path " $ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\net45-results.xml" ))
75+ $wc.UploadFile (" https://ci.appveyor.com/api/testresults/nunit3/$ ( $env: APPVEYOR_JOB_ID ) " , (Resolve-Path " $ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\core-results.xml" ))
76+
77+ $errorMessage = $NULL
78+
79+ if ($corePassed -ne 0 )
80+ {
81+ $errorMessage = " .Net Core tests failed`r`n "
82+ }
83+
84+ if ($net45Passed -ne 0 )
85+ {
86+ $errorMessage = $errorMessage + " .Net 4.5 tests failed`r`n "
87+ }
88+
89+ if ($errorMessage -ne $NULL )
90+ {
91+ throw $errorMessage
92+ }
6693
6794# Sonar Analysis
6895echo " Installing sonarscanner"
@@ -84,20 +111,43 @@ Catch
84111 else { echo " sonarscanner already installed" }
85112}
86113
114+ echo " Installing reportgenerator"
115+ Try
116+ {
117+ exec { & dotnet tool install - g dotnet- reportgenerator- globaltool }
118+ }
119+ Catch
120+ {
121+ $needInstallSonar = dotnet tool list - g | Select-String - Pattern " dotnet-reportgenerator-globaltool" | % { $_.Matches.Value -eq $NULL }
122+ if ($needInstallSonar -eq $true )
123+ {
124+ $ErrorMessage = $_.Exception.Message
125+ $FailedItem = $_.Exception.ItemName
126+ echo $FailedItem
127+ echo $ErrorMessage
128+ return -1
129+ }
130+ else { echo " reportgenerator already installed" }
131+ }
132+
87133echo " Starting Sonar for Library"
88134
89135if ($env: APPVEYOR_PULL_REQUEST_NUMBER -ne $null )
90136{
91- exec { & dotnet sonarscanner begin / d:sonar.login= " $env: sonartoken " / key:" HodStudio.EntityFrameworkDiffLog" / o:" hodstudio-github" / d:sonar.sources= " .\src\HodStudio.EntityFrameworkDiffLog" / d:sonar.host.url= " https://sonarcloud.io" / d:sonar.pullrequest.base= " $env: APPVEYOR_REPO_BRANCH " / d:sonar.pullrequest.branch= " $env: APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH " / d:sonar.pullrequest.key= " $env: APPVEYOR_PULL_REQUEST_NUMBER " / d:sonar.pullrequest.provider= " GitHub" / d:sonar.pullrequest.github.repository= " $env: APPVEYOR_REPO_NAME " }
137+ exec { & dotnet sonarscanner begin / d:sonar.login= " $env: sonartoken " / key:" HodStudio.EntityFrameworkDiffLog" / o:" hodstudio-github" / d:sonar.sources= " .\src\HodStudio.EntityFrameworkDiffLog" / d:sonar.host.url= " https://sonarcloud.io" / d:sonar.pullrequest.base= " $env: APPVEYOR_REPO_BRANCH " / d:sonar.pullrequest.branch= " $env: APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH " / d:sonar.pullrequest.key= " $env: APPVEYOR_PULL_REQUEST_NUMBER " / d:sonar.pullrequest.provider= " GitHub" / d:sonar.pullrequest.github.repository= " $env: APPVEYOR_REPO_NAME " / d:sonar.coverageReportPaths = " $ ( $ env: APPVEYOR_BUILD_FOLDER ) \testresults\SonarQube.xml " }
92138}
93139else
94140{
95- exec { & dotnet sonarscanner begin / d:sonar.login= " $env: sonartoken " / key:" HodStudio.EntityFrameworkDiffLog" / o:" hodstudio-github" / d:sonar.sources= " .\src\HodStudio.EntityFrameworkDiffLog" / d:sonar.host.url= " https://sonarcloud.io" / version:" $completeVersion " }
141+ exec { & dotnet sonarscanner begin / d:sonar.login= " $env: sonartoken " / key:" HodStudio.EntityFrameworkDiffLog" / o:" hodstudio-github" / d:sonar.sources= " .\src\HodStudio.EntityFrameworkDiffLog" / d:sonar.host.url= " https://sonarcloud.io" / version:" $completeVersion " / d:sonar.coverageReportPaths = " $ ( $ env: APPVEYOR_BUILD_FOLDER ) \testresults\SonarQube.xml " }
96142}
97143
98144exec { & dotnet build $libraryOnlySolutionPath - c Release }
99145
146+ dotnet test - c Release - s " $ ( $env: APPVEYOR_BUILD_FOLDER ) \coverletArgs.runsettings" - r " $ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\"
147+
148+ exec { & reportgenerator " -reports:$ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\*\*.xml" " -targetdir:$ ( $env: APPVEYOR_BUILD_FOLDER ) \TestResults\" " -reporttypes:SonarQube" }
149+
100150exec { & dotnet sonarscanner end / d:sonar.login= " $env: sonartoken " }
101151
102152echo " Packing the library"
103- exec { & dotnet pack $projectPath - c Release - o .\..\..\ artifacts -- version- suffix= $revision }
153+ exec { & dotnet pack $projectPath - c Release - o " $ ( $ env: APPVEYOR_BUILD_FOLDER ) \ artifacts" -- version- suffix= $revision }
0 commit comments