forked from github/VisualStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild-Solution.ps1
147 lines (123 loc) · 4.54 KB
/
Build-Solution.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
param(
[ValidateSet('Full', 'Tests', 'Build', 'Clean')]
[string]
$build = "Build"
,
[ValidateSet('Debug', 'Release')]
[string]
$config = "Release"
,
[ValidateSet('Any CPU', 'x86', 'x64')]
[string]
$platform = "Any CPU"
,
[string]
$verbosity = "minimal"
)
$rootDirectory = Split-Path $MyInvocation.MyCommand.Path
$projFile = join-path $rootDirectory GitHubVS.msbuild
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
function Die([string]$message, [object[]]$output) {
if ($output) {
Write-Output $output
$message += ". See output above."
}
Throw (New-Object -TypeName ScriptException -ArgumentList $message)
}
function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
$output = ""
if ($Quiet) {
$output = & $Command 2>&1
} else {
& $Command
}
if (!$Fatal) {
return
}
$exitCode = 0
if (!$? -and $LastExitCode -ne 0) {
$exitCode = $LastExitCode
} elseif (!$?) {
$exitCode = 1
} else {
return
}
Die "``$Command`` failed" $output
}
function Run-XUnit([string]$project, [int]$timeoutDuration, [string]$configuration) {
$dll = "src\$project\bin\$configuration\$project.dll"
$xunitDirectory = Join-Path $rootDirectory packages\xunit.runner.console.2.1.0\tools
$consoleRunner = Join-Path $xunitDirectory xunit.console.x86.exe
$xml = Join-Path $rootDirectory "nunit-$project.xml"
$outputPath = [System.IO.Path]::GetTempFileName()
$args = $dll, "-noshadow", "-xml", $xml, "-parallel", "all"
[object[]] $output = "$consoleRunner " + ($args -join " ")
$process = Start-Process -PassThru -NoNewWindow -RedirectStandardOutput $outputPath $consoleRunner ($args | %{ "`"$_`"" })
Wait-Process -InputObject $process -Timeout $timeoutDuration -ErrorAction SilentlyContinue
if ($process.HasExited) {
$output += Get-Content $outputPath
$exitCode = $process.ExitCode
} else {
$output += "Tests timed out. Backtrace:"
$output += Get-DotNetStack $process.Id
$exitCode = 9999
}
Stop-Process -InputObject $process
Remove-Item $outputPath
$result = New-Object System.Object
$result | Add-Member -Type NoteProperty -Name Output -Value $output
$result | Add-Member -Type NoteProperty -Name ExitCode -Value $exitCode
$result
}
function Run-NUnit([string]$project, [int]$timeoutDuration, [string]$configuration) {
$dll = "src\$project\bin\$configuration\$project.dll"
$nunitDirectory = Join-Path $rootDirectory packages\NUnit.Runners.2.6.4\tools
$consoleRunner = Join-Path $nunitDirectory nunit-console-x86.exe
$xml = Join-Path $rootDirectory "nunit-$project.xml"
$outputPath = [System.IO.Path]::GetTempFileName()
$args = "-noshadow", "-xml:$xml", "-framework:net-4.5", "-exclude:Timings", $dll
[object[]] $output = "$consoleRunner " + ($args -join " ")
$process = Start-Process -PassThru -NoNewWindow -RedirectStandardOutput $outputPath $consoleRunner ($args | %{ "`"$_`"" })
Wait-Process -InputObject $process -Timeout $timeoutDuration -ErrorAction SilentlyContinue
if ($process.HasExited) {
$output += Get-Content $outputPath
$exitCode = $process.ExitCode
} else {
$output += "Tests timed out. Backtrace:"
$output += Get-DotNetStack $process.Id
$exitCode = 9999
}
Stop-Process -InputObject $process
Remove-Item $outputPath
$result = New-Object System.Object
$result | Add-Member -Type NoteProperty -Name Output -Value $output
$result | Add-Member -Type NoteProperty -Name ExitCode -Value $exitCode
$result
}
function Build-Solution([string]$solution) {
Run-Command -Fatal { & $msbuild $solution /t:Build /property:Configuration=$config /verbosity:$verbosity /p:VisualStudioVersion=14.0 /p:DeployExtension=false }
}
Write-Output "Building GitHub for Visual Studio..."
Write-Output ""
Build-Solution GitHubVs.sln
$exitCode = 0
Write-Output "Running Unit Tests..."
$result = Run-XUnit UnitTests 180 $config
if ($result.ExitCode -eq 0) {
# Print out the test result summary.
Write-Output $result.Output[-1]
} else {
$exitCode = $result.ExitCode
Write-Output $result.Output
}
Write-Output "Running TrackingCollection Tests..."
$result = Run-NUnit TrackingCollectionTests 180 $config
if ($result.ExitCode -eq 0) {
# Print out the test result summary.
Write-Output $result.Output[-3]
} else {
$exitCode = $result.ExitCode
Write-Output $result.Output
}
Write-Output ""
exit $exitCode