-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstallers.cake
203 lines (150 loc) · 5.79 KB
/
installers.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
// Customize this file when using a different issue tracker
#l "installers-innosetup.cake"
#l "installers-msix.cake"
#l "installers-squirrel.cake"
using System.Diagnostics;
//-------------------------------------------------------------
public interface IInstaller
{
bool IsAvailable { get; }
Task PackageAsync(string projectName, string channel);
Task<DeploymentTarget> GenerateDeploymentTargetAsync(string projectName);
}
//-------------------------------------------------------------
public class DeploymentCatalog
{
public DeploymentCatalog()
{
Targets = new List<DeploymentTarget>();
}
public List<DeploymentTarget> Targets { get; private set; }
}
//-------------------------------------------------------------
public class DeploymentTarget
{
public DeploymentTarget()
{
Groups = new List<DeploymentGroup>();
}
public string Name { get; set; }
public List<DeploymentGroup> Groups { get; private set; }
}
//-------------------------------------------------------------
public class DeploymentGroup
{
public DeploymentGroup()
{
Channels = new List<DeploymentChannel>();
}
public string Name { get; set; }
public List<DeploymentChannel> Channels { get; private set; }
}
//-------------------------------------------------------------
public class DeploymentChannel
{
public DeploymentChannel()
{
Releases = new List<DeploymentRelease>();
}
public string Name { get; set; }
public List<DeploymentRelease> Releases { get; private set; }
}
//-------------------------------------------------------------
public class DeploymentRelease
{
public string Name { get; set; }
public DateTime? Timestamp { get; set;}
public bool HasFull
{
get { return Full is not null; }
}
public DeploymentReleasePart Full { get; set; }
public bool HasDelta
{
get { return Delta is not null; }
}
public DeploymentReleasePart Delta { get; set; }
}
//-------------------------------------------------------------
public class DeploymentReleasePart
{
public string Hash { get; set; }
public string RelativeFileName { get; set; }
public ulong Size { get; set; }
}
//-------------------------------------------------------------
public class InstallerIntegration : IntegrationBase
{
private readonly List<IInstaller> _installers = new List<IInstaller>();
public InstallerIntegration(BuildContext buildContext)
: base(buildContext)
{
_installers.Add(new InnoSetupInstaller(buildContext));
_installers.Add(new MsixInstaller(buildContext));
_installers.Add(new SquirrelInstaller(buildContext));
}
public string GetDeploymentChannelSuffix(string prefix = "_", string suffix = "")
{
var channelSuffix = string.Empty;
if (BuildContext.Wpf.AppendDeploymentChannelSuffix)
{
if (BuildContext.General.IsAlphaBuild ||
BuildContext.General.IsBetaBuild)
{
channelSuffix = $"{prefix}{BuildContext.Wpf.Channel}{suffix}";
}
BuildContext.CakeContext.Information($"Using deployment channel suffix '{channelSuffix}'");
}
return channelSuffix;
}
public async Task PackageAsync(string projectName, string channel)
{
BuildContext.CakeContext.LogSeparator($"Packaging installer for '{projectName}'");
foreach (var installer in _installers)
{
if (!installer.IsAvailable)
{
continue;
}
BuildContext.CakeContext.LogSeparator($"Applying installer '{installer.GetType().Name}' for '{projectName}'");
var stopwatch = Stopwatch.StartNew();
try
{
await installer.PackageAsync(projectName, channel);
}
finally
{
stopwatch.Stop();
BuildContext.CakeContext.Information($"Installer took {stopwatch.Elapsed}");
}
}
if (BuildContext.Wpf.GenerateDeploymentCatalog)
{
BuildContext.CakeContext.LogSeparator($"Generating deployment catalog for '{projectName}'");
var catalog = new DeploymentCatalog();
foreach (var installer in _installers)
{
if (!installer.IsAvailable)
{
continue;
}
BuildContext.CakeContext.LogSeparator($"Generating deployment target for catalog for installer '{installer.GetType().Name}' for '{projectName}'");
var deploymentTarget = await installer.GenerateDeploymentTargetAsync(projectName);
if (deploymentTarget is not null)
{
catalog.Targets.Add(deploymentTarget);
}
}
var localCatalogDirectory = System.IO.Path.Combine(BuildContext.General.OutputRootDirectory, "catalog", projectName);
BuildContext.CakeContext.CreateDirectory(localCatalogDirectory);
var localCatalogFileName = System.IO.Path.Combine(localCatalogDirectory, "catalog.json");
var json = Newtonsoft.Json.JsonConvert.SerializeObject(catalog);
System.IO.File.WriteAllText(localCatalogFileName, json);
if (BuildContext.Wpf.UpdateDeploymentsShare)
{
var targetFileName = System.IO.Path.Combine(BuildContext.Wpf.GetDeploymentShareForProject(projectName), "catalog.json");
BuildContext.CakeContext.CopyFile(localCatalogFileName, targetFileName);
}
}
}
}