-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.cake
More file actions
261 lines (210 loc) · 8.15 KB
/
build.cake
File metadata and controls
261 lines (210 loc) · 8.15 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
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
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var configurationName = "Release";
var target = Argument("target", "Default");
var configuration = Argument("configuration", configurationName);
var packageVersion = string.Empty;
var product = "Codestellation.Galaxy";
var copyright = string.Format("Copyright (c) Codestellation Team 2014 - {0}", DateTime.Now.Year);
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var buildDirInfo = new DirectoryInfo("./build");
var buildDir = Directory(buildDirInfo.FullName);
var nugetDirInfo = new DirectoryInfo("./nuget");
var nugetDir = Directory(nugetDirInfo.FullName);
var solutionPath = "./src/Galaxy.sln";
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
CleanDirectory(nugetDir);
});
//////////////////////////////////////////////////////////////////////
Task("Generate-Solution-Version")
.Does(() =>
{
var command = new ProcessSettings
{
Arguments = "describe --abbrev=7 --first-parent --long --dirty --always",
RedirectStandardOutput = true
};
IEnumerable<string> output;
var exitCode = StartProcess("git", command, out output);
var describe = output.Single();
Information("Git describe is '{0}'", describe);
var annotatedTagPattern = @"(?<major>[0-9]+).(?<minor>[0-9]+)-(?<revision>[0-9]+)-g(?<hash>[\w]+)-?(?<dirty>[\w]+)*";
var parts = System.Text.RegularExpressions.Regex.Match(describe, annotatedTagPattern);
string major = "0";
string minor = "0";
string revision = "0";
string build = "0"; // get it from appveyor
string hash = string.Empty;
string dirty = string.Empty;
if(parts.Success)
{
major = parts.Groups["major"].Value;
minor = parts.Groups["minor"].Value;
revision = parts.Groups["revision"].Value;
hash = parts.Groups["hash"].Value;
dirty = parts.Groups["dirty"].Value;
}
else
{
var tokens = describe.Split('-');
hash = tokens[0];
if(tokens.Length > 1)
{
dirty = tokens[1];
}
}
if(AppVeyor.IsRunningOnAppVeyor)
{
build = AppVeyor.Environment.Build.Number.ToString();
}
var assemblyVersion = string.Format("{0}.{1}", major, minor);
var fullVersion = string.Format("{0}.{1}.{2}.{3}", major, minor, revision, build);
packageVersion = fullVersion;
if(!string.IsNullOrWhiteSpace(dirty))
{
packageVersion += ("-" + dirty);
}
var infoVersion = string.Format("{0} {1}", packageVersion, hash);
var asmInfo = new AssemblyInfoSettings
{
Product = product,
Version = assemblyVersion,
FileVersion = fullVersion,
InformationalVersion = infoVersion,
Copyright = copyright
};
var file = "./src/SolutionVersion.cs";
CreateAssemblyInfo(file, asmInfo);
Information("AssemblyVersion is '{0}'", infoVersion);
});
//////////////////////////////////////////////////////////////////////
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solutionPath);
});
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Generate-Solution-Version")
.Does(() =>
{
MSBuild(solutionPath, settings => {
settings.SetConfiguration(configuration);
settings.Properties["OutDir"] = new List<string>{ buildDirInfo.FullName };
settings.Verbosity = Verbosity.Minimal;
});
});
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var testsAssembly = buildDirInfo
.EnumerateFiles("*.Tests.dll", SearchOption.AllDirectories)
.Select(x => x.FullName)
.First();
var nunitPath = new DirectoryInfo("./")
.EnumerateFiles("nunit-console.exe", SearchOption.AllDirectories)
.First();
var settings = new NUnitSettings { ToolPath = nunitPath.FullName };
NUnit(testsAssembly, settings);
});
//////////////////////////////////////////////////////////////////////
Task("PackHost")
.IsDependentOn("Test")
.Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings {
Id = "Codestellation.Galaxy.Host",
Version = packageVersion,
Title = "Codestellation Galaxy Host",
Authors = new[] {"Codestellation Team"},
Owners = new[] {"Codestellation Team"},
Description = "Provides extended functionality over TopShelf service",
//Summary = "Excellent summare of what the package does",
ProjectUrl = new Uri("https://github.com/Codestellation/Galaxy"),
//IconUrl = new Uri("http://cdn.rawgit.com/SomeUser/TestNuget/master/icons/testnuget.png"),
LicenseUrl = new Uri("https://github.com/Codestellation/Galaxy/blob/master/LICENSE"),
Copyright = copyright,
//ReleaseNotes = new [] {"Bug fixes", "Issue fixes", "Typos"},
Tags = new [] {"Windows", "Service", "Consul", "Config"},
RequireLicenseAcceptance= false,
Symbols = false,
//NoPackageAnalysis = true,
Files = new [] { new NuSpecContent {Source = "Codestellation.Galaxy.Host.???", Target = "lib/net45"}, },
BasePath = "./build",
OutputDirectory = "./nuget"
};
NuGetPack("./src/Galaxy.Host/galaxy.host.nuspec", nuGetPackSettings);
});
Task("PackService")
.IsDependentOn("Test")
.Does(() =>
{
var galaxyProjFile = "./src/Galaxy/Galaxy.csproj";
var serviceBuildPath = System.IO.Path.Combine(buildDirInfo.FullName, "service");
MSBuild(galaxyProjFile, settings => {
settings.SetConfiguration(configuration);
settings.Properties["OutDir"] = new List<string>{ serviceBuildPath };
settings.Verbosity = Verbosity.Minimal;
});
var xmlFiles = new DirectoryInfo(serviceBuildPath)
.EnumerateFiles("*.xml");
foreach(var file in xmlFiles)
{
file.Delete();
}
var nuGetPackSettings = new NuGetPackSettings {
Id = "Codestellation.Galaxy",
Version = packageVersion,
Title = "Codestellation Galaxy",
Authors = new[] {"Codestellation Team"},
Owners = new[] {"Codestellation Team"},
Description = "Deploys topshelf-based services using nuget packages",
ProjectUrl = new Uri("https://github.com/Codestellation/Galaxy"),
LicenseUrl = new Uri("https://github.com/Codestellation/Galaxy/blob/master/LICENSE"),
Copyright = copyright,
Tags = new [] {"Windows", "Service", "Hosting"},
BasePath = serviceBuildPath,
Files = new [] { new NuSpecContent {Source = "*.dll;*.exe;*.config;*.pdb;*.ps1", Target = ""}},
OutputDirectory = "./nuget"
};
NuGetPack("./src/Galaxy/galaxy.nuspec", nuGetPackSettings);
});
Task("Push")
.IsDependentOn("PackHost")
.IsDependentOn("PackService")
.Does(() =>
{
var packages = nugetDirInfo
.EnumerateFiles("*.nupkg")
.Select(x => x.FullName);
foreach(var package in packages)
{
NuGetPush(package, new NuGetPushSettings {
Source = "https://www.myget.org/F/codestellation/api/v2/package",
ApiKey = EnvironmentVariable("myget_key")
});
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Test");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);