forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamcity.build
438 lines (381 loc) · 18 KB
/
teamcity.build
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?xml version="1.0" ?>
<project name="NHibernate TeamCity Build" xmlns="http://nant.sf.net/release/0.90/nant.xsd" default="clean-configure-test" xsi:schemaLocation="http://nant.sf.net/release/0.90/nant.xsd Tools\nant\schema\nant.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<property name="root.dir" value="." />
<property name="config.teamcity" value="default"/>
<include buildfile="${root.dir}/default.build" />
<if test="${not property::exists('CCNetLabel') and not property::exists('build.number')}">
<fail message="This build file is for use with CruiseControl.NET or TeamCity" />
</if>
<property name="build.number" value="${CCNetLabel}" if="${property::exists('CCNetLabel')}" />
<target name="clean-configure-test" depends="cleanall init copy-teamcity-configuration binaries test verify-test-results binaries-zip" />
<target name="copy-teamcity-configuration">
<copy file="build-common/teamcity-hibernate.cfg.xml" tofile="${bin.dir}/hibernate.cfg.xml" />
<call target="setup-teamcity-${config.teamcity}"/>
<property name="app.config" value="../${bin.dir}/hibernate.cfg.xml" />
<nant buildfile="${root.dir}/build-common/common-project.xml" target="common.put-connection-settings-into-defined-app-config" />
</target>
<target name="verify-test-results">
<if test="${property::exists('NHibernate.Test.IgnoreFail')}">
<!-- Process the current results first, so that these will be available in build artifacts even
if the last-result files is missing. -->
<property name="teamcity.current.result" value="${testResult::StripTimings(testresults.dir + '/NHibernate.Test.dll-results.xml', 'NHibernate.Test.current-results.xml')}" />
<copy file="${teamcity.last.result}" todir="${testresults.dir}" />
<property name="teamcity.report" value="${testResult::CompareResults(teamcity.current.result, teamcity.last.result)}" />
</if>
</target>
<target name="setup-teamcity-default">
<!-- default (SQL Server) does not require any additional settings/binaries -->
</target>
<target name="setup-teamcity-sqlServerOdbc">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OdbcDriver" />
<property name="nhibernate.connection.connection_string" value="Driver={SQL Native Client};Server=.\SQLExpress;Database=nhibernateOdbc;Trusted_Connection=yes" />
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/sqlServerOdbc/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-sqlServerCe32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlServerCeDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSqlCe40Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.sdf" />
<property name="nhibernate.command_timeout" value="0" />
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/sqlServerCe/NHibernate.Test.last-results.xml" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/sqlServerCe/X86">
<include name="*.dll"/>
</fileset>
</copy>
</target>
<target name="setup-teamcity-sqlServerCe64">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlServerCeDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSqlCe40Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.sdf" />
<property name="nhibernate.command_timeout" value="0" />
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/sqlServerCe/NHibernate.Test.last-results.xml" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/sqlServerCe/AMD64">
<include name="*.dll"/>
</fileset>
</copy>
</target>
<target name="setup-teamcity-firebird32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" />
<property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/firebird/x86">
<include name="*.dll"/>
<include name="*.msg"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/firebird/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-firebird64">
<property name="nunit-console" value="${tools.dir}/NUnit/nunit-console.exe" />
<property name="nunit.found" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" />
<property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/firebird/x64">
<include name="*.dll"/>
<include name="*.msg"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/firebird/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-sqlite32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/sqlite/x86">
<include name="*.dll"/>
</fileset>
</copy>
</target>
<target name="setup-teamcity-sqlite64">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/sqlite/x64">
<include name="*.dll"/>
</fileset>
</copy>
</target>
<target name="setup-teamcity-postgresql">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.NpgsqlDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.PostgreSQL82Dialect" />
<property name="nhibernate.connection.connection_string" value="Host=localhost;Port=5432;Database=nhibernate;Username=nhibernate;Password=nhibernate" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/postgresql">
<include name="*.dll"/>
</fileset>
</copy>
</target>
<target name="setup-teamcity-oracle32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Data Source=XE" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/x86">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-oracle-managed32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleManagedDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/managed/common">
<include name="*.dll"/>
</fileset>
</copy>
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/managed/x86">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-oracle-managed64">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleManagedDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/managed/common">
<include name="*.dll"/>
</fileset>
</copy>
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/managed/x64">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-mysql">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MySQL5Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=localhost;Protocol=pipe;Database=nhibernate;User ID=nhibernate;Password=nhibernate;Old Guids=True;" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/mysql">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/mysql/NHibernate.Test.last-results.xml" />
</target>
<script language="C#" prefix="testResult">
<references>
<include name="System.dll" />
<include name="System.Data.dll" />
<include name="System.Xml.dll" />
</references>
<imports>
<import namespace="System.Collections.Generic"/>
<import namespace="System.Data"/>
<import namespace="System.Data.Common"/>
<import namespace="System.Data.SqlClient"/>
<import namespace="System.IO"/>
<import namespace="System.Xml"/>
</imports>
<code>
<![CDATA[
public static void StripAttributes(XmlDocument source, string xpath)
{
foreach(XmlAttribute att in source.SelectNodes(xpath))
att.OwnerElement.RemoveAttribute(att.Name);
}
public static void StripElements(XmlDocument source, string xpath)
{
foreach(XmlElement el in source.SelectNodes(xpath))
el.ParentNode.RemoveChild(el);
}
[Function("StripTimings")]
public static string StripTimings(string testResultFile, string outputFile)
{
try
{
XmlDocument testResults = new XmlDocument();
testResults.Load(testResultFile);
StripElements(testResults, "//stack-trace");
StripAttributes(testResults, "//@cwd");
StripAttributes(testResults, "//@total");
StripAttributes(testResults, "//@date");
StripAttributes(testResults, "//@time");
StripAttributes(testResults, "//@machine-name");
StripAttributes(testResults, "//@user");
StripAttributes(testResults, "//@user-domain");
outputFile = Path.GetDirectoryName(testResultFile) + "/" + outputFile;
testResults.Save(outputFile);
return outputFile;
}
catch(Exception e)
{
Console.WriteLine(e);
throw;
}
}
public class Result
{
public string Name;
public bool Executed;
public bool Success;
private static Result Parse(XmlNode testCase)
{
Result result = new Result();
result.Name = testCase.Attributes["name"].Value;
result.Executed = bool.Parse(testCase.Attributes["executed"].Value);
if (result.Executed)
result.Success = bool.Parse(testCase.Attributes["success"].Value);
return result;
}
public override string ToString()
{
string prefix = "IGNORED - ";
if (Executed) prefix = Success ? "PASS - " : "FAIL - ";
return prefix + Name;
}
public static IList<Result> ParseFile(string file)
{
XmlDocument run1 = new XmlDocument();
run1.Load(file);
IList<Result> results = new List<Result>();
foreach (XmlNode testCase in run1.SelectNodes("//test-case"))
{
Result result = Result.Parse(testCase);
results.Add(result);
}
return results;
}
}
[Function("CompareResults")]
public static string CompareResults(string currentResult, string lastResult)
{
try
{
string outputFile = Path.GetDirectoryName(currentResult) + "/Comparison.txt";
StringBuilder report = new StringBuilder();
report.AppendLine("Comparison Results");
report.AppendLine("==================");
IList<Result> before = Result.ParseFile(lastResult);
IList<Result> after = Result.ParseFile(currentResult);
IList<string> beforeTestNames = new List<string>();
IList<string> afterTestNames = new List<string>();
foreach(Result result in before) beforeTestNames.Add(result.Name);
foreach(Result result in after) afterTestNames.Add(result.Name);
IList<Result> afterExistingTests = new List<Result>();
foreach(Result result in after)
if (beforeTestNames.Contains(result.Name))
afterExistingTests.Add(result);
IList<Result> newFailingTests = new List<Result>();
IList<Result> newNotFailingTests = new List<Result>();
foreach(Result result in after)
if (!beforeTestNames.Contains(result.Name))
if (result.Executed && !result.Success)
newFailingTests.Add(result);
else
newNotFailingTests.Add(result);
report.AppendLine();
report.AppendLine("*** Tests new (not failing) since last recorded results ***");
if (newNotFailingTests.Count > 0)
{
foreach(Result result in newNotFailingTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
report.AppendLine();
report.AppendLine("*** Tests new (failed) since last recorded results ***");
if (newFailingTests.Count > 0)
{
foreach(Result result in newFailingTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
IList<Result> fixedTests = new List<Result>();
foreach(Result afterResult in afterExistingTests)
foreach(Result beforeResult in before)
if (beforeResult.Name == afterResult.Name)
if (!beforeResult.Success && afterResult.Success)
fixedTests.Add(afterResult);
report.AppendLine();
report.AppendLine("*** Tests fixed since last recorded results ***");
if (fixedTests.Count > 0)
{
foreach(Result result in fixedTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
IList<Result> missingTests = new List<Result>();
foreach(Result result in before)
if (!afterTestNames.Contains(result.Name))
missingTests.Add(result);
report.AppendLine();
report.AppendLine("*** Tests missing since last recorded results ***");
if (missingTests.Count > 0)
{
foreach(Result result in missingTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
IList<Result> ignoredTests = new List<Result>();
foreach(Result afterResult in afterExistingTests)
foreach(Result beforeResult in before)
if (beforeResult.Name == afterResult.Name)
if (beforeResult.Executed && !afterResult.Executed)
ignoredTests.Add(afterResult);
report.AppendLine();
report.AppendLine("*** Tests ignored since last recorded results ***");
if (ignoredTests.Count > 0)
{
foreach(Result result in ignoredTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
IList<Result> brokenTests = new List<Result>();
foreach(Result afterResult in afterExistingTests)
foreach(Result beforeResult in before)
if (beforeResult.Name == afterResult.Name)
if (beforeResult.Success && afterResult.Executed && !afterResult.Success)
brokenTests.Add(afterResult);
report.AppendLine();
report.AppendLine("*** Tests broken since last recorded results ***");
if (brokenTests.Count > 0)
{
foreach(Result result in brokenTests)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
string output = report.ToString();
File.WriteAllText(outputFile, output);
if (brokenTests.Count > 0)
throw new Exception("Previously passing tests have been broken\n\n" + output);
if (newFailingTests.Count > 0)
throw new Exception("New tests that fail have been added\n\n" + output);
return output;
}
catch(Exception e)
{
Console.WriteLine(e);
throw;
}
}
]]>
</code>
</script>
</project>