-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.ps1
227 lines (167 loc) · 6.89 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
Framework "4.6"
properties {
$projectName = "NSB-Webinar"
$base_dir = resolve-path .\
$source_dir = "$base_dir\src"
$unitTestAssembly = "Order.UnitTests.dll"
$projectConfig = $env:Configuration
$version = $env:Version
$nunitPath = Resolve-Path("$source_dir\packages\NUnit.Console*\Tools")
$specflowPath = Resolve-Path("$source_dir\packages\SpecFlow*\tools")
$teamcityoutput = ""
$build_dir = "$base_dir\build"
$test_dir = "$build_dir\test"
$testCopyIgnorePath = "_ReSharper"
$package_dir = "$build_dir\package"
$package_file = "$build_dir\latestVersion\" + $projectName +"_Package.zip"
$runOctoPack = $env:RunOctoPack
$databaseName = $projectName
$databaseServer = "localhost\SQLEXPRESS"
$databaseScripts = "$source_dir\Database\scripts"
$hibernateConfig = "$source_dir\hibernate.cfg.xml"
$schemaDatabaseName = $databaseName + "_schema"
$integratedSecurity = "Integrated Security=true"
$connection_string = "server=$databaseserver;database=$databasename;$databaseUser;"
$AliaSql = "$source_dir\Database\scripts\AliaSql.exe"
$webapp_dir = "$source_dir\UI"
if([string]::IsNullOrEmpty($version)) { $version = "1.0.0"}
if([string]::IsNullOrEmpty($projectConfig)) {$projectConfig = "Release"}
if([string]::IsNullOrEmpty($runOctoPack)) {$runOctoPack = "true"}
}
task ? -Description "Shows the description of all tasks"{
WriteDocumentation
}
task default -depends ?
task ci -depends CiInit, Init, CommonAssemblyInfo, ConnectionString, Compile, RebuildDatabase, Test
task CiInit {
$script:teamcityoutput = "--teamcity"
}
task Init {
delete_file $package_file
delete_directory $build_dir
create_directory $test_dir
create_directory $build_dir
}
task ConnectionString {
$connection_string = "server=$databaseserver;database=$databasename;$integratedSecurity;"
write-host "Using connection string: $connection_string"
if ( Test-Path "$hibernateConfig" ) {
poke-xml $hibernateConfig "//e:property[@name = 'connection.connection_string']" $connection_string @{"e" = "urn:nhibernate-configuration-2.2"}
}
}
task Compile -depends Init {
exec {
& msbuild /t:Clean`;Rebuild /v:q /nologo /p:Configuration=$projectConfig /p:OctoPackPackageVersion=$version /p:RunOctoPack=$runOctoPack /p:OctoPackEnforceAddingFiles=true $source_dir\$projectName.sln
}
Copy_and_flatten $source_dir *.nupkg $build_dir
}
task Test -depends Compile, RebuildDatabase {
copy_all_assemblies_for_test $test_dir
exec {
& $nunitPath\nunit3-console.exe $test_dir\$unitTestAssembly $script:teamcityoutput --workers=1 --noheader --result="$build_dir\TestResult.xml"`;format=nunit2
}
}
task RebuildDatabase -depends ConnectionString {
exec {
& $AliaSql Rebuild $databaseServer $databaseName $databaseScripts
}
}
task CreateCompareSchema -depends SchemaConnectionString {
exec {
& $AliaSql Rebuild $databaseServer $schemaDatabaseName $databaseScripts
}
}
task SchemaConnectionString {
$connection_string = "server=$databaseserver;database=$schemaDatabaseName;@integratedSecurity;"
write-host "Using connection string: $connection_string"
}
task CommonAssemblyInfo {
create-commonAssemblyInfo "$version" $projectName "$source_dir\CommonAssemblyInfo.cs"
}
function global:zip_directory($directory,$file) {
write-host "Zipping folder: " $test_assembly
write-host "Zipping directory: " $directory
write-host "Zipping file: " $file
write-host "Base: " $base_dir
delete_file $file
cd $directory
& "$base_dir\tools\7zip\7z.exe" a -mx=9 -r $file
cd $base_dir
}
function global:copy_website_files($source,$destination){
$exclude = @('*.user','*.dtd','*.tt','*.cs','*.csproj','*.orig', '*.log')
copy_files $source $destination $exclude
delete_directory "$destination\obj"
}
function global:copy_files($source,$destination,$exclude=@()){
create_directory $destination
Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
}
function global:Copy_and_flatten ($source,$filter,$dest) {
ls $source -filter $filter -r | Where-Object{!$_.FullName.Contains("$testCopyIgnorePath") -and !$_.FullName.Contains("packages") }| cp -dest $dest -force
}
function global:copy_all_assemblies_for_test($destination){
create_directory $destination
Copy_and_flatten $source_dir *.exe $destination
Copy_and_flatten $source_dir *.dll $destination
Copy_and_flatten $source_dir *.config $destination
Copy_and_flatten $source_dir *.xml $destination
Copy_and_flatten $source_dir *.pdb $destination
Copy_and_flatten $source_dir *.sql $destination
Copy_and_flatten $source_dir *.xlsx $destination
}
function global:delete_file($file) {
if($file) { remove-item $file -force -ErrorAction SilentlyContinue | out-null }
}
function global:delete_directory($directory_name)
{
rd $directory_name -recurse -force -ErrorAction SilentlyContinue | out-null
}
function global:delete_files_in_dir($dir)
{
get-childitem $dir -recurse | foreach ($_) {remove-item $_.fullname}
}
function global:create_directory($directory_name)
{
mkdir $directory_name -ErrorAction SilentlyContinue | out-null
}
function global:create-commonAssemblyInfo($version,$applicationName,$filename)
{
"using System;
using System.Reflection;
using System.Runtime.InteropServices;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: ComVisibleAttribute(false)]
[assembly: AssemblyVersionAttribute(""$version"")]
[assembly: AssemblyFileVersionAttribute(""$version"")]
[assembly: AssemblyCopyrightAttribute(""Copyright 2015"")]
[assembly: AssemblyProductAttribute(""$applicationName"")]
[assembly: AssemblyCompanyAttribute(""Clear Measure, Inc."")]
[assembly: AssemblyConfigurationAttribute(""$projectConfig"")]
[assembly: AssemblyInformationalVersionAttribute(""$version"")]" | out-file $filename -encoding "ASCII"
}
function script:poke-xml($filePath, $xpath, $value, $namespaces = @{}) {
[xml] $fileXml = Get-Content $filePath
if($namespaces -ne $null -and $namespaces.Count -gt 0) {
$ns = New-Object Xml.XmlNamespaceManager $fileXml.NameTable
$namespaces.GetEnumerator() | %{ $ns.AddNamespace($_.Key,$_.Value) }
$node = $fileXml.SelectSingleNode($xpath,$ns)
} else {
$node = $fileXml.SelectSingleNode($xpath)
}
Assert ($node -ne $null) "could not find node @ $xpath"
if($node.NodeType -eq "Element") {
$node.InnerText = $value
} else {
$node.Value = $value
}
$fileXml.Save($filePath)
}