-Update build script to run tests against the final assemblies

-Update psake script to latest version
This commit is contained in:
JamesNK
2010-02-28 07:58:37 +00:00
parent 29b1ff5f0a
commit d93aaf9707
4 changed files with 129 additions and 88 deletions
+43 -26
View File
@@ -38,42 +38,34 @@ task Build -depends Clean {
foreach ($build in $builds)
{
$name = $build.Name
$finalDir = $build.FinalDir
Write-Host -ForegroundColor Green "Building " $name
Write-Host
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$signAssemblies" (GetConstants $build.Constants $signAssemblies) ".\Src\Newtonsoft.Json\$name.csproj" } "Error building $name"
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$signAssemblies" (GetConstants $build.Constants $signAssemblies) ".\Src\$name.sln" } "Error building $name"
}
}
task Package -depends Build {
$compileOutputDir = "$sourceDir\Newtonsoft.Json\bin\Release"
Copy-Item -Path $compileOutputDir -Destination $workingDir -recurse
task Merge -depends Build {
$binaryDir = "$sourceDir\Newtonsoft.Json\bin\Release\DotNet20"
MergeAssembly "$binaryDir\Newtonsoft.Json.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
del $binaryDir\LinqBridge.dll
New-Item -Path $workingDir\Merge -ItemType Directory
$ilMergeKeyFile = switch($signAssemblies) { $true { "/keyfile:$signKeyPath" } default { "" } }
exec { .\Tools\ILMerge\ilmerge.exe "/internalize" $ilMergeKeyFile "/out:$workingDir\Merge\Newtonsoft.Json.Net20.dll" "$workingDir\Release\Newtonsoft.Json.Net20.dll" "$workingDir\Release\LinqBridge.dll" } "Error executing ILMerge"
del $workingDir\Release\Newtonsoft.Json.Net20.dll
del $workingDir\Release\Newtonsoft.Json.Net20.pdb
del $workingDir\Release\LinqBridge.dll
Copy-Item -Path $workingDir\Merge\Newtonsoft.Json.Net20.dll -Destination $workingDir\Release\
Copy-Item -Path $workingDir\Merge\Newtonsoft.Json.Net20.pdb -Destination $workingDir\Release\
$binaryDir = "$sourceDir\Newtonsoft.Json.Tests\bin\Release\DotNet20"
MergeAssembly "$binaryDir\Newtonsoft.Json.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
MergeAssembly "$binaryDir\Newtonsoft.Json.Tests.Net20.dll" $signKeyPath "$binaryDir\LinqBridge.dll"
del $binaryDir\LinqBridge.dll
}
task Package -depends Merge {
foreach ($build in $builds)
{
$name = $build.Name
$name = $build.TestsName
$finalDir = $build.FinalDir
New-Item -Path $workingDir\Package\Bin\$finalDir -ItemType Directory
dir $workingDir\Release | where { $_.Name -like "*$name*" -and $_.PSIsContainer -ne $true } | move -Destination $workingDir\Package\Bin\$finalDir\$_
Copy-Item -Path "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" -Destination $workingDir\Package\Bin\$finalDir -recurse
}
del $workingDir\Merge -Recurse
del $workingDir\Release -Recurse
if ($buildDocumentation)
{
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release .\Doc\doc.shfbproj } "Error building documentation. Check that you have Sandcastle, Sandcastle Help File Builder and HTML Help Workshop installed."
@@ -99,12 +91,37 @@ task Test -depends Deploy {
foreach ($build in $builds)
{
$name = $build.TestsName
Write-Host -ForegroundColor Green "Building " $name
$finalDir = $build.FinalDir
Write-Host -ForegroundColor Green "Copying test assembly $name to deployed directory"
Write-Host
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$signAssemblies" (GetConstants $build.Constants $signAssemblies) ".\Src\Newtonsoft.Json.Tests\$name.csproj" } "Error executing MSBUILD"
robocopy ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir" $workingDir\Deployed\Bin\$finalDir /NP /XO /XF LinqBridge.dll
Copy-Item -Path ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir\$name.dll" -Destination $workingDir\Deployed\Bin\$finalDir\
Write-Host -ForegroundColor Green "Running tests " $name
Write-Host
exec { .\Tools\NUnit\nunit-console.exe ".\Src\Newtonsoft.Json.Tests\bin\Release\$name.dll" /xml:$workingDir\$name.xml } "Error running $name tests"
exec { .\Tools\NUnit\nunit-console.exe "$workingDir\Deployed\Bin\$finalDir\$name.dll" /xml:$workingDir\$name.xml } "Error running $name tests"
}
}
function MergeAssembly($dllPrimaryAssembly, $signKey, [string[]]$mergedAssemlies)
{
$mergeAssemblyPaths = [String]::Join(" ", $mergedAssemlies)
$primary = Get-Item $dllPrimaryAssembly
$mergedAssemblyName = $primary.Name
$temporaryDir = $primary.DirectoryName + "\" + [Guid]::NewGuid().ToString()
New-Item $temporaryDir -ItemType Directory
try
{
exec { .\Tools\ILMerge\ilmerge.exe "/internalize" $ilMergeKeyFile "/out:$temporaryDir\$mergedAssemblyName" $dllPrimaryAssembly $mergeAssemblyPaths } "Error executing ILMerge"
Copy-Item -Path $temporaryDir\$mergedAssemblyName -Destination $dllPrimaryAssembly -Force
}
finally
{
Remove-Item $temporaryDir -Recurse -Force
}
}
@@ -270,6 +270,11 @@
<DependentUpon>LinqToSqlClasses.dbml</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="bunny_pancake.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -94,7 +94,7 @@ namespace Newtonsoft.Json.Tests
public void SerializeSizeData()
{
Image image = new Image();
image.Data = System.IO.File.ReadAllBytes(@"..\..\bunny_pancake.jpg");
image.Data = System.IO.File.ReadAllBytes(@"bunny_pancake.jpg");
image.FileName = "bunny_pancake.jpg";
image.Author = "Hironori Akutagawa";
image.Caption = "I have no idea what you are talking about so here's a bunny with a pancake on its head";
+80 -61
View File
@@ -21,24 +21,14 @@
#Requires -Version 2.0
#-- Private Module Variables (Listed here for quick reference)
[string]$script:originalEnvPath
[string]$script:originalDirectory
[string]$script:formatTaskNameString
[string]$script:currentTaskName
[hashtable]$script:tasks
[array]$script:properties
[scriptblock]$script:taskSetupScriptBlock
[scriptblock]$script:taskTearDownScriptBlock
[system.collections.queue]$script:includes
[system.collections.stack]$script:executedTasks
[system.collections.stack]$script:callStack
[system.collections.stack]$script:context
#-- Public Module Variables -- The psake hashtable variable is initialized in the invoke-psake function
$script:psake = @{}
$script:psake.use_exit_on_error = $false # determines if psake uses the "exit()" function when an exception occurs
$script:psake.log_error = $false # determines if the exception details are written to a file
$script:psake.build_success = $false # indicates that the current build was successful
$script:psake.version = "2.02" # contains the current version of psake
$script:psake.version = "2.02" # contains the current version of psake
$script:psake.build_script_file = $null # contains a System.IO.FileInfo for the current build file
$script:psake.framework_version = "" # contains the framework version # for the current build
@@ -53,18 +43,18 @@ function ExecuteTask
$taskKey = $taskName.Tolower()
Assert ($script:tasks.Contains($taskKey)) "task [$taskName] does not exist"
Assert ($script:context.Peek().tasks.Contains($taskKey)) "task [$taskName] does not exist"
if ($script:executedTasks.Contains($taskKey))
if ($script:context.Peek().executedTasks.Contains($taskKey))
{
return
}
Assert (!$script:callStack.Contains($taskKey)) "Error: Circular reference found for task, $taskName"
Assert (!$script:context.Peek().callStack.Contains($taskKey)) "Error: Circular reference found for task, $taskName"
$script:callStack.Push($taskKey)
$script:context.Peek().callStack.Push($taskKey)
$task = $script:tasks.$taskKey
$task = $script:context.Peek().tasks.$taskKey
$taskName = $task.Name
@@ -94,11 +84,11 @@ function ExecuteTask
ExecuteTask $childTask
}
$script:currentTaskName = $taskName
$script:context.Peek().currentTaskName = $taskName
if ($script:taskSetupScriptBlock -ne $null)
if ($script:context.Peek().taskSetupScriptBlock -ne $null)
{
& $script:taskSetupScriptBlock
& $script:context.Peek().taskSetupScriptBlock
}
if ($task.PreAction -ne $null)
@@ -106,7 +96,7 @@ function ExecuteTask
& $task.PreAction
}
$script:formatTaskNameString -f $taskName
$script:context.Peek().formatTaskNameString -f $taskName
& $task.Action
if ($task.PostAction -ne $null)
@@ -114,9 +104,9 @@ function ExecuteTask
& $task.PostAction
}
if ($script:taskTearDownScriptBlock -ne $null)
if ($script:context.Peek().taskTearDownScriptBlock -ne $null)
{
& $script:taskTearDownScriptBlock
& $script:context.Peek().taskTearDownScriptBlock
}
}
catch
@@ -126,7 +116,6 @@ function ExecuteTask
"-"*70
"Error in Task [$taskName] $_"
"-"*70
continue
}
else
{
@@ -159,11 +148,11 @@ function ExecuteTask
}
}
$poppedTaskKey = $script:callStack.Pop()
$poppedTaskKey = $script:context.Peek().callStack.Pop()
Assert ($poppedTaskKey -eq $taskKey) "Error: CallStack was corrupt. Expected $taskKey, but got $poppedTaskKey."
$script:executedTasks.Push($taskKey)
$script:context.Peek().executedTasks.Push($taskKey)
}
function Configure-BuildEnvironment
@@ -190,9 +179,9 @@ function Configure-BuildEnvironment
function Cleanup-Environment
{
$env:path = $script:originalEnvPath
Set-Location $script:originalDirectory
$global:ErrorActionPreference = $originalErrorActionPreference
$env:path = $script:context.Peek().originalEnvPath
Set-Location $script:context.Peek().originalDirectory
$global:ErrorActionPreference = $script:context.Peek().originalErrorActionPreference
}
#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
@@ -217,13 +206,13 @@ function Resolve-Error($ErrorRecord=$Error[0])
function Write-Documentation
{
$list = New-Object System.Collections.ArrayList
foreach($key in $script:tasks.Keys)
foreach($key in $script:context.Peek().tasks.Keys)
{
if($key -eq "default")
{
continue
}
$task = $script:tasks.$key
$task = $script:context.Peek().tasks.$key
$content = "" | Select-Object Name, Description
$content.Name = $task.Name
$content.Description = $task.Description
@@ -239,10 +228,10 @@ function Write-TaskTimeSummary
"Build Time Report"
"-"*70
$list = @()
while ($script:executedTasks.Count -gt 0)
while ($script:context.Peek().executedTasks.Count -gt 0)
{
$taskKey = $script:executedTasks.Pop()
$task = $script:tasks.$taskKey
$taskKey = $script:context.Peek().executedTasks.Pop()
$task = $script:context.Peek().tasks.$taskKey
if($taskKey -eq "default")
{
continue
@@ -524,9 +513,9 @@ Assert
$taskKey = $name.ToLower()
Assert (!$script:tasks.ContainsKey($taskKey)) "Error: Task, $name, has already been defined."
Assert (!$script:context.Peek().tasks.ContainsKey($taskKey)) "Error: Task, $name, has already been defined."
$script:tasks.$taskKey = $newTask
$script:context.Peek().tasks.$taskKey = $newTask
}
function Properties
@@ -583,7 +572,7 @@ You can have more than 1 "Properties" function defined in the script
[Parameter(Position=0,Mandatory=1)]
[scriptblock]$properties
)
$script:properties += $properties
$script:context.Peek().properties += $properties
}
function Include
@@ -640,7 +629,7 @@ You can have more than 1 "Include" function defined in the script
[string]$fileNamePathToInclude
)
Assert (test-path $fileNamePathToInclude) "Error: Unable to include $fileNamePathToInclude. File not found."
$script:includes.Enqueue((Resolve-Path $fileNamePathToInclude));
$script:context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
}
function FormatTaskName
@@ -712,7 +701,7 @@ Assert
[Parameter(Position=0,Mandatory=1)]
[string]$format
)
$script:formatTaskNameString = $format
$script:context.Peek().formatTaskNameString = $format
}
function TaskSetup
@@ -744,7 +733,7 @@ Task Clean {
}
TaskSetup {
"Running 'TaskSetup' for task $script:currentTaskName"
"Running 'TaskSetup' for task $script:context.Peek().currentTaskName"
}
You should get the following output:
@@ -787,7 +776,7 @@ Assert
[Parameter(Position=0,Mandatory=1)]
[scriptblock]$setup
)
$script:taskSetupScriptBlock = $setup
$script:context.Peek().taskSetupScriptBlock = $setup
}
function TaskTearDown
@@ -819,7 +808,7 @@ Task Clean {
}
TaskTearDown {
"Running 'TaskTearDown' for task $script:currentTaskName"
"Running 'TaskTearDown' for task $script:context.Peek().currentTaskName"
}
You should get the following output:
@@ -861,7 +850,7 @@ Assert
param(
[Parameter(Position=0,Mandatory=1)]
[scriptblock]$teardown)
$script:taskTearDownScriptBlock = $teardown
$script:context.Peek().taskTearDownScriptBlock = $teardown
}
function Invoke-psake
@@ -886,6 +875,9 @@ Default = '3.5'
.PARAMETER Docs
Prints a list of tasks and their descriptions
.PARAMETER Parameters
A hashtable containing parameters to be passed into the current build script.
.EXAMPLE
Invoke-psake
@@ -906,6 +898,11 @@ Runs the 'Tests' and 'Package' tasks in the '.build.ps1' build script
Invoke-psake '.\build.ps1' -docs
Prints a report of all the tasks and their descriptions and exits
.EXAMPLE
Invoke-psake .\parameters.ps1 -parameters @{"p1"="v1";"p2"="v2"}
Runs the build script called 'parameters.ps1' and passes in parameters 'p1' and 'p2' with values 'v1' and 'v2'
.OUTPUTS
If there is an exception and '$psake.use_exit_on_error' -eq $true
@@ -996,26 +993,35 @@ Assert
[Parameter(Position=2,Mandatory=0)]
[string]$framework = '3.5',
[Parameter(Position=3,Mandatory=0)]
[switch]$docs = $false
[switch]$docs = $false,
[Parameter(Position=4,Mandatory=0)]
[System.Collections.Hashtable]$parameters = @{}
)
Begin
{
$script:psake.build_success = $false
$script:psake.framework_version = $framework
$script:formatTaskNameString = "Executing task: {0}"
$script:taskSetupScriptBlock = $null
$script:taskTearDownScriptBlock = $null
$script:executedTasks = New-Object System.Collections.Stack
$script:callStack = New-Object System.Collections.Stack
$script:originalEnvPath = $env:path
$script:originalDirectory = Get-Location
$originalErrorActionPreference = $global:ErrorActionPreference
$script:psake.build_success = $false
$script:psake.framework_version = $framework
$script:tasks = @{}
$script:properties = @()
$script:includes = New-Object System.Collections.Queue
if ($script:context -eq $null)
{
$script:context = New-Object System.Collections.Stack
}
$script:context.push(@{
"formatTaskNameString" = "Executing task: {0}";
"taskSetupScriptBlock" = $null;
"taskTearDownScriptBlock" = $null;
"executedTasks" = New-Object System.Collections.Stack;
"callStack" = New-Object System.Collections.Stack;
"originalEnvPath" = $env:path;
"originalDirectory" = Get-Location;
"originalErrorActionPreference" = $global:ErrorActionPreference;
"tasks" = @{};
"properties" = @();
"includes" = New-Object System.Collections.Queue ;
})
}
Process
@@ -1042,15 +1048,27 @@ Assert
# N.B. The initial dot (.) indicates that variables initialized/modified
# in the propertyBlock are available in the parent scope.
while ($script:includes.Count -gt 0)
while ($script:context.Peek().includes.Count -gt 0)
{
$includeBlock = $script:includes.Dequeue()
$includeBlock = $script:context.Peek().includes.Dequeue()
. $includeBlock
}
foreach($propertyBlock in $script:properties)
foreach($propertyBlock in $script:context.Peek().properties)
{
. $propertyBlock
}
foreach($key in $parameters.keys)
{
if (test-path "variable:\$key")
{
set-item -path "variable:\$key" -value $parameters.$key
}
else
{
new-item -path "variable:\$key" -value $parameters.$key
}
}
# Execute the list of tasks or the default task
if($taskList.Length -ne 0)
@@ -1060,7 +1078,7 @@ Assert
ExecuteTask $task
}
}
elseif ($script:tasks.default -ne $null)
elseif ($script:context.Peek().tasks.default -ne $null)
{
ExecuteTask default
}
@@ -1108,6 +1126,7 @@ Assert
{
# Clear out any global variables
Cleanup-Environment
[void]$script:context.Pop()
}
}