-
Notifications
You must be signed in to change notification settings - Fork 48
/
BuildScript.ps1
296 lines (258 loc) · 14.7 KB
/
BuildScript.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
$psake.use_exit_on_error = $true
properties {
$currentDir = resolve-path .
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
$baseDir = Split-Path -parent $Invocation.MyCommand.Definition | split-path -parent | split-path -parent | split-path -parent
echo $baseDir
$port = "8877"
$configuration = "debug"
# Package Directories
$webDir = (get-childitem (split-path c:\requestreduce) -filter mwrock.github.com).fullname
$filesDir = "$baseDir\BuildFiles"
$version = git describe --abbrev=0 --tags
$version = $version.substring(1) + '.' + (git log $($version + '..') --pretty=oneline | measure-object).Count
$projectFiles = "$baseDir\RequestReduce\RequestReduce.csproj"
$nugetDir = "$baseDir\.NuGet"
}
task Test-Solution -depends Unit-Tests, Integration-Tests
task Debug -depends Default
task Default -depends Clean-Solution, Setup-IIS, Build-35-Solution, Build-Solution, Test-Solution
task Download -depends Pull-Repo, Pull-Web, Clean-Solution, Update-AssemblyInfoFiles, Build-Output, Push-Repo, Update-Website-Download-Links, Push-Web
task private-download -depends Pull-Repo, Clean-Solution, Update-AssemblyInfoFiles, Build-Output, Push-Repo
task Push-Nuget-All -depends Push-Nuget-Core, Push-Nuget-SqlServer, Push-Nuget-SassLessCoffee
task Setup-IIS {
Setup-IIS "RequestReduce" $baseDir $port
}
task Clean-Solution -depends Clean-BuildFiles {
$conf = $configuration+35
clean $baseDir\RequestReduce\Nuget\Lib
create $baseDir\RequestReduce\Nuget\Lib
exec { msbuild RequestReduce.sln /t:Clean /v:quiet }
exec { msbuild 'RequestReduce\RequestReduce.csproj' /t:Clean /v:quiet /p:Configuration=$conf }
exec { msbuild 'RequestReduce.SqlServer\RequestReduce.SqlServer.csproj' /t:Clean /v:quiet /p:Configuration=$conf }
}
task echo-path {
write-host "dir:" $webDir
}
task Update-AssemblyInfoFiles {
$v = git describe --abbrev=0 --tags
$commit = git log -1 $($v + '..') --pretty=format:%H
Update-AssemblyInfoFiles $version $commit
}
task create-WebProject-build-target {
create $env:MSBuildExtensionsPath32\Microsoft\VisualStudio\v10.0
Copy-Item $baseDir\Microsoft.WebApplication.targets $env:MSBuildExtensionsPath32\Microsoft\VisualStudio\v10.0\Microsoft.WebApplication.targets
}
task Build-35-Solution {
$conf = $configuration+35
exec { msbuild 'RequestReduce\RequestReduce.csproj' /maxcpucount /t:Build /v:Minimal /p:Configuration=$conf }
exec { msbuild 'RequestReduce.SqlServer\RequestReduce.SqlServer.csproj' /maxcpucount /t:Build /v:Minimal /p:Configuration=$conf }
}
task Build-Solution {
exec { msbuild RequestReduce.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}
task Clean-BuildFiles -depends create-WebProject-build-target {
clean $filesDir
}
task Pull-Web {
cd $webDir
exec {git pull }
cd $currentDir
}
task Pull-Repo {
exec {git pull }
}
task Push-Web {
$message="deploying $version"
cd $webDir
exec { git add . }
exec { git commit -a -m $message }
exec { git push }
cd $currentDir
}
task Push-Repo {
$message="deploying $version"
exec { git add . }
exec { git commit -a -m $message }
exec { git push }
}
task Push-Nuget-Core {
$pkg = Get-Item -path $filesDir/RequestReduce.1.*.*.nupkg
exec { .$nugetDir\nuget.exe push $filesDir\$($pkg.Name) }
}
task Push-Nuget-SqlServer {
$pkg = Get-Item -path $filesDir/RequestReduce.SqlServer.*.*.*.nupkg
exec { .$nugetDir\nuget.exe push $filesDir\$($pkg.Name) }
}
task Push-Nuget-SassLessCoffee {
$pkg = Get-Item -path $filesDir/RequestReduce.SassLessCoffee.*.*.*.nupkg
exec { .$nugetDir\nuget.exe push $filesDir\$($pkg.Name) }
}
task Merge-35-Assembly -depends Build-35-Solution {
clean $baseDir\RequestReduce\Nuget\Lib\net20
clean $baseDir\RequestReduce.SqlServer\Nuget\Lib\net20
create $baseDir\RequestReduce\Nuget\Lib\net20
create $baseDir\RequestReduce.SqlServer\Nuget\Lib\net20
if ($env:PROCESSOR_ARCHITECTURE -eq "x64") {$bitness = "64"}
exec { .\Tools\ilmerge.exe /t:library /internalize /targetplatform:"v2,$env:windir\Microsoft.NET\Framework$bitness\v2.0.50727" /wildcards /out:$baseDir\RequestReduce\Nuget\Lib\net20\RequestReduce.dll "$baseDir\RequestReduce\bin\v3.5\$configuration\RequestReduce.dll" "$baseDir\RequestReduce\bin\v3.5\$configuration\AjaxMin.dll" "$baseDir\RequestReduce\bin\v3.5\$configuration\StructureMap.dll" "$baseDir\RequestReduce\bin\v3.5\$configuration\nquant.core.dll" }
}
task Merge-40-Assembly -depends Build-Solution {
clean $baseDir\RequestReduce\Nuget\Lib\net40
clean $baseDir\RequestReduce.SqlServer\Nuget\Lib\net40
clean $baseDir\RequestReduce.SassLessCoffee\Nuget\Lib\net40
create $baseDir\RequestReduce\Nuget\Lib\net40
create $baseDir\RequestReduce.SqlServer\Nuget\Lib\net40
create $baseDir\RequestReduce.SassLessCoffee\Nuget\Lib\net40
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") {
if( Test-Path "${env:ProgramFiles(x86)}\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" ) {
exec { .\Tools\ilmerge.exe /t:library /internalize /targetplatform:"v4,${env:ProgramFiles(x86)}\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /wildcards /out:$baseDir\RequestReduce\Nuget\Lib\net40\RequestReduce.dll "$baseDir\RequestReduce\bin\v4.0\$configuration\RequestReduce.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\AjaxMin.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\StructureMap.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\nquant.core.dll" }
}
else {
exec { .\Tools\ilmerge.exe /t:library /internalize /targetplatform:"v4,$env:windir\Microsoft.NET\Framework64\v4.0.30319" /wildcards /out:$baseDir\RequestReduce\Nuget\Lib\net40\RequestReduce.dll "$baseDir\RequestReduce\bin\v4.0\$configuration\RequestReduce.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\AjaxMin.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\StructureMap.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\nquant.core.dll" }
}
}
else {
if( Test-Path "$env:ProgramFiles\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" ) {
exec { .\Tools\ilmerge.exe /t:library /internalize /targetplatform:"v4,$env:ProgramFiles\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /wildcards /out:$baseDir\RequestReduce\Nuget\Lib\net40\RequestReduce.dll "$baseDir\RequestReduce\bin\v4.0\$configuration\RequestReduce.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\AjaxMin.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\StructureMap.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\nquant.core.dll" }
}
else {
exec { .\Tools\ilmerge.exe /t:library /internalize /targetplatform:"v4,$env:windir\Microsoft.NET\Framework\v4.0.30319" /wildcards /out:$baseDir\RequestReduce\Nuget\Lib\net40\RequestReduce.dll "$baseDir\RequestReduce\bin\v4.0\$configuration\RequestReduce.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\AjaxMin.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\StructureMap.dll" "$baseDir\RequestReduce\bin\v4.0\$configuration\nquant.core.dll" }
}
}
}
task Build-Output -depends Merge-35-Assembly, Merge-40-Assembly {
clean $filesDir
clean $baseDir\RequestReduce\Nuget\pngoptimization
create $baseDir\RequestReduce\Nuget\pngoptimization
Copy-Item $baseDir\RequestReduce.SqlServer\bin\v4.0\$configuration\RequestReduce.SqlServer.* $baseDir\RequestReduce.SqlServer\Nuget\lib\net40\
Copy-Item $baseDir\RequestReduce.SqlServer\bin\v3.5\$configuration\RequestReduce.SqlServer.* $baseDir\RequestReduce.SqlServer\Nuget\lib\net20\
Copy-Item $baseDir\RequestReduce.SassLessCoffee\bin\$configuration\RequestReduce.SassLessCoffee.* $baseDir\RequestReduce.SassLessCoffee\Nuget\lib\net40\
Copy-Item $baseDir\Readme.md $baseDir\RequestReduce\Nuget\readme.txt
Copy-Item $baseDir\ExternalBinaries\pngoptimization\*.* $baseDir\RequestReduce\Nuget\pngoptimization\
create $filesDir\net35
create $filesDir\net40
Copy-Item $baseDir\requestreduce\nuget\lib\net20\*.* $filesDir\net35
Copy-Item $baseDir\requestreduce\nuget\lib\net40\*.* $filesDir\net40
Copy-Item $baseDir\License.txt $filesDir
Copy-Item $baseDir\RequestReduce\Nuget\pngoptimization\*.txt $filesDir
Copy-Item $baseDir\Readme.md $filesDir\RequestReduce.readme.txt
Copy-Item $baseDir\RequestReduce\Nuget\pngoptimization\*.exe $filesDir\net35
Copy-Item $baseDir\RequestReduce\Nuget\pngoptimization\*.exe $filesDir\net40
create $filesDir\RequestReduce.SqlServer
create $filesDir\RequestReduce.SqlServer\net35
create $filesDir\RequestReduce.SqlServer\net40
Copy-Item $baseDir\requestreduce.SqlServer\nuget\lib\net20\*.* $filesDir\RequestReduce.SqlServer\net35
Copy-Item $baseDir\requestreduce.SqlServer\nuget\lib\net40\*.* $filesDir\RequestReduce.SqlServer\net40
Copy-Item $baseDir\requestreduce.SqlServer\nuget\tools\*.* $filesDir\RequestReduce.SqlServer
create $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\dotless.core.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\IronRuby.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\Jurassic.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\Microsoft.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\SassAndCoffee.Core.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\bin\$configuration\V8Bridge.Interface.* $filesDir\RequestReduce.SassLessCoffee
Copy-Item $baseDir\requestreduce.SassLessCoffee\nuget\lib\net40\*.* $filesDir\RequestReduce.SassLessCoffee
cd $filesDir
exec { & $baseDir\Tools\zip.exe -9 -r RequestReduce-$version.zip . }
cd $currentDir
exec { .$nugetDir\nuget.exe pack "RequestReduce\Nuget\RequestReduce.nuspec" -o $filesDir -version $version }
exec { .$nugetDir\nuget.exe pack "RequestReduce.SqlServer\Nuget\RequestReduce.SqlServer.nuspec" -o $filesDir -version $version }
exec { .$nugetDir\nuget.exe pack "RequestReduce.SassLessCoffee\Nuget\RequestReduce.SassLessCoffee.nuspec" -o $filesDir -version $version }
}
task Update-Website-Download-Links {
Copy-Item $filesDir\RequestReduce-$version.zip $webDir
$downloadUrl="RequestReduce-" + $version + ".zip"
$downloadButtonUrlPatern="RequestReduce-[0-9]+(\.([0-9]+|\*)){1,3}\.zip"
$downloadLinkTextPattern="V[0-9]+(\.([0-9]+|\*)){1,3}"
$filename = "$webDir\index.html"
(Get-Content $filename) | % {$_ -replace $downloadButtonUrlPatern, $downloadUrl } | % {$_ -replace $downloadLinkTextPattern, ("v"+$version) } | Set-Content $filename
}
task Unit-Tests -depends Build-Solution {
$runnerDir = ([array](dir $currentDir\packages\xunit.runners.*))[-1];
exec { .$runnerDir\tools\xunit.console.clr4.exe "RequestReduce.Facts\bin\$configuration\RequestReduce.Facts.dll" }
}
task Integration-Tests -depends Build-Solution {
$runnerDir = ([array](dir $currentDir\packages\xunit.runners.*))[-1];
exec {.$runnerDir\tools\xunit.console.clr4.exe "RequestReduce.Facts.Integration\bin\$configuration\RequestReduce.Facts.Integration.dll" /-trait "type=manual_adhoc" }
}
function roboexec([scriptblock]$cmd) {
& $cmd | out-null
if ($lastexitcode -eq 0) { throw "No files were copied for command: " + $cmd }
}
function clean($path) {
remove-item -force -recurse $path -ErrorAction SilentlyContinue
}
function create([string[]]$paths) {
foreach ($path in $paths) {
if ((test-path $path) -eq $FALSE) {
new-item -path $path -type directory | out-null
}
}
}
function Load-IISProvider {
$module = Get-Module | Where-Object {$_.Name -eq "WebAdministration"}
if($module -eq $null) {
Import-Module WebAdministration
}
}
function Setup-IIS([string] $siteName, [string] $solutionDir, [string] $port )
{
try
{
Load-IISProvider
# cleanup
echo "looking for $siteName website"
if(Test-Path IIS:\Sites\$siteName)
{
return
}
echo "Setting up $siteName website"
$siteName35 = $sitename+35
$websitePhysicalPath = $solutionDir + "\RequestReduce.SampleWeb"
# Create the site
$id = (Get-ChildItem IIS:\Sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
New-Website -Name $siteName -Port $port -PhysicalPath $websitePhysicalPath -Id $id
New-Website -Name $siteName35 -Port ([int]$port+1) -PhysicalPath ($websitePhysicalPath+35) -Id ($id+1)
# Create app pool and have it run under network service
$appPool = New-Item -Force IIS:\AppPools\$siteName
$appPool.processModel.identityType = "NetworkService"
$appPool.managedRuntimeVersion = "v4.0.30319"
$appPool | Set-Item
$appPool = New-Item -Force IIS:\AppPools\$siteName35
$appPool.processModel.identityType = "NetworkService"
$appPool.managedRuntimeVersion = "v2.0"
$appPool | Set-Item
# Set app pool
Set-ItemProperty IIS:\Sites\$siteName -name applicationPool -value $siteName
Set-ItemProperty IIS:\Sites\$siteName35 -name applicationPool -value $siteName35
New-WebApplication -Name styles\secure -Site $siteName -PhysicalPath $websitePhysicalPath\Styles\secure -ApplicationPool $siteName
#Start Site
Start-WebItem IIS:\Sites\$siteName
Start-WebItem IIS:\Sites\$siteName35
}
catch {
"Error in Setup-IIS: " + $_.Exception
}
}
# Borrowed from Luis Rocha's Blog (http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html)
function Update-AssemblyInfoFiles ([string] $version, [string] $commit) {
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileCommitPattern = 'AssemblyTrademarkAttribute\("([a-f0-9]{40})?"\)'
$assemblyVersion = 'AssemblyVersion("' + $version + '")';
$fileVersion = 'AssemblyFileVersion("' + $version + '")';
$commitVersion = 'AssemblyTrademarkAttribute("' + $commit + '")';
Get-ChildItem -path $baseDir -r -filter GlobalAssemblyInfo.cs | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
$filename + ' -> ' + $version
# If you are using a source control that requires to check-out files before
# modifying them, make sure to check-out the file here.
# For example, TFS will require the following command:
# tf checkout $filename
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion } |
% {$_ -replace $fileCommitPattern, $commitVersion }
} | Set-Content $filename
}
}