build-new.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
  2. $configuration = "Release"
  3. $nuspecDir = Join-Path $scriptPath "NuSpecs"
  4. $isAppVeyor = Test-Path -Path env:\APPVEYOR
  5. $outputLocation = Join-Path $scriptPath "testResults"
  6. #remove any old coverage file
  7. md -Force $outputLocation | Out-Null
  8. $outputPath = (Resolve-Path $outputLocation).Path
  9. $outputFile = Join-Path $outputPath -childpath 'coverage.xml'
  10. Remove-Item $outputPath -Force -Recurse
  11. md -Force $outputLocation | Out-Null
  12. if (!(Test-Path .\nuget.exe)) {
  13. wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
  14. }
  15. $msbuild = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
  16. # TODO: if not found, bail out
  17. $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
  18. # get version
  19. .\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
  20. .\nuget.exe install -excludeversion OpenCover -outputdirectory packages
  21. .\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
  22. .\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
  23. #update version
  24. .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
  25. $versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json
  26. $version = $versionObj.MajorMinorPatch
  27. $tag = $versionObj.PreReleaseLabel
  28. $preRelNum = $versionObj.CommitsSinceVersionSourcePadded
  29. if($tag -ne ""){
  30. $version = "$version-$tag-$preRelNum"
  31. }
  32. Write-Host "Version: $version"
  33. Write-Host "Restoring packages" -Foreground Green
  34. dotnet restore $scriptPath | out-null
  35. #need to ensure core is built first due to bad dependency order determination by dotnet build
  36. $coreDir = gci $scriptPath -Directory | where-object {$_.Name -eq "System.Reactive.Core"} | Select -First 1
  37. dotnet build -c "$configuration" $coreDir.FullName
  38. Write-Host "Building projects" -Foreground Green
  39. $projects = gci $scriptPath -Directory `
  40. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  41. foreach ($project in $projects) {
  42. dotnet build -c "$configuration" $project.FullName
  43. if ($LastExitCode -ne 0) {
  44. Write-Host "Error building project $project" -Foreground Red
  45. if($isAppVeyor) {
  46. $host.SetShouldExit($LastExitCode)
  47. }
  48. }
  49. }
  50. Write-Host "Building Packages" -Foreground Green
  51. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  52. New-Item -ItemType Directory -Force -Path .\artifacts
  53. foreach ($nuspec in $nuspecs)
  54. {
  55. $symbolSwitch = "-symbols"
  56. # nuget will error if we pass -symbols to the meta-package
  57. if($nuSpec -like "*\System.Reactive.nuspec")
  58. {
  59. $symbolSwitch = ""
  60. }
  61. .\nuget pack $nuspec $symbolSwitch -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.12 -outputdirectory .\artifacts
  62. if ($LastExitCode -ne 0) {
  63. Write-Host "Error packing NuGet $nuspec" -Foreground Red
  64. if($isAppVeyor) {
  65. $host.SetShouldExit($LastExitCode)
  66. }
  67. }
  68. }
  69. Write-Host "Running tests" -Foreground Green
  70. $testDirectory = Join-Path $scriptPath "Tests.System.Reactive"
  71. # Execute OpenCover with a target of "dotnet test"
  72. .\packages\OpenCover\tools\OpenCover.Console.exe -register:user -oldStyle -mergeoutput -target:dotnet.exe -threshold:1 -targetdir:"$testDirectory" -targetargs:"test $testDirectory -c $configuration" -output:"$outputFile" -skipautoprops -returntargetcode "-excludebyattribute:System.Diagnostics.DebuggerNonUserCodeAttribute" -nodefaultfilters -hideskipped:All -filter:"+[*]* -[*.Tests]* -[Tests.*]* -[xunit.*]* -[*]Xunit.*"
  73. if ($LastExitCode -ne 0) {
  74. Write-Host "Error with tests" -Foreground Red
  75. if($isAppVeyor) {
  76. $host.SetShouldExit($LastExitCode)
  77. }
  78. }
  79. # Either display or publish the results
  80. if ($env:CI -eq 'True')
  81. {
  82. .\packages\coveralls.io\tools\coveralls.net.exe --opencover "$outputFile" --full-sources
  83. }
  84. else
  85. {
  86. .\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
  87. &$outPutPath/index.htm
  88. }
  89. Write-Host "Reverting AssemblyInfo's" -Foreground Green
  90. gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ }