Skip to content

Commit d590181

Browse files
committed
Get a ps script going for doing public builds
1 parent 620962e commit d590181

File tree

2 files changed

+133
-36
lines changed

2 files changed

+133
-36
lines changed

Build-Solution.ps1

Lines changed: 133 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
param(
2-
[ValidateSet('FullBuild', 'RunUnitTests', 'RunIntegrationTests', 'Build', 'Clean')]
2+
[ValidateSet('Full', 'Tests', 'Build', 'Clean')]
33
[string]
4-
$build = "FullBuild"
4+
$build = "Build"
55
,
66
[ValidateSet('Debug', 'Release')]
77
[string]
@@ -12,10 +12,136 @@ param(
1212
$platform = "Any CPU"
1313
,
1414
[string]
15-
$MSBuildVerbosity = "normal"
15+
$verbosity = "minimal"
1616
)
1717

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

GitHubVS.msbuild

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)