-
Notifications
You must be signed in to change notification settings - Fork 68
/
build.cake
98 lines (77 loc) · 2.47 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
var configuration = Argument("configuration", string.Empty);
var target = Argument("target", "default");
var author = Argument("author", "gusztavvargadr");
var version = Argument("version", "2409");
var configurationParts = configuration.Split('/', StringSplitOptions.RemoveEmptyEntries);
var sample = configurationParts.ElementAtOrDefault(0) ?? Argument<string>("sample");
var image = configurationParts.ElementAtOrDefault(1) ?? Argument<string>("image");
var provider = configurationParts.ElementAtOrDefault(2) ?? Argument<string>("provider");
var build = configurationParts.ElementAtOrDefault(3) ?? Argument<string>("build");
var platform = (sample.Contains("ubuntu") || sample.Contains("linux")) ? "ubuntu" : "windows";
var sampleDirectory = Directory($"samples/{sample}");
var platformDirectory = Directory($"../../src/{platform}");
var artifactsDirectory = Directory($"artifacts");
Task("init")
.Does(() => {
PackerInit();
});
Task("restore")
.Does(() => {
PackerBuild("restore");
});
Task("build")
.Does(() => {
PackerBuild("build");
});
Task("test")
.Does(() => {
PackerBuild("test");
});
Task("publish")
.Does(() => {
PackerBuild("publish");
});
Task("download")
.Does(() => {
PackerBuild("download");
});
Task("clean")
.Does(() => {
CleanDirectory(artifactsDirectory);
});
Task("default")
.IsDependentOn("init")
.IsDependentOn("restore")
.IsDependentOn("build")
.IsDependentOn("test");
RunTarget(target);
void PackerInit() {
var arguments = new ProcessArgumentBuilder();
arguments.Append("init");
arguments.Append(platformDirectory);
Packer(arguments);
}
void PackerBuild(string stage) {
var arguments = new ProcessArgumentBuilder();
arguments.Append("build");
arguments.Append($"-var author=\"{author}\"");
arguments.Append($"-var version=\"{version}\"");
arguments.Append($"-var-file=\"images.pkrvars.hcl\"");
arguments.Append($"-var image=\"{image}\"");
arguments.Append($"-var provider=\"{provider}\"");
arguments.Append($"-var build=\"{build}\"");
arguments.Append($"-only \"{build}-{stage}.*\"");
arguments.Append("-force");
arguments.Append("-timestamp-ui");
arguments.Append(platformDirectory);
Packer(arguments);
}
void Packer(ProcessArgumentBuilder arguments) {
var result = StartProcess("packer", new ProcessSettings {
Arguments = arguments,
WorkingDirectory = sampleDirectory
});
if (result != 0) {
throw new Exception($"Packer failed with code {result} .");
}
}