forked from mmanela/chutzpah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.ps1
278 lines (213 loc) · 9.67 KB
/
default.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
properties {
$baseDir = Resolve-Path .
$configuration = "debug"
$xUnit = Resolve-Path .\3rdParty\XUnit\xunit.console.clr4.exe
$filesDir = "$baseDir\_build"
$nugetDir = "$baseDir\_nuget"
$chocolateyDir = "$baseDir\_chocolatey"
$packageDir = "$baseDir\_package"
}
# Aliases
task Default -depends Build
task Package -depends Clean-Solution-VS,Clean-PackageFiles, Set-Version, Update-VersionInFiles, Build-Solution-VS, Package-Files, Package-NuGet, Package-Chocolatey
task Clean -depends Clean-Solution-NoVS
task TeamCity -depends Clean-TeamCitySolution, Build-TeamCitySolution, Run-UnitTests, Run-IntegrationTests
# Build Tasks
task Build -depends Clean-Solution-NoVS, Build-Solution-NoVS, Run-UnitTests, Run-IntegrationTests
task Build-Full -depends Clean-Solution-VS, Build-Solution-VS, Run-UnitTests, Run-IntegrationTests
task Set-Version {
if($arg1) {
$v = $arg1
$global:version = $v + ".0"
if($arg2) {
$global:isBeta = $true
}
}
else {
$vtag = git describe --abbrev=0 --tags
$v = $vtag.substring(1)
$global:version = $v + '.' + (git log $($vtag + '..') --pretty=oneline | measure-object).Count
}
$global:versionPart = $v
}
task Update-VersionInFiles {
if($arg1) {
$v = $arg1
$commit = git log -1 --pretty=format:%H
}
else {
$vtag = git describe --abbrev=0 --tags
$v = $vtag.substring(1)
$commit = git log -1 $($vtag + '..') --pretty=format:%H
}
Update-AssemblyInfoFiles $global:version $commit
Update-OtherFiles $global:versionPart
}
task Run-Chutzpah -depends Build-Solution {
exec { & .\ConsoleRunner\bin\$configuration\chutzpah.console.exe ConsoleRunner\JS\test.html /file ConsoleRunner\JS\tests.js}
}
task Clean-PackageFiles {
clean $nugetDir
clean $filesDir
clean $packageDir
}
# CodeBetter TeamCity does not have VS SDK installed so we use a custom solution that does not build the
# VS components
task Clean-TeamCitySolution {
exec { msbuild TeamCity.CodeBetter.sln /t:Clean /v:quiet }
}
task Clean-Solution-VS {
exec { msbuild Chutzpah.VS2013.sln /t:Clean /v:quiet }
}
task Clean-Solution-NoVS {
exec { msbuild Chutzpah.NoVS.sln /t:Clean /v:quiet }
}
# CodeBetter TeamCity does not have VS SDK installed so we use a custom solution that does not build the
# VS components
task Build-TeamCitySolution {
exec { msbuild TeamCity.CodeBetter.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}
task Build-Solution-VS {
exec { msbuild Chutzpah.VS2013.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}
task Build-Solution-NoVS {
exec { msbuild Chutzpah.NoVS.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}
task Run-PerfTester {
$result = & "PerfTester\bin\$configuration\chutzpah.perftester.exe"
Write-Output $result
$result | Out-File "perf_results.txt" -Encoding ASCII
}
task Run-UnitTests {
exec { & $xUnit "Facts\bin\$configuration\Facts.Chutzpah.dll" }
}
task Run-IntegrationTests {
exec { & $xUnit "Facts.Integration\bin\$configuration\Facts.Integration.Chutzpah.dll" }
}
task Run-Phantom {
$testFilePath = Resolve-Path $arg1;
$type = $arg2;
$mode = $arg3;
if(-not $type){
$type = "qunit";
}
if($type -eq "jasmine") {
$suffix = "V2"
}
$phantom = "3rdParty\Phantom\phantomjs.exe";
$testFilePath = $testFilePath.Path.Replace("\","/");
exec { & $phantom "Chutzpah\JSRunners\$($type)Runner$suffix.js" "file:///$testFilePath" $mode }
}
task Package-Files -depends Clean-PackageFiles {
create $filesDir, $packageDir
copy-item "$baseDir\License.txt" -destination $filesDir
copy-item "$baseDir\3rdParty\ServiceStack\LICENSE.BSD" -destination $filesDir\ServiceStack.LICENSE.BSD
roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $filesDir /S /xd JS /xf *.xml}
# Copy Adapter files to package zip
copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS.Common.*" -destination $filesDir
copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS2012.TestAdapter.*" -destination $filesDir
cd $filesDir
exec { &"$baseDir\3rdParty\Zip\zip.exe" -r -9 "$packageDir\Chutzpah.$($global:versionPart).zip" *.* }
cd $baseDir
# Copy over Vsix Files
copy-item "$baseDir\VisualStudioContextMenu\bin\$configuration\Chutzpah.VisualStudioContextMenu.vsix" -destination $packageDir
copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS2012.vsix" -destination $packageDir
}
task Package-NuGet -depends Clean-PackageFiles, Set-Version {
$nugetTools = "$nugetDir\tools"
$nuspec = "$baseDir\Chutzpah.nuspec"
create $nugetDir, $nugetTools, $packageDir
copy-item "$baseDir\License.txt", $nuspec -destination $nugetDir
copy-item "$baseDir\3rdParty\ServiceStack\LICENSE.BSD" -destination $nugetDir\ServiceStack.LICENSE.BSD
roboexec {robocopy "$baseDir\ConsoleRunner\bin\$configuration\" $nugetTools /S /xd JS /xf *.xml}
# Copy Adapter files to nuget zip
copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS.Common.*" -destination $nugetTools
copy-item "$baseDir\VS2012\bin\$configuration\Chutzpah.VS2012.TestAdapter.*" -destination $nugetTools
$v = new-object -TypeName System.Version -ArgumentList $global:version
$vStr = $v.ToString(3)
if($global:isBeta) {
$vStr += "-beta"
}
regex-replace "$nugetDir\Chutzpah.nuspec" '(?m)@Version@' $vStr
exec { .\Tools\nuget.exe pack "$nugetDir\Chutzpah.nuspec" -o $packageDir }
}
task Push-Public -depends Push-Nuget, Push-Chocolatey
task Package-Chocolatey -depends Clean-PackageFiles, Set-Version {
$nuspec = "$baseDir\Chutzpah.nuspec"
$chocolateyInstall = "$baseDir\chocolateyInstall.ps1"
create $chocolateyDir, $packageDir
copy-item $chocolateyInstall, $nuspec -destination $chocolateyDir
$v = new-object -TypeName System.Version -ArgumentList $global:version
regex-replace "$chocolateyDir\chocolateyInstall.ps1" '(?m)@Version@' $v.ToString(3)
push-location $chocolateyDir
$v = new-object -TypeName System.Version -ArgumentList $global:version
regex-replace "$chocolateyDir\Chutzpah.nuspec" '(?m)@Version@' $v.ToString(3)
exec { cpack "$chocolateyDir\Chutzpah.nuspec" }
pop-location
}
task Push-Nuget -depends Set-Version {
$v = new-object -TypeName System.Version -ArgumentList $global:version
exec { .\Tools\nuget.exe push $packageDir\Chutzpah.$($v.ToString(3)).nupkg }
}
task Push-Chocolatey -depends Set-Version {
$v = new-object -TypeName System.Version -ArgumentList $global:version
exec { chocolatey push $chocolateyDir\Chutzpah.$($v.ToString(3)).nupkg }
}
# Help
task ? -Description "Help information" {
Write-Documentation
}
function create([string[]]$paths) {
foreach ($path in $paths) {
if(-not (Test-Path $path)) {
new-item -path $path -type directory | out-null
}
}
}
function regex-replace($filePath, $find, $replacement) {
$regex = [regex] $find
$content = [System.IO.File]::ReadAllText($filePath)
Assert $regex.IsMatch($content) "Unable to find the regex '$find' to update the file '$filePath'"
[System.IO.File]::WriteAllText($filePath, $regex.Replace($content, $replacement))
}
function clean([string[]]$paths) {
foreach ($path in $paths) {
remove-item -force -recurse $path -ErrorAction SilentlyContinue
}
}
function roboexec([scriptblock]$cmd) {
& $cmd | out-null
if ($lastexitcode -eq 0) { throw "No files were copied for command: " + $cmd }
}
# 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 = 'AssemblyTrademark\("[a-f0-9]*"\)'
$assemblyVersion = 'AssemblyVersion("' + $version + '")';
$fileVersion = 'AssemblyFileVersion("' + $version + '")';
$commitVersion = 'AssemblyTrademark("' + $commit + '")';
echo "Setting version: $version and commit:$commit"
Get-ChildItem -path $baseDir -r -filter AssemblyInfo.cs | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion } |
% {$_ -replace $fileCommitPattern, $commitVersion }
} | Set-Content $filename
}
}
function Update-OtherFiles ([string] $version) {
$chutzpahVersionPattern = 'public const string ChutzpahVersion = "(([0-9]\.?)*?)"'
$chutzpahVersion = 'public const string ChutzpahVersion = "'+$version+'"'
$contantsFile = Join-Path $baseDir "Chutzpah\Constants.cs"
(Get-Content $contantsFile) | ForEach-Object { $_ -replace $chutzpahVersionPattern, $chutzpahVersion } | Set-Content $contantsFile
$manifestFile = Join-Path $baseDir "VS2012\source.extension.vsixmanifest"
$manifest = [xml](Get-Content $manifestFile)
$manifest.PackageManifest.Metadata.Identity.Version = $version
$manifest.Save($manifestFile)
$manifestFile = Join-Path $baseDir "VisualStudioContextMenu\source.extension.vsixmanifest"
$manifest = [xml](Get-Content $manifestFile)
$manifest.PackageManifest.Metadata.Identity.Version = $version
$manifest.Save($manifestFile)
}