-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.cake
373 lines (310 loc) · 10.1 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#addin nuget:?package=Cake.Npm&version=2.0.0
#tool nuget:?package=Microsoft.TestPlatform&version=15.9.0
#tool nuget:?package=NuGet.CommandLine&version=5.9.1
#addin nuget:?package=Octokit&version=4.0.2
#addin nuget:?package=Cake.Git&version=2.0.0
// tool nuget:?package=GitVersion.CommandLine
var isCIBuild = EnvironmentVariable("CI") == "true";
var isRelease = isCIBuild && EnvironmentVariable("RELEASE") == "true";
var isPrerelease = isRelease && EnvironmentVariable("PRERELEASE") == "true";
var githubToken = EnvironmentVariable("CI") == "true" ? EnvironmentVariable("GH_TOKEN") ?? EnvironmentVariable("GITHUB_TOKEN") : null;
var branchName = EnvironmentVariable("CI") == "true" ? EnvironmentVariable("GITHUB_REF").Replace("refs/heads/", "") : null;
var target = Argument("target", "default");
var solution = File("./DarkId.Papyrus.sln");
var debuggerSolution = File("./DarkId.Papyrus.DebugServer.sln");
var forceDownloads = HasArgument("force-downloads");
var pluginFileDirectory = Directory("src/papyrus-lang-vscode/debug-plugin/");
var pyroCliDirectory = Directory("src/papyrus-lang-vscode/pyro/");
var version = "0.0.0";
public bool ShouldContinueWithDownload(DirectoryPath path)
{
if (DirectoryExists(path))
{
if (forceDownloads)
{
DeleteDirectory(path, new DeleteDirectorySettings { Recursive = true, Force = true });
return true;
}
else
{
return false;
}
}
return true;
}
public void UpdatePyroCli()
{
if (!ShouldContinueWithDownload(pyroCliDirectory))
{
return;
}
var client = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Papyrus-Lang-CI"));
if (githubToken != null)
{
client.Credentials = new Octokit.Credentials(githubToken);
}
client.Repository.Release.GetAll("fireundubh", "pyro").ContinueWith((task) =>
{
var latestRelease = task.Result.First();
Information("Found latest release: " + latestRelease.Name);
var latestReleaseAsset = latestRelease.Assets.First();
var downloadUrl = latestReleaseAsset.BrowserDownloadUrl;
var pyroCliZip = DownloadFile(downloadUrl);
Unzip(pyroCliZip, pyroCliDirectory);
Information("Pyro update complete.");
}).Wait();
}
public void DownloadCompilers()
{
if (!ShouldContinueWithDownload(Directory("dependencies/compilers")))
{
return;
}
var filePath = DownloadFile("https://www.dropbox.com/s/vkoffvsdhru7p1c/papyrus-compilers.zip?dl=1");
Unzip(filePath, "./dependencies");
}
public void NpmScript(string scriptName)
{
var settings = new NpmRunScriptSettings()
{
ScriptName = scriptName,
WorkingDirectory = "./src/papyrus-lang-vscode"
};
NpmRunScript(settings);
}
// As much as the idea of a task with side effects grosses me out, meh...
Task("get-version")
.Does(() =>
{
if (isPrerelease)
{
// Generate a correctly sortable and valid semver based on the current date and time.
var now = DateTime.UtcNow;
var minuteOfDay = now.Hour * 60 + now.Minute;
version = $"{now.Year}.{now.DayOfYear + 300}.{minuteOfDay}";
return;
}
Information("Getting version from semantic-release...");
var done = false;
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = "generate-version-number",
WorkingDirectory = "src/papyrus-lang-vscode",
StandardOutputAction = (line) =>
{
Information("version stdout: " + line);
if (done || !System.Version.TryParse(line, out var _))
{
return;
}
done = true;
version = line;
}
});
});
Task("npm-install")
.Does(() =>
{
NpmInstall(new NpmInstallSettings()
{
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-ci")
.Does(() =>
{
NpmCi(new NpmCiSettings()
{
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-copy-bin")
.Does(() =>
{
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = "copy-bin",
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-copy-debug-bin")
.Does(() =>
{
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = "copy-debug-bin",
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-clean")
.Does(() =>
{
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = "clean",
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-build")
.Does(() =>
{
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = isRelease ? "compile:release" : "compile",
WorkingDirectory = "src/papyrus-lang-vscode",
});
});
Task("npm-publish")
.Does(() =>
{
NpmRunScript(new NpmRunScriptSettings()
{
ScriptName = "semantic-release",
WorkingDirectory = "src/papyrus-lang-vscode",
EnvironmentVariables =
{
// TODO: Something not terrible.
{ "PRERELEASE_FLAG", isPrerelease ? "--pre-release" : " " },
{ "VERSION", version },
{ "BRANCH_NAME", branchName }
}
});
});
Task("download-compilers")
.Does(() =>
{
DownloadCompilers();
});
Task("copy-debug-plugin")
.Does(() =>
{
try
{
CreateDirectory("./src/papyrus-lang-vscode/debug-plugin");
var configuration = isRelease ? "Release" : "Debug";
CopyFileToDirectory(
$"src/DarkId.Papyrus.DebugServer/bin/DarkId.Papyrus.DebugServer.Skyrim/x64/{configuration}/DarkId.Papyrus.DebugServer.Skyrim.dll",
"./src/papyrus-lang-vscode/debug-plugin");
CopyFileToDirectory(
$"src/DarkId.Papyrus.DebugServer/bin/DarkId.Papyrus.DebugServer.Fallout4/x64/{configuration}/DarkId.Papyrus.DebugServer.Fallout4.dll",
"./src/papyrus-lang-vscode/debug-plugin");
}
catch (Exception)
{
// Making this non-fatal during local development.
if (isCIBuild)
{
throw;
}
}
});
Task("download-pyro-cli")
.Does(() =>
{
UpdatePyroCli();
});
Task("restore")
.Does(() =>
{
NuGetRestore(solution);
});
Task("build-debugger")
.Does(() =>
{
var parsedVersion = System.Version.Parse(version);
MSBuild(debuggerSolution, new MSBuildSettings()
{
PlatformTarget = PlatformTarget.x64,
Configuration = isRelease ? "Release" : "Debug",
Properties =
{
{ "VersionMajor", new List<string>(){ parsedVersion.Major.ToString() } },
{ "VersionMinor", new List<string>(){ parsedVersion.Minor.ToString() } },
{ "VersionPatch", new List<string>(){ parsedVersion.Build.ToString() } },
{ "VersionBuild", new List<string>(){ "0" } }
}
});
});
Task("build")
.Does(() =>
{
var parsedVersion = System.Version.Parse(version);
var assemblyVersion = parsedVersion.Major.ToString() + "." + parsedVersion.Minor.ToString() + "." + parsedVersion.Build.ToString() + ".0";
Information("Assembly version: " + assemblyVersion);
// TODO: Do release builds when running CI.
MSBuild(solution, new MSBuildSettings()
{
AssemblyVersion = assemblyVersion,
Verbosity = Verbosity.Minimal
});
});
Task("test")
.Does(() =>
{
var falloutTestTask = System.Threading.Tasks.Task.Run(() => VSTest("./src/DarkId.Papyrus.Test/bin/Debug/net472/DarkId.Papyrus.Test.Fallout4/DarkId.Papyrus.Test.Fallout4.dll", new VSTestSettings()
{
ToolPath = Context.Tools.Resolve("vstest.console.exe")
}));
var skyrimTestTask = System.Threading.Tasks.Task.Run(() => VSTest("./src/DarkId.Papyrus.Test/bin/Debug/net472/DarkId.Papyrus.Test.Skyrim/DarkId.Papyrus.Test.Skyrim.dll", new VSTestSettings()
{
ToolPath = Context.Tools.Resolve("vstest.console.exe")
}));
System.Threading.Tasks.Task.WaitAll(falloutTestTask, skyrimTestTask);
});
Task("clean")
.Does(() =>
{
CleanDirectories("./src/*/bin");
CleanDirectories("./src/*/bin-debug");
CleanDirectories("./src/*/obj");
});
void BuildDefaultTask()
{
var builder = Task("default");
if (isCIBuild)
{
builder.IsDependentOn("npm-ci");
}
else
{
builder.IsDependentOn("npm-install");
}
if (isRelease)
{
builder
.IsDependentOn("get-version");
}
builder.IsDependentOn("clean")
.IsDependentOn("download-compilers")
.IsDependentOn("download-pyro-cli")
.IsDependentOn("restore")
.IsDependentOn("build-debugger")
.IsDependentOn("copy-debug-plugin")
.IsDependentOn("build")
.IsDependentOn("test");
builder
.IsDependentOn("npm-clean")
.IsDependentOn("npm-build")
.IsDependentOn("npm-copy-bin")
.IsDependentOn("npm-copy-debug-bin");
if (isRelease)
{
builder.IsDependentOn("npm-publish");
}
}
// TODO: Clean up local development tasks. Should add additional arguments to control what gets built.
// TODO: Document how to use the tasks in the new CONTRIBUTING.md file.
// TODO: Task to copy the debug plugin to the correct location for testing without relying on the extension to figure it
// out/do it.
Task("update-bin")
.IsDependentOn("build")
.IsDependentOn("npm-copy-bin")
.IsDependentOn("npm-copy-debug-bin")
.IsDependentOn("copy-debug-plugin");
Task("build-extension")
.IsDependentOn("npm-build");
Task("build-test")
.IsDependentOn("build")
.IsDependentOn("test");
BuildDefaultTask();
RunTarget(target);