-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.cake
208 lines (167 loc) · 7.22 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
200
201
202
203
204
205
206
207
208
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.Docker&version=0.8.5
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.DoInDirectory&version=2.0.0
// #addin nuget:https://www.nuget.org/api/v2/?package=Cake.FileHelpers
//////////////////////////////////////////////////////////////////////
// CONFIGURATION
//////////////////////////////////////////////////////////////////////
const string TESTER_SERVICE_INTEGRATION_TESTS = "integration-tester";
var PROJECTS_TO_PACK = new List<string>
{
"NAME",
"NAME.WebApi",
"NAME.AspNetCore",
"NAME.SelfHost.Kestrel",
"NAME.SelfHost.HttpListener"
// "NAME.Registry"
};
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Full-Build");
var configuration = Argument("configuration", "Release");
var nugetPreReleaseTag = Argument("nugetPreReleaseTag", "dev");
var dockerComposeProject = Argument("composeProject", "name-integration-tests");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var outputDir = Directory("Output/");
var artifactsDir = outputDir + Directory("Artifacts/");
var nugetPackagesDir = artifactsDir + Directory("NuGets/");
var preReleaseNugetPackagesDir = nugetPackagesDir + Directory("PreRelease/");
var releaseNugetPackagesDir = nugetPackagesDir + Directory("Release/");
var integrationTestResultsOutputDir = outputDir + Directory("IntegrationTestsResults/");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDir);
CleanDirectory(integrationTestResultsOutputDir);
});
Task("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreRestore("NAME.sln");
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var dotNetBuildConfig = new DotNetCoreBuildSettings() {
Configuration = configuration,
MSBuildSettings = new DotNetCoreMSBuildSettings()
};
dotNetBuildConfig.MSBuildSettings.TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error;
DotNetCoreBuild("NAME.sln", dotNetBuildConfig);
});
Task("Nuget-Pack")
.Does(()=>{
EnsureDirectoryExists(preReleaseNugetPackagesDir);
EnsureDirectoryExists(releaseNugetPackagesDir);
CleanDirectory(preReleaseNugetPackagesDir);
CleanDirectory(releaseNugetPackagesDir);
var preReleaseSettings = new DotNetCorePackSettings{
Configuration = configuration,
OutputDirectory = preReleaseNugetPackagesDir,
VersionSuffix = nugetPreReleaseTag
};
var releaseSettings = new DotNetCorePackSettings{
Configuration = configuration,
OutputDirectory = releaseNugetPackagesDir
};
// https://github.com/NuGet/Home/issues/4337
// While this issue is not fixed we need to specify the version suffix in the restore task.
Action<DotNetCorePackSettings> packProjects = (settings) => {
var dotnetCoreRestoreSettings = new DotNetCoreRestoreSettings();
if (settings.VersionSuffix != null) {
dotnetCoreRestoreSettings.EnvironmentVariables = new Dictionary<string, string>()
{
{ "VersionSuffix", settings.VersionSuffix }
};
}
foreach(var project in PROJECTS_TO_PACK){
var projectFolder = "./src/" + project;
DotNetCoreRestore(projectFolder, dotnetCoreRestoreSettings);
DotNetCorePack(projectFolder, settings);
}
};
packProjects(preReleaseSettings);
packProjects(releaseSettings);
});
Task("Run-Unit-Tests")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var files = GetFiles("./unit-tests/**/*.csproj");
int highestExitCode = 0;
foreach (var file in files){
// While https://github.com/cake-build/cake/pull/1578 is not merged,
// we need to start our own process to run dotnet xunit.
// Related: https://github.com/cake-build/cake/issues/1577
var processSettings = new ProcessSettings {
Arguments = "xunit -trait \"TestCategory=\"Unit\"\"",
WorkingDirectory = file.GetDirectory()
};
if (IsRunningOnUnix()) {
var frameworks = XmlPeek(file, "/Project/PropertyGroup/TargetFrameworks/text()");
if (frameworks == null)
frameworks = XmlPeek(file, "/Project/PropertyGroup/TargetFramework/text()");
if (frameworks == null || frameworks.Contains("netcoreapp") == false) {
continue;
}
processSettings.Arguments.Append("-framework netcoreapp1.0");
}
var exitCode = StartProcess("dotnet", processSettings);
if(exitCode > highestExitCode)
highestExitCode = exitCode;
}
// Means there was an error
if(highestExitCode > 0 )
throw new Exception("Some tests failed.");
});
Task("Run-Integration-Tests")
.IsDependentOn("Nuget-Pack")
.Does(() => {
EnsureDirectoryExists(releaseNugetPackagesDir);
EnsureDirectoryExists(integrationTestResultsOutputDir);
System.IO.File.Create(integrationTestResultsOutputDir + File("integrationTests.trx"));
DoInDirectory("./integration-tests/", () => {
try
{
DockerComposePull();
DockerComposeBuild(new DockerComposeBuildSettings() { ProjectName = dockerComposeProject });
DockerComposeRun(new DockerComposeRunSettings() { ProjectName = dockerComposeProject, Rm = true}, TESTER_SERVICE_INTEGRATION_TESTS);
}
finally
{
DockerComposeKill(new DockerComposeKillSettings() { ProjectName = dockerComposeProject });
DockerComposeRm(new DockerComposeRmSettings() { ProjectName = dockerComposeProject, Force = true , Volumes = true});
}
});
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Build-AND-Test")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests");
Task("AppVeyor")
.IsDependentOn("Build-AND-Test")
.IsDependentOn("Nuget-Pack");
Task("TravisCI")
.IsDependentOn("Build-AND-Test")
.Does(() => {
if(IsRunningOnUnix()) {
Information("Travis CI running on Linux, executing the integration tests.");
RunTarget("Run-Integration-Tests");
}
});
Task("Default")
.IsDependentOn("Build-AND-Test");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);