forked from spectresystems/jarvis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
182 lines (159 loc) · 5.74 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
#load "./build/version.cake"
#tool nuget:?package=Wix&version=3.11.0
#tool nuget:?package=chocolatey&version=0.10.8&exclude=./tools/chocolateyinstall/redirects/choco.exe
#tool nuget:?package=xunit.runner.console&version=2.3.1
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var patch = HasArgument("patch");
///////////////////////////////////////////////////////////////////////////////
// GLOBALS
///////////////////////////////////////////////////////////////////////////////
var version = BuildVersion.Calculate(Context);
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory("./.artifacts");
CleanDirectory("./.artifacts/bin");
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.Version,
FileVersion = version.Version,
InformationalVersion = version.SemVersion,
Company = "Spectre Systems AB",
Copyright = "Copyright (c) 2017 Spectre Systems AB",
Product = "Jarvis"
});
});
Task("Build")
.IsDependentOn("Restore")
.IsDependentOn("Patch-Version")
.Does(() =>
{
MSBuild("./src/Jarvis.sln", new MSBuildSettings()
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal)
.WithWarningsAsError()
.WithProperty("AssemblyVersion", "2.0.0.0"));
});
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");
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.Version }
}
});
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.Version }
}
});
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"
});
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build-Chocolatey-Package");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);