forked from jonwagner/Insight.Database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.psake.ps1
230 lines (199 loc) · 9.23 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
$psake.use_exit_on_error = $true
#########################################
# to build a new version
# 1. git tag 1.0.x
# 2. build package
#########################################
properties {
$baseDir = $psake.build_script_dir
$version = git describe --abbrev=0 --tags
$changeset = (git log -1 $version --pretty=format:%H)
$assemblyversion = $version.Split('-', 2)[0]
$outputDir = "$baseDir\Build\Output"
$net35Path = "$baseDir\Insight.Database\bin\NET35"
$net40Path = "$baseDir\Insight.Database\bin\NET40"
$net45Path = "$baseDir\Insight.Database\bin\NET45"
$monoPath = "$baseDir\Insight.Database\bin\Mono"
$framework = "$env:systemroot\Microsoft.NET\Framework\v4.0.30319\"
$msbuild = $framework + "msbuild.exe"
$configuration = "Release"
$nuget = "nuget.exe"
$nunit = Get-ChildItem "$baseDir\packages" -Recurse -Include nunit-console.exe
$nunitx86 = Get-ChildItem "$baseDir\packages" -Recurse -Include nunit-console-x86.exe
}
Task default -depends Build
Task Build -depends Build45,Build40,Build35,BuildMono
Task Test -depends Test45,Test40,Test35
function Replace-Version {
param (
[string] $Path
)
(Get-Content $Path) |
% { $_ -replace "\[assembly: AssemblyFileVersion\(`"(\d+\.?)*`"\)\]","[assembly: AssemblyFileVersion(`"$assemblyversion`")]" } |
Set-Content $Path
}
function ReplaceVersions {
Get-ChildItem $baseDir -Include AssemblyInfo.cs -Recurse |% { Replace-Version $_.FullName }
}
function RestoreVersions {
Get-ChildItem $baseDir -Include AssemblyInfo.cs -Recurse |% {
git checkout $_.FullName
}
}
function Wipe-Folder {
param (
[string] $Path
)
if (Test-Path $Path) { Remove-Item $Path -Recurse }
New-Item -Path $Path -ItemType Directory | Out-Null
}
Task Build35 {
ReplaceVersions
try {
# build the NET35 binaries
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database\Insight.Database.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Configuration\Insight.Database.Configuration.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Providers.Default\Insight.Database.Providers.Default.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Compatibility3x\Insight.Database.Compatibility3x.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Providers.PostgreSQL\Insight.Database.Providers.PostgreSQL.NET35.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Tests\Insight.Tests.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Tests.Compatibility3x\Insight.Tests.Compatibility3x.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v3.5 /p:DefineConstants=```"NODBASYNC``;NODYNAMIC``;NET35```" '/t:Clean;Build'"
}
# copy the binaries to the net35 folder
Wipe-Folder $net35Path
Copy-Item $baseDir\Insight.Database\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Database.Configuration\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Database.Providers.Default\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Database.Compatibility3x\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Database.Json\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Database.Providers.PostgreSQL\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Tests\bin\Release\*.* $net35Path
Copy-Item $baseDir\Insight.Tests.Compatibility3x\bin\Release\*.* $net35Path
}
finally {
RestoreVersions
}
}
Task Build40 {
ReplaceVersions
try {
# build the NET40 binaries
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database\Insight.Database.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Configuration\Insight.Database.Configuration.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Providers.Default\Insight.Database.Providers.Default.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Compatibility3x\Insight.Database.Compatibility3x.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Providers.Glimpse\Insight.Database.Providers.Glimpse.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database.Providers.PostgreSQL\Insight.Database.Providers.PostgreSQL.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Tests\Insight.Tests.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Tests.Compatibility3x\Insight.Tests.Compatibility3x.csproj /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'"
}
# copy the binaries to the net40 folder
Wipe-Folder $net40Path
Copy-Item $baseDir\Insight.Database\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Configuration\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Providers.Default\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Compatibility3x\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Json\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Providers.Glimpse\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Database.Providers.PostgreSQL\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Tests\bin\Release\*.* $net40Path
Copy-Item $baseDir\Insight.Tests.Compatibility3x\bin\Release\*.* $net40Path
}
finally {
RestoreVersions
}
}
Task Build45 {
ReplaceVersions
try {
# build the NET45 binaries
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.sln '/p:Configuration=$configuration' '/t:Clean;Build'"
}
# copy the binaries to the net45 folder
Wipe-Folder $net45Path
Copy-Item $baseDir\*.*\bin\Release\*.* $net45Path
}
finally {
RestoreVersions
}
}
Task BuildMono {
ReplaceVersions
try {
# build the binaries for mono
Exec {
Invoke-Expression "$msbuild $baseDir\Insight.Database\Insight.Database.csproj /p:Configuration=$configuration /p:DefineConstants=```"MONO```" '/t:Clean;Build'"
}
# copy the binaries to the mono folder
Wipe-Folder $monoPath
Copy-Item $baseDir\Insight.Database\bin\Release\*.* $monoPath
}
finally {
RestoreVersions
}
}
Task Test35 -depends Build35 {
Exec {
Invoke-Expression "$nunit $net35Path\Insight.Tests.dll"
}
}
Task Test40 -depends Build40 {
Exec {
Invoke-Expression "$nunit $net40Path\Insight.Tests.dll"
}
}
Task Test45Only {
Get-ChildItem $baseDir\Insight.Tests* |% {
Exec {
if ($_.Name -eq 'Insight.Tests.SQLite') {
Invoke-Expression "$nunit $baseDir\$($_.Name)\bin\Release\$($_.Name).dll"
}
else {
Invoke-Expression "$nunit $net45Path\$($_.Name).dll"
}
}
}
}
Task Test45 -depends Build45, Test45Only {
}
Task PackageOnly {
Wipe-Folder $outputDir
# package nuget
Get-ChildItem $baseDir\Insight* |% { Get-ChildItem -Path $_ } |? Extension -eq .nuspec |% {
Exec {
$nuspec = $_.FullName
Invoke-Expression "$nuget pack $nuspec -OutputDirectory $outputDir -Version $version -NoPackageAnalysis"
}
}
}
Task Package -depends Test, PackageOnly {
}