1
0

build-new.ps1 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. $openCoverPath = ".\packages\OpenCover\tools\OpenCover.Console.exe"
  7. $signClientSettings = Join-Path (Join-Path (Get-Item $scriptPath).Parent.Parent.FullName "scripts") "SignClientSettings.json"
  8. $hasSignClientSecret = !([string]::IsNullOrEmpty($env:SignClientSecret))
  9. $signClientAppPath = Join-Path (Join-Path (Join-Path .\Packages "SignClient") "Tools") "SignClient.dll"
  10. #remove any old coverage file
  11. md -Force $outputLocation | Out-Null
  12. $outputPath = (Resolve-Path $outputLocation).Path
  13. $outputFile = Join-Path $outputPath -childpath 'coverage-rx.xml'
  14. Remove-Item $outputPath -Force -Recurse
  15. md -Force $outputLocation | Out-Null
  16. if (!(Test-Path .\nuget.exe)) {
  17. wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
  18. }
  19. $msbuild = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"
  20. # TODO: if not found, bail out
  21. $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
  22. # get version
  23. .\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
  24. .\nuget.exe install -excludeversion SignClient -Version 0.5.0-beta3 -pre -outputdirectory packages
  25. .\nuget.exe install -excludeversion OpenCover -outputdirectory packages
  26. .\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
  27. .\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
  28. #update version
  29. .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
  30. $versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json
  31. $version = $versionObj.MajorMinorPatch
  32. $tag = $versionObj.PreReleaseLabel
  33. $preRelNum = $versionObj.CommitsSinceVersionSourcePadded
  34. if($tag -ne ""){
  35. if($preRelNum -ne "00000" {
  36. $version = "$version-$tag-$preRelNum"
  37. }
  38. else {
  39. $version = "$version-$tag"
  40. }
  41. }
  42. Write-Host "Version: $version"
  43. Write-Host "Restoring packages" -Foreground Green
  44. dotnet restore $scriptPath | out-null
  45. #need to ensure core is built first due to bad dependency order determination by dotnet build
  46. $coreDir = gci $scriptPath -Directory | where-object {$_.Name -eq "System.Reactive.Core"} | Select -First 1
  47. dotnet build -c "$configuration" $coreDir.FullName
  48. Write-Host "Building projects" -Foreground Green
  49. $projects = gci $scriptPath -Directory `
  50. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  51. foreach ($project in $projects) {
  52. dotnet build -c "$configuration" $project.FullName
  53. if ($LastExitCode -ne 0) {
  54. Write-Host "Error building project $project" -Foreground Red
  55. if($isAppVeyor) {
  56. $host.SetShouldExit($LastExitCode)
  57. }
  58. }
  59. }
  60. Write-Host "Building Packages" -Foreground Green
  61. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  62. New-Item -ItemType Directory -Force -Path .\artifacts
  63. foreach ($nuspec in $nuspecs)
  64. {
  65. $symbolSwitch = "-symbols"
  66. # nuget will error if we pass -symbols to the meta-package
  67. if($nuSpec -like "*\System.Reactive.nuspec")
  68. {
  69. $symbolSwitch = ""
  70. }
  71. .\nuget pack $nuspec $symbolSwitch -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.12 -outputdirectory .\artifacts
  72. if ($LastExitCode -ne 0) {
  73. Write-Host "Error packing NuGet $nuspec" -Foreground Red
  74. if($isAppVeyor) {
  75. $host.SetShouldExit($LastExitCode)
  76. }
  77. }
  78. }
  79. if($hasSignClientSecret) {
  80. Write-Host "Signing Packages" -Foreground Green
  81. $nupgks = ls .\artifacts\*React*.nupkg | Select -ExpandProperty FullName
  82. foreach ($nupkg in $nupgks) {
  83. Write-Host "Submitting $nupkg for signing"
  84. dotnet $signClientAppPath 'zip' -c $signClientSettings -i $nupkg -s $env:SignClientSecret -n 'Rx.NET' -d 'Reactive Extensions for .NET' -u 'http://reactivex.io/'
  85. if ($LastExitCode -ne 0) {
  86. Write-Host "Error signing $nupkg" -Foreground Red
  87. if($isAppVeyor) {
  88. $host.SetShouldExit($LastExitCode)
  89. }
  90. }
  91. Write-Host "Finished signing $nupkg"
  92. }
  93. } else {
  94. Write-Host "Client Secret not found, not signing packages"
  95. }
  96. Write-Host "Running tests" -Foreground Green
  97. $testDirectory = Join-Path $scriptPath "Tests.System.Reactive"
  98. # Execute OpenCover with a target of "dotnet test"
  99. & $openCoverPath -register:user -oldStyle -mergeoutput -target:dotnet.exe -targetdir:"$testDirectory" -targetargs:"test $testDirectory -c $configuration -notrait SkipCI=true" -output:"$outputFile" -skipautoprops -returntargetcode -excludebyattribute:"System.Diagnostics.DebuggerNonUserCodeAttribute;System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" -nodefaultfilters -hideskipped:All -filter:"+[*]* -[*.Tests]* -[Tests.*]* -[xunit.*]* -[*]Xunit.*"
  100. if ($LastExitCode -ne 0) {
  101. Write-Host "Error with tests" -Foreground Red
  102. if($isAppVeyor) {
  103. $host.SetShouldExit($LastExitCode)
  104. }
  105. }
  106. # Either display or publish the results
  107. if ($env:CI -eq 'True')
  108. {
  109. .\packages\coveralls.io\tools\coveralls.net.exe --opencover "$outputFile" --full-sources
  110. }
  111. else
  112. {
  113. .\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
  114. &$outPutPath/index.htm
  115. }
  116. if ($env:CI -ne 'True') {
  117. Write-Host "Reverting AssemblyInfo's" -Foreground Green
  118. gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ }
  119. }