build-new.ps1 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 tools
  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. Write-Host "Building projects" -Foreground Green
  36. $projects = gci $scriptPath -Directory `
  37. | Where-Object { ($_.Name -notlike "*DeviceRunner") -and (Test-Path (Join-Path $_.FullName "project.json")) } `
  38. foreach ($project in $projects) {
  39. dotnet build -c "$configuration" $project.FullName
  40. if ($LastExitCode -ne 0) {
  41. Write-Host "Error building project $project" -Foreground Red
  42. if($isAppVeyor) {
  43. $host.SetShouldExit($LastExitCode)
  44. }
  45. }
  46. }
  47. Write-Host "Building Packages" -Foreground Green
  48. $nuspecs = ls $nuspecDir\*.nuspec | Select -ExpandProperty FullName
  49. New-Item -ItemType Directory -Force -Path .\artifacts
  50. foreach ($nuspec in $nuspecs) {
  51. .\nuget pack $nuspec -symbols -Version $version -Properties "Configuration=$configuration" -MinClientVersion 2.12 -outputdirectory .\artifacts
  52. if ($LastExitCode -ne 0) {
  53. Write-Host "Error packing NuGet $nuspec" -Foreground Red
  54. if($isAppVeyor) {
  55. $host.SetShouldExit($LastExitCode)
  56. }
  57. }
  58. }
  59. Write-Host "Running tests" -Foreground Green
  60. $testDirectory = Join-Path $scriptPath "Tests"
  61. # Execute OpenCover with a target of "dotnet test"
  62. .\packages\OpenCover\tools\OpenCover.Console.exe -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.*]*"
  63. if ($LastExitCode -ne 0) {
  64. Write-Host "Error with tests" -Foreground Red
  65. if($isAppVeyor) {
  66. $host.SetShouldExit($LastExitCode)
  67. }
  68. }
  69. # Either display or publish the results
  70. if ($env:CI -eq 'True')
  71. {
  72. .\packages\coveralls.io\tools\coveralls.net.exe --opencover "$outputFile" --full-sources
  73. }
  74. else
  75. {
  76. .\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
  77. &$outPutPath/index.htm
  78. }
  79. if ($env:CI -ne 'True') {
  80. Write-Host "Reverting AssemblyInfo's" -Foreground Green
  81. gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ }
  82. }