-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathbuild.cake
251 lines (219 loc) · 8.27 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
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
#load "./build/version.cake"
#load "./build/appveyor.cake"
#load "./build/parameters.cake"
#tool "nuget:https://api.nuget.org/v3/index.json?package=Wix&version=3.11.0"
#tool "nuget:https://api.nuget.org/v3/index.json?package=chocolatey&version=0.10.8&exclude=./tools/chocolateyinstall/redirects/choco.exe"
#tool "nuget:https://api.nuget.org/v3/index.json?package=xunit.runner.console&version=2.3.1"
#tool "nuget:https://api.nuget.org/v3/index.json?package=gitreleasemanager&version=0.7.0"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var patch = HasArgument("patch");
///////////////////////////////////////////////////////////////////////////////
// GLOBALS
///////////////////////////////////////////////////////////////////////////////
var appveyor = AppVeyorSettings.Initialize(Context);
var parameters = Parameters.Initialize(Context);
var version = BuildVersion.Calculate(Context, appveyor);
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory("./.artifacts");
CleanDirectory("./.artifacts/bin");
CleanDirectory("./.artifacts/appx");
CleanDirectory("./.artifacts/installer");
CleanDirectory("./.artifacts/installer/bin");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./src/Jarvis.sln");
});
Task("Patch-Version")
.WithCriteria(() => patch)
.Does(() =>
{
CreateAssemblyInfo("./src/SharedAssemblyInfo.cs", new AssemblyInfoSettings
{
Version = version.MajorMinorPatch,
FileVersion = version.MajorMinorPatch,
InformationalVersion = version.MajorMinorPatch,
Company = "Spectre Systems AB",
Copyright = "Copyright (c) 2017 Spectre Systems AB",
Product = "Jarvis"
});
});
Task("Patch-AppX-Info")
.Does(() =>
{
var manifest = File("./src/Jarvis.Package/Package.appxmanifest");
var settings = new XmlPokeSettings
{
Namespaces = {{ "c", "http://schemas.microsoft.com/appx/manifest/foundation/windows10" }}
};
XmlPoke(manifest, "c:Package/c:Identity/@Version", $"{version.MsiVersion}.0", settings);
});
Task("Build")
.IsDependentOn("Restore")
.IsDependentOn("Patch-Version")
.IsDependentOn("Patch-AppX-Info")
.Does(() =>
{
MSBuild("./src/Jarvis.sln", new MSBuildSettings()
.WithProperty("AppxBundlePlatforms", "neutral")
.WithProperty("AppxBundle", "Always")
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
XUnit2($"./src/**/bin/{configuration}/*.Tests.dll");
});
Task("Copy-Binaries")
.IsDependentOn("Build")
.Does(() =>
{
CopyFiles($"./src/Jarvis/bin/{configuration}/*", "./.artifacts/bin");
CopyFiles($"./src/Jarvis/bin/{configuration}/*", "./.artifacts/installer/bin");
CopyFiles($"./src/Jarvis.Package/AppPackages/Jarvis.Package_{version.MsiVersion}.0_*/**/*", "./.artifacts/appx", true);
DeleteFiles("./.artifacts/installer/bin/*.xml");
DeleteFiles("./.artifacts/installer/bin/*.pdb");
});
Task("Build-Installer")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Copy-Binaries")
.Does(() =>
{
Information("Compiling installer...");
WiXCandle("./installer/wix/Jarvis.wxs", new CandleSettings
{
NoLogo = true,
Architecture = Architecture.X64,
OutputDirectory = "./.artifacts/installer",
Extensions = new[] { "WixUtilExtension" },
Defines = new Dictionary<string, string>
{
{ "Configuration", configuration },
{ "PublishDirectory", "./.artifacts/bin" },
{ "Platform", "x64" },
{ "ResourceDirectory", "./res" },
{ "Version", version.MsiVersion }
}
});
Information("Linking installer...");
WiXLight("./.artifacts/installer/Jarvis.wixobj", new LightSettings
{
NoLogo = true,
Extensions = new [] { "WixBalExtension", "WixNetFxExtension", "WixUtilExtension" },
OutputFile = "./.artifacts/installer/Jarvis.msi"
});
Information("Compiling bundle...");
var wxsFiles = new[] {
new FilePath("./installer/wix/Bundle.wxs"),
new FilePath("./installer/wix/Prereqs.wxs")
};
WiXCandle(wxsFiles, new CandleSettings
{
NoLogo = true,
Architecture = Architecture.X64,
Extensions = new [] { "WixBalExtension", "WixNetFxExtension", "WixUtilExtension" },
OutputDirectory = "./.artifacts/installer",
Defines = new Dictionary<string, string>
{
{ "JarvisInstaller", "./.artifacts/installer/Jarvis.msi" },
{ "Platform", "x64" },
{ "ResourceDirectory", "./res" },
{ "Version", version.MsiVersion }
}
});
Information("Linking bundle...");
var wixobjFiles = new[] {
new FilePath("./.artifacts/installer/Bundle.wixobj"),
new FilePath("./.artifacts/installer/Prereqs.wixobj")
};
WiXLight(wixobjFiles, new LightSettings
{
NoLogo = true,
Extensions = new [] { "WixBalExtension", "WixNetFxExtension", "WixUtilExtension" },
OutputFile = "./.artifacts/installer/Jarvis-Installer.exe"
});
// Move the file to the artifact root.
if(FileExists("./.artifacts/installer/Jarvis-Installer.exe"))
{
MoveFile("./.artifacts/installer/Jarvis-Installer.exe", $"./.artifacts/Jarvis-{version.SemVersion}-x64.exe");
}
});
Task("Build-Chocolatey-Package")
.IsDependentOn("Build-Installer")
.Does(() =>
{
TransformTextFile("./installer/chocolatey/chocolateyinstall.ps1.template", "%{", "}")
.WithToken("Installer", $"Jarvis-{version.SemVersion}-x64.exe")
.WithToken("Version", version.SemVersion)
.Save("./installer/chocolatey/chocolateyinstall.ps1");
var nuspec = MakeAbsolute(File("./installer/chocolatey/jarvis.nuspec"));
ChocolateyPack(nuspec, new ChocolateyPackSettings
{
Version = version.SemVersion,
OutputDirectory = "./.artifacts"
});
});
Task("Publish-Preview-To-GitHub")
.IsDependentOn("Build-Installer")
.WithCriteria(() => appveyor.IsRunningOnAppVeyor
&& !appveyor.IsPullRequest && appveyor.IsDevelopBranch
&& !appveyor.IsMaintenanceBuild && !appveyor.IsTaggedBuild)
.Does(() =>
{
if(string.IsNullOrWhiteSpace(parameters.GitHubUsername))
{
throw new CakeException("Could not resolve GitHub username.");
}
if(string.IsNullOrWhiteSpace(parameters.GitHubPassword))
{
throw new CakeException("Could not resolve GitHub password.");
}
// Create empty release notes for now.
var releaseNotes = MakeAbsolute(File($"./.artifacts/ReleaseNotes.md"));
System.IO.File.WriteAllText(releaseNotes.FullPath, string.Empty);
// Create release.
GitReleaseManagerCreate(
parameters.GitHubUsername, parameters.GitHubPassword,
"spectresystems", "jarvis", new GitReleaseManagerCreateSettings
{
InputFilePath = releaseNotes,
Name = $"v{version.SemVersion}",
Prerelease = true,
TargetCommitish = "develop"
});
// Add assets.
GitReleaseManagerAddAssets(
parameters.GitHubUsername, parameters.GitHubPassword,
"spectresystems", "jarvis",
$"v{version.SemVersion}",
$"./.artifacts/Jarvis-{version.SemVersion}-x64.exe");
// Publish release.
GitReleaseManagerPublish(
parameters.GitHubUsername, parameters.GitHubPassword,
"spectresystems", "jarvis",
$"v{version.SemVersion}");
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build-Chocolatey-Package");
Task("AppVeyor")
.IsDependentOn("Publish-Preview-To-GitHub");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);