forked from FlaUI/FlaUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
199 lines (173 loc) · 6.11 KB
/
build.cake
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
#tool nuget:?package=NuGet.CommandLine&version=6.3.0
#tool nuget:?package=NUnit.ConsoleRunner&version=3.15.2
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var slnFile = @"src\FlaUI.sln";
var artifactDir = new DirectoryPath("artifacts");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactDir);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(slnFile);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var buildLogFile = artifactDir.CombineWithFilePath("BuildLog.txt");
var buildSettings = new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.VS2022,
Configuration = configuration,
PlatformTarget = PlatformTarget.MSIL,
}.AddFileLogger(new MSBuildFileLogger {
LogFile = buildLogFile.ToString(),
MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.All
});
// Hide informational warnings for now
buildSettings.Properties.Add("WarningLevel", new[] { "3" });
// Force restoring
buildSettings.Properties.Add("RestoreForce", new[] { "true" });
// First build with default settings
buildSettings.Targets.Clear();
buildSettings.WithTarget("Restore");
MSBuild(slnFile, buildSettings);
buildSettings.Targets.Clear();
buildSettings.WithTarget("Build");
MSBuild(slnFile, buildSettings);
// Second build with signing enabled
var buildLogSignedFile = artifactDir.CombineWithFilePath("BuildLogSigned.txt");
buildSettings.FileLoggers.First().LogFile = buildLogSignedFile.ToString();
buildSettings.Properties.Add("EnableSigning", new[] { "true" });
buildSettings.Targets.Clear();
buildSettings.WithTarget("Restore");
MSBuild(slnFile, buildSettings);
buildSettings.Targets.Clear();
buildSettings.WithTarget("Build");
MSBuild(slnFile, buildSettings);
// Zip the logs
Zip(artifactDir, artifactDir.CombineWithFilePath("BuildLog.zip"), new [] { buildLogFile, buildLogSignedFile });
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var resultFile = artifactDir.CombineWithFilePath("UnitTestResult.xml");
NUnit3(@"src\FlaUI.Core.UnitTests\bin\FlaUI.Core.UnitTests.dll", new NUnit3Settings {
Results = new[] {
new NUnit3Result { FileName = resultFile, Format = "nunit3" }
}
});
if (AppVeyor.IsRunningOnAppVeyor) {
AppVeyor.UploadTestResults(resultFile, AppVeyorTestResultsType.NUnit3);
}
});
Task("Run-UI-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var resultFile = artifactDir.CombineWithFilePath("UIA2TestResult.xml");
NUnit3(@"src\FlaUI.Core.UITests\bin\FlaUI.Core.UITests.dll", new NUnit3Settings {
Results = new[] {
new NUnit3Result { FileName = resultFile, Format = "nunit3" }
},
ArgumentCustomization = args => args.Append("--testparam:uia=2")
});
Information("Finished UIA2 Tests");
if (AppVeyor.IsRunningOnAppVeyor) {
AppVeyor.UploadTestResults(resultFile, AppVeyorTestResultsType.NUnit3);
}
resultFile = artifactDir.CombineWithFilePath("UIA3TestResult.xml");
NUnit3(@"src\FlaUI.Core.UITests\bin\FlaUI.Core.UITests.dll", new NUnit3Settings {
Results = new[] {
new NUnit3Result { FileName = resultFile, Format = "nunit3" }
},
ArgumentCustomization = args => args.Append("--testparam:uia=3")
});
Information("Finished UIA3 Tests");
if (AppVeyor.IsRunningOnAppVeyor) {
AppVeyor.UploadTestResults(resultFile, AppVeyorTestResultsType.NUnit3);
}
});
Task("Run-Tests")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Run-UI-Tests")
.Does(() =>
{
});
Task("Package")
.IsDependentOn("Run-Tests")
.Does(() =>
{
// Upload the artifacts to appveyor
if (AppVeyor.IsRunningOnAppVeyor) {
// Add the nuget packages
foreach(var file in GetFiles(artifactDir.ToString() + "/*.nupkg"))
{
AppVeyor.UploadArtifact(file);
}
// Add the test xml files
foreach(var file in GetFiles(artifactDir.ToString() + "/*.xml"))
{
AppVeyor.UploadArtifact(file);
}
// Add zip files
foreach(var file in GetFiles(artifactDir.ToString() + "/*.zip"))
{
AppVeyor.UploadArtifact(file);
}
}
});
Task("Push-To-Nuget")
.Does(() =>
{
var apiKey = System.IO.File.ReadAllText(".nugetapikey");
// Get the paths to the packages
var packages = GetFiles($"{artifactDir}/*.nupkg");
// Push the packages
foreach (var package in packages) {
Information($"Pushing {package}");
NuGetPush(package, new NuGetPushSettings {
Source = "https://nuget.org/api/v2/package",
ApiKey = apiKey
});
}
});
Task("Push-To-SymbolSource")
.Does(() =>
{
var apiKey = System.IO.File.ReadAllText(".nugetapikey");
// Get the paths to the packages
var packages = GetFiles($"{artifactDir}/*.snupkg");
// Push the packages
foreach (var package in packages) {
Information($"Pushing {package}");
NuGetPush(package, new NuGetPushSettings {
Source = "https://nuget.smbsrc.net",
ApiKey = apiKey
});
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Run-Unit-Tests");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);