-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild-psake.ps1
233 lines (187 loc) · 9.19 KB
/
build-psake.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
properties {
$zipFileName = "HttpSecureCookie.zip"
$majorVersion = "0.1"
$majorWithReleaseVersion = "0.1.1"
$version = GetVersion $majorWithReleaseVersion
$signAssemblies = $false
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
$buildDocumentation = $false
$buildNuGet = $true
$treatWarningsAsErrors = $false
$baseDir = resolve-path "."
$buildDir = "$baseDir"
$sourceDir = "$baseDir\src"
$toolsDir = "$baseDir\_build-tools"
$testsDir = "$baseDir\_build_output\Testing"
$docDir = "$baseDir\Doc"
$workingDir = "$baseDir\_build_output\Working"
$builds = @(
@{Name = "HttpSecureCookie.vs2010"; TestsName = "HttpSecureCookie.Tests"; Constants=""; FinalDir="Net"; NuGetDir = "net"; Framework="net-4.0"; Sign=$false}
#@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true},
#@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net40+sl4+wp7+win8"; Framework="net-4.0"; Sign=$true},
#@{Name = "Newtonsoft.Json.WinRT"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="WinRT"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true},
#@{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "sl3-wp,sl4-windowsphone71"; Framework="net-4.0"; Sign=$true},
#@{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "sl4"; Framework="net-4.0"; Sign=$true},
#@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"; Sign=$true},
#@{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; Constants="NET20"; FinalDir="Net20"; NuGetDir = "net20"; Framework="net-2.0"; Sign=$true}
)
}
$framework = '4.0x86'
task default -depends Test
# Ensure a clean working directory
task Clean {
Set-Location $baseDir
if (Test-Path -path $workingDir)
{
Write-Output "Deleting Working Directory"
del $workingDir -Recurse -Force
}
if (Test-Path -path $testsDir)
{
Write-Output "Deleting Testing directory"
del $testsDir -Recurse -Force
}
}
# Build each solution, optionally signed
task Build -depends Clean,UpdateAssemblyInfoVersions {
New-Item -Path $workingDir -ItemType Directory
foreach ($build in $builds)
{
$name = $build.Name
$finalDir = $build.FinalDir
$sign = ($build.Sign -and $signAssemblies)
Write-Host -ForegroundColor Green "Building " $name
Write-Host -ForegroundColor Green "Signed " $sign
Write-Host
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:Platform=Any CPU" /p:OutputPath=$workingDir\bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$sign" "/p:TreatWarningsAsErrors=$treatWarningsAsErrors" (GetConstants $build.Constants $sign) ".\Src\$name.sln" | Out-Default } "Error building $name"
}
}
task UpdateAssemblyInfoVersions {
Write-Host -ForegroundColor Green "Updating assembly version"
Write-Host
Update-AssemblyInfoFiles $sourceDir ($majorVersion + '.0.0') $version
}
# Optional build documentation, add files to final zip
task Package -depends Test {
foreach ($build in $builds)
{
$name = $build.TestsName
$finalDir = $build.FinalDir
#robocopy "$sourceDir\Google.Maps\bin\Release\$finalDir" $workingDir\Package\Bin\$finalDir /NP /XO /XF *.pri | Out-Default
}
# if ($buildDocumentation)
# {
# $mainBuild = $builds | where { $_.Name -eq "Newtonsoft.Json" } | select -first 1
# $mainBuildFinalDir = $mainBuild.FinalDir
# $documentationSourcePath = "$workingDir\Package\Bin\$mainBuildFinalDir"
# Write-Host -ForegroundColor Green "Building documentation from $documentationSourcePath"
#
# # Sandcastle has issues when compiling with .NET 4 MSBuild - http://shfb.codeplex.com/Thread/View.aspx?ThreadId=50652
# exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:DocumentationSourcePath=$documentationSourcePath" $docDir\doc.shfbproj | Out-Default } "Error building documentation. Check that you have Sandcastle, Sandcastle Help File Builder and HTML Help Workshop installed."
#
# move -Path $workingDir\Documentation\LastBuild.log -Destination $workingDir\Documentation.log
# }
#
# Copy-Item -Path $docDir\readme.txt -Destination $workingDir\Package\
# Copy-Item -Path $docDir\versions.txt -Destination $workingDir\Package\Bin\
#
# robocopy $sourceDir $workingDir\Package\Source\Src /MIR /NP /XD .svn bin obj TestResults AppPackages /XF *.suo *.user | Out-Default
# robocopy $buildDir $workingDir\Package\Source\Build /MIR /NP /XD .svn | Out-Default
# robocopy $docDir $workingDir\Package\Source\Doc /MIR /NP /XD .svn | Out-Default
# robocopy $toolsDir $workingDir\Package\Source\Tools /MIR /NP /XD .svn | Out-Default
# exec { .\Tools\7-zip\7za.exe a -tzip $workingDir\$zipFileName $workingDir\Package\* | Out-Default } "Error zipping"
}
# Unzip package to a location
task Deploy -depends Package {
exec { .\Tools\7-zip\7za.exe x -y "-o$workingDir\Deployed" $workingDir\$zipFileName | Out-Default } "Error unzipping"
}
task UpdateNuspecVersion {
$versionNodePattern = "<version>[0-9]+(\.([0-9]+|\*)){1,3}</version>"
$versionOut = "<version>" + $majorWithReleaseVersion + "</version>"
Get-ChildItem -Path $baseDir *.nuspec | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
Write-Host "$filename -> $majorWithReleaseVersion"
(Get-Content $filename) | Foreach-Object {
% {$_ -replace $versionNodePattern, $versionOut }
} | Set-Content $filename
}
}
task NugetPackage -depends Test,UpdateNuspecVersion {
New-Item -Path $workingDir\NuGet -ItemType Directory
Copy-Item -Path "$baseDir\HttpSecureCookie.nuspec" -Destination "$workingDir\NuGet\HttpSecureCookie.nuspec" -recurse
foreach ($build in $builds)
{
if ($build.NuGetDir -ne $null)
{
$name = $build.TestsName
$finalDir = $build.FinalDir
$frameworkDirs = $build.NuGetDir.Split(",")
foreach ($frameworkDir in $frameworkDirs)
{
robocopy "$workingDir\bin\Release\$finalDir" $workingDir\NuGet\lib\$frameworkDir /NP /XO /XF *.pri | Out-Default
}
}
}
exec { .\_build-tools\NuGet.exe pack "$workingDir\NuGet\HttpSecureCookie.nuspec" -Symbols }
move -Path .\*.nupkg -Destination $workingDir\NuGet
Write-Host -ForegroundColor Magenta "Push nuget package to servers: .\nuget_push $majorWithReleaseVersion"
}
# Run tests on deployed files
#task Test -depends Deploy {
task Test -depends Build {
if ((Test-Path -path $testsDir) -eq $false)
{
New-Item -Path $testsDir -ItemType Directory
}
foreach ($build in $builds)
{
$name = $build.TestsName
if ($name -ne $null)
{
$finalDir = $build.FinalDir
$framework = $build.Framework
exec { msbuild /p:Configuration=Release /p:OutDir=$testsDir\bin\$finalDir\ $sourceDir\$name\$name.csproj }
Write-Host -ForegroundColor Green "Copying test assembly $name to deployed directory"
Write-Host
#robocopy ".\Src\Google.Maps\bin\Release\$finalDir" $workingDir\Deployed\Bin\$finalDir /MIR /NP /XO /XF LinqBridge.dll | Out-Default
#Copy-Item -Path "$testsDir\bin\$finalDir\*" -Destination $workingDir\Testing\Bin\$finalDir\
Write-Host -ForegroundColor Green "Running tests " $name
Write-Host
exec { .\_build-tools\NUnit.Runners\tools\nunit-console.exe "$testsDir\Bin\$finalDir\$name.dll" /labels /framework=$framework /xml:$workingDir\$name.xml | Out-Default } "Error running $name tests"
}
}
}
function GetConstants($constants, $includeSigned)
{
$signed = switch($includeSigned) { $true { ";SIGNED" } default { "" } }
return "/p:DefineConstants=`"CODE_ANALYSIS;TRACE;$constants$signed`""
}
function GetVersion($majorVersion)
{
$now = [DateTime]::Now
$year = $now.Year - 2000
$month = $now.Month
$totalMonthsSince2000 = ($year * 12) + $month
$day = $now.Day
$minor = "{0}{1:00}" -f $totalMonthsSince2000, $day
$hour = $now.Hour
$minute = $now.Minute
$revision = "{0:00}{1:00}" -f $hour, $minute
return $majorVersion + "." + $minor
}
function Update-AssemblyInfoFiles ([string] $sourceDir, [string] $assemblyVersionNumber, [string] $fileVersionNumber)
{
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$assemblyVersion = 'AssemblyVersion("' + $assemblyVersionNumber + '")';
$fileVersion = 'AssemblyFileVersion("' + $fileVersionNumber + '")';
Get-ChildItem -Path $sourceDir -r -filter AssemblyInfo.cs | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
Write-Host $filename
$filename + ' -> ' + $version
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion }
} | Set-Content $filename
}
}