-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbuild.cake
More file actions
230 lines (180 loc) · 7.48 KB
/
build.cake
File metadata and controls
230 lines (180 loc) · 7.48 KB
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
#tool "nuget:?package=xunit.runner.console"
#tool "nuget:?package=GitVersion.CommandLine"
#addin "nuget:?package=Cake.SqlServer"
#load "./parameters.cake"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
bool publishingError = false;
BuildParameters parameters = BuildParameters.GetParameters(Context);
Setup(context =>
{
parameters.Initialize(context);
Information("SemVersion: {0}", parameters.SemVersion);
Information("Version: {0}", parameters.Version);
Information("Building from branch: " + AppVeyor.Environment.Repository.Branch);
});
Task("debug")
.Does(() => {
Information("debug");
});
Task("Clean")
.Does(() =>
{
CleanDirectories(new DirectoryPath[]{
Directory("./src/Tests/bin/"),
Directory("./src/Tests/obj/"),
Directory(parameters.Artifacts),
Directory(parameters.NSagaBinDir),
Directory(parameters.NSagaBinDir + "../../obj/"),
Directory(parameters.AutofacBinDir),
Directory(parameters.AutofacBinDir + "../../obj/"),
Directory(parameters.SimpleInjectorBinDir),
Directory(parameters.SimpleInjectorBinDir + "../../obj/"),
Directory(parameters.StructureMapBinDir),
Directory(parameters.StructureMapBinDir + "../../obj/"),
Directory(parameters.AzureTablesBinDir),
Directory(parameters.AzureTablesBinDir + "../../obj/"),
});
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Starting Nuget Restore");
NuGetRestore(parameters.Solution);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
MSBuild(parameters.Solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithTarget("Build")
.SetConfiguration(configuration));
});
Task("Create-DB-And-Schema")
.Description("Creates database and installs schema")
.Does(() =>
{
LocalDbCreateInstance("v12.0");
var masterConnectionString = @"data source=(LocalDb)\v12.0;";
var dbConnectionString = @"data source=(LocalDb)\v12.0;Database=NSaga-Testing";
DropAndCreateDatabase(masterConnectionString, "NSaga-Testing");
ExecuteSqlFile(dbConnectionString, "./src/NSaga/SqlServer/Install.sql");
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.IsDependentOn("Create-DB-And-Schema")
.Does(() =>
{
XUnit2("./src/Tests/bin/" + configuration + "/Tests.dll");
});
Task("Copy-Files")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
EnsureDirectoryExists(parameters.Artifacts);
EnsureDirectoryExists(parameters.ArtifactsBin);
CopyFiles(new FilePath[] { "LICENSE", "README.md", "ReleaseNotes.md" }, parameters.ArtifactsBin);
CopyFileToDirectory(parameters.NSagaBinDir + "NSaga.dll", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.NSagaBinDir + "NSaga.pdb", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.NSagaBinDir + "NSaga.xml", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.NSagaBinDir + "SqlServer/Install.sql", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AutofacBinDir + "NSaga.Autofac.dll", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AutofacBinDir + "NSaga.Autofac.pdb", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AutofacBinDir + "NSaga.Autofac.xml", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.SimpleInjectorBinDir + "NSaga.SimpleInjector.dll", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.SimpleInjectorBinDir + "NSaga.SimpleInjector.pdb", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.SimpleInjectorBinDir + "NSaga.SimpleInjector.xml", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.StructureMapBinDir + "NSaga.StructureMap.dll", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.StructureMapBinDir + "NSaga.StructureMap.pdb", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.StructureMapBinDir + "NSaga.StructureMap.xml", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AzureTablesBinDir + "NSaga.AzureTables.dll", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AzureTablesBinDir + "NSaga.AzureTables.pdb", parameters.ArtifactsBin);
CopyFileToDirectory(parameters.AzureTablesBinDir + "NSaga.AzureTables.xml", parameters.ArtifactsBin);
});
Task("Package")
.IsDependentOn("Copy-Files")
.Does(() =>
{
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
var settings = new NuGetPackSettings
{
Version = parameters.Version,
ReleaseNotes = releaseNotes.Notes.ToArray(),
BasePath = parameters.ArtifactsBin,
OutputDirectory = parameters.Artifacts,
Symbols = false,
NoPackageAnalysis = true
};
NuGetPack("./src/NSaga/NSaga.nuspec", settings);
NuGetPack("./src/NSaga.Autofac/NSaga.Autofac.nuspec", settings);
NuGetPack("./src/NSaga.SimpleInjector/NSaga.SimpleInjector.nuspec", settings);
NuGetPack("./src/NSaga.StructureMap/NSaga.StructureMap.nuspec", settings);
NuGetPack("./src/NSaga.AzureTables/NSaga.AzureTables.nuspec", settings);
});
Task("Publish-MyGet")
.IsDependentOn("Package")
.WithCriteria(() => parameters.IsRunningOnAppVeyor)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("MYGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
}
// Push the Packages
var files = GetFiles(parameters.Artifacts + "*.nupkg");
foreach(var file in files)
{
Information("Found nupkg file: {0}", file);
NuGetPush(file, new NuGetPushSettings {
Source = apiUrl,
ApiKey = apiKey
});
}
})
.OnError(exception =>
{
Information("Publish-MyGet Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Package")
.WithCriteria(() => parameters.IsRunningOnAppVeyor)
.Does(() =>
{
var files = GetFiles(parameters.Artifacts + "*.nupkg");
foreach(var file in files)
{
AppVeyor.UploadArtifact(file);
}
});
Task("AppVeyor")
.IsDependentOn("Publish-MyGet")
.IsDependentOn("Upload-AppVeyor-Artifacts")
.Finally(() =>
{
if(publishingError)
{
throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted.");
}
});
Task("SqlExpress")
.Description("Create NSaga database on SqlExpress for local execution")
.Does(() =>
{
var masterConnectionString = @"data source=.\SQLEXPRESS;integrated security=SSPI;";
var dbConnectionString = @"data source=.\SQLEXPRESS;integrated security=SSPI;Initial Catalog=NSaga;";
CreateDatabaseIfNotExists(masterConnectionString, "NSaga");
ExecuteSqlFile(dbConnectionString, "./src/NSaga.SqlServer/Install.sql");
Information("Created SQL Schema for NSaga database");
});
Task("Default")
.IsDependentOn("Package");
RunTarget(target);