build-new.ps1 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
  2. $configuration = $Env:BuildConfiguration
  3. $isCloudBuild = Test-Path -Path env:\TF_BUILD
  4. $outputLocation = Join-Path $scriptPath "testResults"
  5. $openCoverPath = ".\packages\OpenCover\tools\OpenCover.Console.exe"
  6. $rootPath = (Resolve-Path .).Path
  7. $artifacts = Join-Path $rootPath "artifacts"
  8. $signClientSettings = Join-Path (Join-Path (Get-Item $scriptPath).Parent.Parent.FullName "scripts") "SignClientSettings.json"
  9. $hasSignClientSecret = !([string]::IsNullOrEmpty($env:SignClientSecret))
  10. $signClientAppPath = ".\packages\SignClient\tools\netcoreapp2.0\SignClient.dll"
  11. #remove any old coverage file
  12. md -Force $outputLocation | Out-Null
  13. $outputPath = (Resolve-Path $outputLocation).Path
  14. $outputFile = Join-Path $outputPath -childpath 'coverage-rx.xml'
  15. Remove-Item $outputPath -Force -Recurse
  16. md -Force $outputLocation | Out-Null
  17. if (!(Test-Path .\nuget.exe)) {
  18. wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
  19. }
  20. # get tools
  21. .\nuget.exe install -excludeversion SignClient -Version 0.9.1 -outputdirectory packages
  22. .\nuget.exe install -excludeversion JetBrains.dotCover.CommandLineTools -version 2017.3.5 -outputdirectory packages
  23. .\nuget.exe install -excludeversion Nerdbank.GitVersioning -Version 2.1.23 -outputdirectory packages
  24. #.\nuget.exe install -excludeversion OpenCover -Version 4.6.519 -outputdirectory packages
  25. .\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
  26. #.\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
  27. .\nuget.exe install -excludeversion coveralls.io.dotcover -outputdirectory packages
  28. #update version
  29. $versionObj = .\packages\Nerdbank.GitVersioning\tools\get-version.ps1
  30. $packageSemVer = $versionObj.NuGetPackageVersion
  31. Write-Host "Building $packageSemVer" -Foreground Green
  32. New-Item -ItemType Directory -Force -Path $artifacts
  33. Write-Host "Building $scriptPath\System.Reactive.sln" -Foreground Green
  34. msbuild "$scriptPath\System.Reactive.sln" /restore /t:build /m /p:Configuration=$configuration /p:CreatePackage=true /p:NoPackageAnalysis=true
  35. if ($LastExitCode -ne 0) {
  36. Write-Host "Error with build" -Foreground Red
  37. if($isCloudBuild) {
  38. $host.SetShouldExit($LastExitCode)
  39. exit $LastExitCode
  40. }
  41. }
  42. Write-Host "Building Compat Package" -Foreground Green
  43. .\nuget.exe pack "$scriptPath\facades\System.Reactive.Compatibility.nuspec" -Version $packageSemVer -MinClientVersion 2.12 -nopackageanalysis -outputdirectory "$artifacts"
  44. if($hasSignClientSecret) {
  45. Write-Host "Signing Packages" -Foreground Green
  46. $nupgks = ls $artifacts\*React*.nupkg | Select -ExpandProperty FullName
  47. foreach ($nupkg in $nupgks) {
  48. Write-Host "Submitting $nupkg for signing"
  49. dotnet $signClientAppPath 'sign' -c $signClientSettings -i $nupkg -r $env:SignClientUser -s $env:SignClientSecret -n 'Rx.NET' -d 'Reactive Extensions for .NET' -u 'http://reactivex.io/'
  50. if ($LastExitCode -ne 0) {
  51. Write-Host "Error signing $nupkg" -Foreground Red
  52. if($isCloudBuild) {
  53. $host.SetShouldExit($LastExitCode)
  54. exit $LastExitCode
  55. }
  56. }
  57. Write-Host "Finished signing $nupkg"
  58. }
  59. } else {
  60. Write-Host "Client Secret not found, not signing packages"
  61. }
  62. Write-Host "Running tests" -Foreground Green
  63. $testDirectory = Join-Path $scriptPath "tests\Tests.System.Reactive"
  64. # OpenCover isn't working currently. So run tests on CI and coverage with JetBrains
  65. $dotnet = "$env:ProgramFiles\dotnet\dotnet.exe"
  66. .\packages\JetBrains.dotCover.CommandLineTools\tools\dotCover.exe analyse /targetexecutable="$dotnet" /targetworkingdir="$testDirectory" /targetarguments="test -c $configuration --no-build --no-restore --filter `"SkipCI!=true`"" /Filters="+:module=System.Reactive;+:module=Microsoft.Reactive.Testing;+:module=System.Reactive.Observable.Aliases;-:type=Xunit*" /DisableDefaultFilters /ReturnTargetExitCode /AttributeFilters="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" /Output="$outputFile" /ReportType=DetailedXML /HideAutoProperties
  67. #dotnet test $testDirectory --no-build --no-restore -c "Release" --filter "SkipCI!=true"
  68. if ($LastExitCode -ne 0) {
  69. Write-Host "Error with tests" -Foreground Red
  70. if($isCloudBuild) {
  71. $host.SetShouldExit($LastExitCode)
  72. exit $LastExitCode
  73. }
  74. }
  75. & dotnet test tests\Tests.System.Reactive.ApiApprovals\Tests.System.Reactive.ApiApprovals.csproj -c $configuration --no-build --no-restore
  76. if ($LastExitCode -ne 0) {
  77. Write-Host "Error with API approval tests" -Foreground Red
  78. if($isCloudBuild) {
  79. $host.SetShouldExit($LastExitCode)
  80. exit $LastExitCode
  81. }
  82. }
  83. # Either display or publish the results
  84. if ($isCloudBuild -eq 'True')
  85. {
  86. .\packages\coveralls.io.dotcover\tools\coveralls.net.exe -f -p DotCover "$outputFile"
  87. }
  88. else
  89. {
  90. .\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
  91. &"$outPutPath/index.htm"
  92. }